24:b7d97ca5ea2c
Anton Shestakov <av6@dwimlabs.net>, Wed, 22 Jun 2016 13:59:56 +0800
backbone.shard: add indexBy method, test it

next change 26:4e7999b5675c
previous change 23:803ba407e901

README.md

Permissions: -rw-r--r--

Other formats: Feeds:
Overview
========
Backbone.Shard is a variation on a Subset taken from different perspective.
Shard was built as a simple "persistent filter" for collections; it can help
grouping and displaying items of certain kind based on your filter function. I
know it works for me, but your mileage may vary.
Usage
=====
It's easy if you're familiar with Backbone.Collection since Shard shares with
it most of the methods marked **Underscore methods** in the
[documentation](http://backbonejs.org/#Collection-Underscore-Methods):
:::javascript
var shelf = Backbone.Shard({
collection: books,
filter: function(book) { return book.get('read'); }
});
shelf.each(...);
shelf.pluck(...);
You can add/remove models or reset *the original collection* and Shard will
honestly try to keep up with it, but currently Shard itself has no methods such
as add/remove/reset.
Events work and respect your filter function:
:::javascript
shelf.on('add', doSomething);
collection.add({read: true}); // this will call doSomething
collection.add({read: false}); // this won't
Tests
=====
Tests can be run [here](https://demos.dwimlabs.net/backbone-shard/test/) or you
can download the
[source](https://bitbucket.org/av6/backbone-shard/get/tip.tar.bz2) and open
test/index.html in your browser.