From 681a3012ee17ed876c777d88810c3232d3ed10b3 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Fri, 4 May 2012 23:29:26 -0700 Subject: Use proxy, and make the bookmark refresh more readable --- lib/completion.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'lib/completion.js') diff --git a/lib/completion.js b/lib/completion.js index bb869206..13be5551 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -118,27 +118,24 @@ var completion = (function() { /** A fuzzy bookmark completer */ var FuzzyBookmarkCompletionSource = AsyncCompletionSource.extend({ traverseTree: function(bookmarks, results) { - var self = this; bookmarks.forEach(function(bookmark) { results.push(bookmark); if (bookmark.children === undefined) return; - self.traverseTree(bookmark.children, results); - }); + this.traverseTree(bookmark.children, results); + }.proxy(this)); }, refresh: function() { - var self = this; - self.reset(); + this.reset(); chrome.bookmarks.getTree(function(bookmarks) { var results = []; - self.traverseTree(bookmarks, results); - - self.resultsReady(results.filter(function(b) { return b.url !== undefined; }) - .map(function(bookmark) { - return self.createInternalMatch('bookmark', bookmark); - })); - }); + this.traverseTree(bookmarks, results); + var validResults = results.filter(function(b) { return b.url !== undefined; }); + var matches = validResults.map( + function(bookmark) { return this.createInternalMatch("bookmark", bookmark); }.proxy(this)); + this.resultsReady(matches); + }.proxy(this)); } }); -- cgit v1.2.3