diff options
| author | Phil Crosby | 2012-05-05 00:05:58 -0700 |
|---|---|---|
| committer | Phil Crosby | 2012-05-05 18:32:13 -0700 |
| commit | 9f026c45189766f74231b6abcc022a81aca964be (patch) | |
| tree | e8840e91030b551e030ef460d92444917f7d9312 /lib/completion.js | |
| parent | 1b35b1c6b1ecb7c88b6d060de3cab0372928b4f1 (diff) | |
| download | vimium-9f026c45189766f74231b6abcc022a81aca964be.tar.bz2 | |
Favor composition over inheritence. Much easier to follow.
Diffstat (limited to 'lib/completion.js')
| -rw-r--r-- | lib/completion.js | 18 |
1 files changed, 10 insertions, 8 deletions
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)); } }); |
