Last active
December 10, 2015 10:38
-
-
Save philmander/4422058 to your computer and use it in GitHub Desktop.
Inverted intro 2 with dependency injection
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 | |
define(function() { | |
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); | |
}); | |
}); | |
}; | |
return 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 | |
define(["jsonp"], function(jsonP) { | |
var JsonMovieFinder = function(jsonpUrl) { | |
this.jsonpUrl = jsonpUrl; | |
}; | |
JsonMovieFinder.prototype.getMovies = function(keywords) { | |
var result = jsonP.getJson(this.jsonUrl, { | |
keywords: keywords || "" | |
}); | |
return result; | |
}; | |
return 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 | |
//load all dependencies up front | |
require([ "movies/movie-lister", "movies/json-movie-finder", function(MovieLister, MovieFinder) { | |
//wire them together | |
var jsonUrl = "http://jsonp.movies.com/movies"; | |
var movieFinder = new MovieFinder(jsonUrl); | |
var movieLister = new MovieLister(movieLister); | |
movieLister.showMovies(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think there is small mistake in inverted-intro-2-3.js