Last active
December 11, 2015 00:09
-
-
Save philmander/4514270 to your computer and use it in GitHub Desktop.
Demonstrates property injecting the appContext into a proto instance
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-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; | |
}); | |
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: { | |
movieFinder : { | |
module: "movies/movie-finder", | |
injectAppContext: true //defaults to false | |
}, | |
moviePrefs: { | |
module: "movies/movie-prefs" | |
}, | |
} | |
}; | |
}); |
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); | |
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