Last active
December 10, 2015 11:58
-
-
Save philmander/4430581 to your computer and use it in GitHub Desktop.
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/movie-lister.js | |
var MovieLister = function(movieFinder) { | |
this.movieFinder = movieFinder; | |
}; | |
MovieLister.prototype.showMovies = function(query) { | |
var keywords = query.split(" "); | |
var movieResult = this.movieFinder.getMovies(keywords); | |
movieResult.done(function() { | |
movies.forEach(function(movie) { | |
console.log(movie.title); | |
}); | |
}); | |
}; | |
module.exports = MovieLister; |
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/json-movie-finder.js | |
var jsonP = require("jsonP"); | |
var JsonMovieFinder = function(jsonpUrl) { | |
this.jsonpUrl = jsonpUrl; | |
}; | |
JsonMovieFinder.prototype.getMovies = function(keywords) { | |
var result = jsonP.getJson(this.jsonUrl, { | |
keywords: keywords || "" | |
}); | |
return result; | |
}; | |
module.exports = JsonMovieFinder; |
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
// movie-app.js | |
var inverted = require("inverted"); | |
var conf = require("./app-config"); | |
//create an appcontext using the app config and the original module | |
var appContext = inverted.create(conf, module); | |
//get an instance of the MoveLister class | |
appContext.getProto("movieLister", function(movieLister) { | |
movieLister.showMovies(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment