From 9f026c45189766f74231b6abcc022a81aca964be Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sat, 5 May 2012 00:05:58 -0700 Subject: Favor composition over inheritence. Much easier to follow. --- lib/completion.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/completion.js b/lib/completion.js index fefa92fa..a00f2dab 100644 --- a/lib/completion.js +++ b/lib/completion.js @@ -6,9 +6,7 @@ var completion = (function() { init: function() { this.id = utils.createUniqueId(); this.reset(); - this.resultsReady = this.fallbackReadyCallback = function(results) { - this.completions = results; - } + this.resultsReady = this.fallbackReadyCallback = function(results) { this.completions = results; } }, reset: function() { @@ -116,7 +114,10 @@ var completion = (function() { }); /** A fuzzy bookmark completer */ - var FuzzyBookmarkCompletionSource = AsyncCompletionSource.extend({ + var FuzzyBookmarkCompletionSource = Class.extend({ + init: function() { this.asyncCompleter = new AsyncCompletionSource(); }, + filter: function(query, callback) { return this.asyncCompleter.filter(query, callback); }, + // Traverses the bookmark hierarhcy and retuns a list of all bookmarks in the tree. traverseBookmarkTree: function(bookmarks) { var results = []; @@ -131,13 +132,14 @@ var completion = (function() { }, refresh: function() { - this.reset(); + this.asyncCompleter.reset(); chrome.bookmarks.getTree(function(bookmarks) { var results = this.traverseBookmarkTree(bookmarks); 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); + var matches = validResults.map(function(bookmark) { + return this.asyncCompleter.createInternalMatch("bookmark", bookmark); + }.proxy(this)); + this.asyncCompleter.resultsReady(matches); }.proxy(this)); } }); -- cgit v1.2.3