Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 10, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philmander/4421686 to your computer and use it in GitHub Desktop.
Save philmander/4421686 to your computer and use it in GitHub Desktop.
Simple example of how to instantiate objects with Inverted
//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;
});
//app-config.js
define(function() {
return {
protos: {
movieLister : {
module: "movies/movie-lister",
},
movieViewer: {
module: "movies/movie-viewer"
}
}
};
});
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