ampersand-collection-filterable
v0.3.0
Published
Simple filterable ampersand collections
Downloads
73
Readme
ampersand-collection-filterable
Simple filterable ampersand collections
Example
var filterable = require('../ampersand-collection-filterable'),
AmpersandCollection = require('ampersand-collection'),
AmpersandState = require('ampersand-state');
var Candy = AmpersandState.extend({
props: {
id: 'number',
name: 'string'
}
});
var CandyCollection = AmpersandCollection.extend(filterable, {model: Candy});
var bag = new CandyCollection([
{id: 1, name: 'Reese\'s Egg'},
{id: 2, name: 'Snickers'},
{id: 3, name: 'Three Musketeers'},
{id: 4, name: 'Milky Way'},
{id: 5, name: 'Twix'}
]);
bag.filter(function(candy){
return candy.name === 'Twix';
});
assert.equal(bag.length, 1);
bag.add({id: 6, name: 'Peppermint Patty'});
assert.equal(bag.length, 1);
bag.unfilter();
assert.equal(bag.length, 6);
Installation
npm install --save ampersand-collection-filterable
Testing
npm test
License
MIT