Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@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-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-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-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-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-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-intro-2-1.js
Last active December 10, 2015 10:38
Inverted intro 2 with dependency injection
//movies/movie-lister.js
define(function() {
var MovieLister = function(movieFinder) {
this.movieFinder = movieFinder;
};
MovieLister.prototype.showMovies = function(query) {
@philmander
philmander / inverted-intro-1-1.js
Last active January 19, 2016 14:32
First inverted intro with no dependency injection
// movies/movie-lister.js
define(["movies/json-movie-finder"], function(MovieFinder) {
var MovieLister = function() {
//hard coded dependency
this.movieFinder = new MovieFinder();
};
MovieLister.prototype.showMovies = function(query) {
@philmander
philmander / inverted-instantiation-1.js
Last active December 10, 2015 10:29
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() {
@philmander
philmander / inverted-movie-app.js
Last active December 10, 2015 08:38
inverter intro 3: using app context
require(["inverted", "app-config"], function(inverted, conf) {
var appContext = inverted.create(conf);
appContext.getProto("movieLister", function(movieLister) {
movieLister.showMovies();
};
});