Skip to content

Commit

Permalink
cancel the second video request when a new search has begun, fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayman committed Sep 21, 2014
1 parent 9c17ef9 commit 206c3cf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions client/views/playlists/playlists.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ var searchResultsDependency = new Deps.Dependency();

youtubeSearchQuery = function(options) {
options = options || {};
var currentSearchTimer = searchTimer;

Meteor.call('youtube_search', options, function(error, data) {
if (error) {
Expand All @@ -428,6 +429,11 @@ youtubeSearchQuery = function(options) {
searchResults = data; // TODO: search result data != videoQuery data
searchResultsDependency.changed();

if (currentSearchTimer != searchTimer) {
console.warn('cancel video query');
return;
}

// query for more details (needs optimization)
var ids = _.pluck(_.pluck(data.items, 'id'), 'videoId');
console.log('load more data for ', ids);
Expand Down

0 comments on commit 206c3cf

Please sign in to comment.