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
;; let collection = some: 'value' another: 'value' arr: 1 2 3 ; /* accessing models */collection;// => { some: 'value' } collection;// returns array of models in range (includes end index model)// => [BehaveImmutabe, ..., BehaveImmutable] collection;// returns array of models containing values given// => [BehaveImmutabe] || [] collection;// returns first model containing the values given// => BehaveImmutabe || undefined /* iterating over the collection */collection;// => BehaveCollection var rawJS = collection;// => [{some: 'value'}, {another: 'value'}, {arr: [1, 2, 3]}] var filteredModels = collection;// get latest version of data, get `some` property from that data /* quick extraction of collection data */collection;// => [{ some: 'value' }, { another: 'value' }, { arr: [1, 2, 3] }] collection;// => [{ "some": "value" }, { "another": "value" }, { "arr": [1, 2, 3] }] /* altering the collection */collection;// adds a model to the collection, fires add event unless opts.silent is true var batched = collection;// returns array of added models, fires add event for each model unless opts.silent is true var removed = collection;// removes a model from the collection, fires remove event unless opts.silent is true collection;// remove all models from the collection collection;// get count of models
Testing
Run npm install
and then run npm test
.
Release History
- 0.1.0 Initial Release