behave-collection
A collection class to simplify working with BehaveImmutable instances
BehaveImmutable models have a lot of great features but working with groups of them can be tough, BehaveCollection
strives to make this a trivial thing.
If you are not familiar with the concepts of BehaveImmutable models then I would suggest reading up on them first. This will help you understand the API of BehaveCollection
.
Install
npm install --save behave-collection
Usage
import BC from 'behave-collection';
import BI from 'behave-immutable';
let collection = new BC([
new BI({ some: 'value' }),
new BI({ another: 'value' }),
new BI({ arr: [1, 2, 3] })
]);
collection.at(0).toJS();
collection.range(0, 2);
collection.find({ some: 'value' });
collection.findWhere({ some: 'value' });
collection.each(m => m.set({ updated: true }));
var rawJS = collection.map(m => m.toJS());
var filteredModels = collection.filter(m => m.get().get('some') === 'value');
collection.toJS();
collection.toJSON();
collection.add(new BI({ model: true }));
var batched = collection.batch([
new BI({ some: 'value' }),
new BI({ another: 'value' }),
new BI({ arr: [1, 2, 3] })
]);
var removed = collection.remove(collection.at(0)._id);
collection.purge();
collection.count();
Testing
Run npm install
and then run npm test
.
Release History