superfeedr/indexeddb-backbonejs-adapter — pull request #73 by ncortines (2014-11-26 11:49:18+00:00)
Title: Some few additional features for displaying large sets of data

Hi,

I wanted to propose the adding of the following features, which are aimed to support the displaying on large sets of data with additional sorting/filtering options:
* New `indexName` string parameter: Allows the user to fetch ALL records in the store using the specified index. Useful for getting lists sorted by different criteria
* New `filter` function parameter: Allows the user to filter out records which do not pass the filter function validation. Useful to extend the IndexedDB filtering capabilities, i.e. filtering with text wildcard or some complex condition
* Support for `always` and `abort` in the returned deferred/promise object

The example explains the use case:

```javascript

var promise, // to reference the latest fetch promise
loading = false, // a loading indicator
movies = new Movies(); // which contains thousands of records

function loadMoviesCollection (textFilter, sortCriteria) {

if (promise) {
promise.abort(); // since movies collection contains thousands of records, the latest fetch operation may not be completed yet - abort it
}

movies.reset(); // clear the collection

loading = true; // loading again

promise = movies.fetch({
indexName: sortCriteria, // the sorting criteria may be different each time, i.e. sorting by 'name' or 'year', etc
addIndividually: true, // we want a responsive UI
filter: function (movie) {
return movie.name.indexOf(textFilter) !== -1); // this kind of filtering is not supported in indexeddb and we don't want the overhead of adding these items to the collection. Filtering them in a collection with thousands of records would be too slow. This is faster and much more responsive
}
}).done(function () {
console.log('done!'); // done successfully - all items loaded
}).error(function () {
console.log('error!'); // some error occurred while fetching
}).always(function () {
loading = false; // always
});
}

loadMoviesCollection('The', 'name');

// Before promise is resolved user selects a different filtering/sort criteria

loadMoviesCollection('The', 'year');

```

Please let me know what you think of these enhancements.

Thanks!