Skip to content

Instantly share code, notes, and snippets.

@philmander
Last active December 10, 2015 11:58
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/4430581 to your computer and use it in GitHub Desktop.
Save philmander/4430581 to your computer and use it in GitHub Desktop.
// 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;
// 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;
// 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