Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 11, 2015 00:09
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/4514270 to your computer and use it in GitHub Desktop.
Save philmander/4514270 to your computer and use it in GitHub Desktop.
Demonstrates property injecting the appContext into a proto instance
// movies/move-finder.js
define(["jquery"], function($) {
var MovieFinder = function() {
var self = this;
$(document).on("click", ".open-prefs", function() {
self.openPreferences();
});
};
MovieFinder.prototype.openPreferences = function() {
// __appContext__ is injected as a property of this instance
self.__appContext__.getProto("moviePrefs", function(moviePrefs) {
moviePrefs.render();
});
};
return MovieFinder;
});
// app-config.js
define(function() {
return {
protos: {
movieFinder : {
module: "movies/movie-finder",
injectAppContext: true //defaults to false
},
moviePrefs: {
module: "movies/movie-prefs"
},
}
};
});
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
appContext.getProto("movieFinder", function(movieFinder) {
// (movieFinder.__appContext__ === appContext) == true
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment