Last active
August 29, 2015 14:05
-
-
Save danschultz/9a840ffaa48975386ea4 to your computer and use it in GitHub Desktop.
Frappe Movie Search Demo
This file contains hidden or 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
ObservableList movieSuggestions = new ObservableList(); | |
var searchInput = document.querySelector("#search-input"); | |
var onInput = new EventStream(searchInput.onKeyUp).merge(searchInput.onChange) | |
.map((_) => searchInput.inputValue) | |
.debounce(new Duration(milliseconds: 250)) | |
.distinct(); | |
var suggestions = onInput.flatMapLatest((search) { | |
var results = search.length >= 3 ? _queryMovies(search) : new Future.value([]); | |
return results.asStream(); | |
}); | |
suggestions.forEach((suggestions) => | |
movieSuggestions | |
..clear() | |
..addAll(suggestions.take(10))); | |
Future<List<String>> _queryMovies(String search) { | |
var uri = new Uri(host: "api.themoviedb.org", path: "3/search/movie", queryParameters: { | |
"api_key": "9eae05e667b4d5d9fbb75d27622347fe", | |
"query": search | |
}); | |
return HttpRequest.getString(uri.toString()) | |
.then((result) => JSON.decode(result)["results"]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment