-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jake Harding
committed
Mar 13, 2013
1 parent
04d8f2a
commit d789c4b
Showing
6 changed files
with
103 additions
and
52 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,13 +10,22 @@ var Dataset = (function() { | |
utils.bindAll(this); | ||
|
||
if (o.template && !o.engine) { | ||
throw new Error('no template engine specified'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jharding
Contributor
|
||
$.error('no template engine specified'); | ||
} | ||
|
||
if (!o.local && !o.prefetch && !o.remote) { | ||
$.error('one of local, prefetch, or remote is requried'); | ||
} | ||
|
||
this.name = o.name; | ||
this.limit = o.limit || 5; | ||
this.template = compileTemplate(o.template, o.engine); | ||
|
||
// used in #initialize | ||
this.local = o.local; | ||
this.prefetch = o.prefetch; | ||
this.remote = o.remote; | ||
|
||
this.keys = { | ||
version: 'version', | ||
protocol: 'protocol', | ||
|
@@ -40,6 +49,7 @@ var Dataset = (function() { | |
|
||
_loadPrefetchData: function(o) { | ||
var that = this, | ||
deferred, | ||
version = this.storage.get(this.keys.version), | ||
protocol = this.storage.get(this.keys.protocol), | ||
itemHash = this.storage.get(this.keys.itemHash), | ||
|
@@ -55,12 +65,16 @@ var Dataset = (function() { | |
itemHash: itemHash, | ||
adjacencyList: adjacencyList | ||
}); | ||
|
||
deferred = $.Deferred().resolve(); | ||
} | ||
|
||
else { | ||
$.getJSON(o.url).done(processPrefetchData); | ||
deferred = $.getJSON(o.url).done(processPrefetchData); | ||
} | ||
|
||
return deferred; | ||
|
||
function processPrefetchData(data) { | ||
var filteredData = o.filter ? o.filter(data) : data, | ||
processedData = that._processData(filteredData), | ||
|
@@ -256,17 +270,20 @@ var Dataset = (function() { | |
|
||
// the contents of this function are broken out of the constructor | ||
// to help improve the testability of datasets | ||
initialize: function(o) { | ||
if (!o.local && !o.prefetch && !o.remote) { | ||
throw new Error('one of local, prefetch, or remote is requried'); | ||
} | ||
initialize: function() { | ||
var deferred; | ||
|
||
this.local && this._processLocalData(this.local); | ||
this.transport = this.remote ? new Transport(this.remote) : null; | ||
|
||
this.transport = o.remote ? new Transport(o.remote) : null; | ||
deferred = this.prefetch ? | ||
this._loadPrefetchData(this.prefetch) : | ||
$.Deferred().resolve(); | ||
|
||
o.local && this._processLocalData(o.local); | ||
o.prefetch && this._loadPrefetchData(o.prefetch); | ||
this.local = this.prefetch = this.remote = null; | ||
this.initialize = function() { return deferred; }; | ||
|
||
return this; | ||
return deferred; | ||
}, | ||
|
||
getSuggestions: function(query, callback) { | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
What was the reason to wrap the error through JQuery instead?