Skip to content
This repository has been archived by the owner on Dec 20, 2023. It is now read-only.

mongodb-js/ampersand-collection-filterable

Repository files navigation

ampersand-collection-filterable

build status

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