Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@philmander
philmander / inverted-intro-3-1.js
Last active December 10, 2015 10:38
Inverted intro with IOC
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
"*jsonMovieFinder"
]
},
@philmander
philmander / inverted-contructor-literals-1.js
Last active December 10, 2015 10:38
Injecting literal values as constructor arguments
//movies/move-finder.js
define(function() {
var MovieFinder = function(jsonUrl, numMovies, includeShortFilms) {
this.jsonUrl = jsonUrl;
this.numMovies = numMovies;
this.includeShortFilms = includeShortFilms;
};
return MovieFinder;
});
@philmander
philmander / inverted-constructor-literals-map-1.js
Created December 31, 2012 19:51
Injecting literal values as a constructor argument using a map of values
//movies/move-finder.js
define(function() {
var MovieFinder = function(options) {
this.jsonUrl = options.jsonUrl || null;
this.numMovies = options.numMovies || 10;
this.includeShortFilms = options.includeShortFilms || false;
};
return MovieFinder;
});
@philmander
philmander / inverted-constructor-deps-1.js
Last active December 10, 2015 10:38
Injecting a dependency as a constructor argument
//movies/movie-lister.js
define(function() {
var MovieLister = function(movieFinder) {
this.movieFinder = movieFinder;
};
return MovieLister;
});
@philmander
philmander / inverted-property-injection-1.js
Created December 31, 2012 20:18
Injecting literal values and dependencies as properties and methods
//movies/movie-lister.js
define(function() {
var MovieLister = function() {
this.movieFinder = null;
this.includeShortFilms = false;
this.numMovies = 10;
};
MovieLister.prototype.setNumToShow = function(numToShow) {
@philmander
philmander / inverted-scopes-1.js
Last active December 10, 2015 10:39
Demonstrates using singleton and static scopes to create movie utils
//movie/movie-util-instance.js
define(function() {
var MovieUtil = function() {
};
MovieUtil.prototype.doSomething = function() {
//dostuff
};
@philmander
philmander / inverted-inheritance-1.js
Created December 31, 2012 20:48
Creating a prototypal inheritance chain with the Inverted
//movies/json-movie-finder.js
define(function() {
var JsonMovieFinder = function(jsonpUrl) {
this.jsonpUrl = jsonpUrl;
};
return JsonMovieFinder;
});
//movies/base-movie-finder.js
@philmander
philmander / inverted-factory-1.js
Created December 31, 2012 20:58
Using factory methods to generate values or dependencies to inject
//movies/move-finder.js
define(function() {
var MovieFinder = function(username, accessCode) {
this.username = username;
this.accessCode = accessCode;
};
return MovieFinder;
});
//movies/movie-util.js
@philmander
philmander / inverted-app-config-reference.js
Last active December 10, 2015 10:59
Reference Inverted application config object.
var applicationConfig = {
// a map of 'protos', inverted objects
protos: {
//the unique id of a proto
protoId: {
//the amd or common js module name which exports the proto
module: "moduleName",
//contructor arguments to inject into protos with prototype or singleton scope
args: [
//a literal value argument
//example app config defining a jquery proto
define({function() {
return: {
protos: {
jquery: {
//assuming jquery's url is
//defined in the amd paths config
module: "jquery",
scope: "static"
},