Created
September 27, 2010 18:15
-
-
Save mattparker/599527 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// A rough idea for a RecordSetIndex plugin | |
// Filtering, searching, sorting on the host RecordSet could use the index if | |
// it's available (possibly creating it the first time someone does a sort or whatever) | |
// So RecordSet.filter() should be something like: | |
/* | |
filter: function(k,v) { | |
if (this.hasIndex(k)) { | |
return this.getIndex(k).find(v); | |
} else { | |
// proceed as normal! | |
} | |
} | |
*/ | |
// Sorting would be similar, it'd just get the pre-sorted index | |
_index:{ | |
}, | |
initializer: function() { | |
var sorted = this.get("host").sort(this.get("sortFn")), | |
key = this.get("key"), | |
recVal; | |
sorted.each(function(r){ | |
recVal = r.getValue(key); | |
if (this._index[recVal] === undefined) { | |
this._index[recVal] = []; | |
} | |
this._index[recVal].push(r); // Or perhaps this._index[key].push(r.get("id")); | |
}); | |
}, | |
find: function(from, to) { | |
return this._index[v]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment