Last active
December 10, 2015 10:29
-
-
Save philmander/4421686 to your computer and use it in GitHub Desktop.
Simple example of how to instantiate objects with Inverted
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//movies/move-lister.js | |
define(function() { | |
var MovieLister = function() { | |
//constructor stuff | |
}; | |
return MovieLister; | |
}); | |
//movies/move-viewer.js | |
define(function() { | |
var MovieViewer = function() { | |
//constructor stuff | |
}; | |
return MovieViewer; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//app-config.js | |
define(function() { | |
return { | |
protos: { | |
movieLister : { | |
module: "movies/movie-lister", | |
}, | |
movieViewer: { | |
module: "movies/movie-viewer" | |
} | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(["inverted", "app-config"], function(inverted, conf) { | |
var appContext = inverted.create(conf); | |
//load one or more protos defined in the app config | |
appContext.getProto(["movieLister", "movieViewer"], | |
function(movieLister, movieViewer) { | |
//movieLister instanceof MovieLister == true | |
//movieViewer instanceof MovieViewer == true | |
}, function(invertedError) { | |
//handle errors in your config here | |
}); | |
//you may also write (v0.2) | |
var result = appContext.getProto(["movieLister", "movieViewer"]) | |
result.then( | |
function(movieLister, movieViewer) { | |
//do stuff | |
}, | |
function(invertedError) { | |
//handle error | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment