enhanced array
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.gitmodules
.jshintrc
Gruntfile.js
History.md
Makefile
Readme.md
component.json
index.js
mocha.opts
package.json
project.sublime-project

Readme.md

modelarray

simple arrays of models with the following features:

  • behave just like an array (ie Array.isArray(myModelArray) === true)
  • emit add /remove / reset / sort events
  • ensure unicity of items

    the rest is up to you!

Example

 var jeremy = new User({id: 1, name: 'jeremy'}),
     mehdi = new User({id: 2, name: 'mehdi'}),
     pg = new User({id: 3, name: 'pg'}),
     thomas = new User({id: 4, name: 'thomas'});

 // use Users items...
 var users = new modelArray([pg, mehdi, jeremy], User);

 // or pojo
 var objs = new ModelArray([{id: 1, name: 'pg'}, {id: 2, name: 'pg'}]);

 // or String (or Numbers, or anything else...)
 var strs = new ModelArray(['pg', 'mehdi', 'jeremy']);

 // push will cast items, remove duplicate
 models.push(pg, thomas, {id: 5, name: joe});

 // remove some items
 models.remove(jeremy, mehdi);

 users.on('add', function (models) { /* do something on add */});
 users.on('remove', function (models) { /* do something on remove */});

Installation

Install with component(1):

$ component install pgherveou/modelarray

Install with npm(2):

$ npm install modelarray

Api

coming soon...

License

MIT