A Javascript Implementation of Array Collection (using UndercoreJS)
npm:
npm install js-arraycollection
bower
bower install js-arraycollection
coffeescript example:
(inst = new ArrayCollection [{value:'foo'}, {value:'bar'}]
).on 'collectionChanged', (data)->
data.keys().forEach (key, val)->
console.log "#{key}:#{JSON.stringify val}"
inst.addItem value:'baz'
inst.getItemAt(0).value = 'huzzah'
inst.removeItemAt inst.length() - 1
javascript example:
var inst;
(inst = new ArrayCollection( [{value:'foo'}, {value:'bar'}] )
).on( 'collectionChanged', function (data) {
data.keys().forEach( function (key, val) {
console.log(""+key+": "+JSON.stringify( val ) );
});
});
inst.addItem( {value:'baz'} );
inst.getItemAt(0).value = 'huzzah';
inst.removeItemAt( inst.length() - 1 );
Triggered when an item is added to the collection
Triggered when an item's properties have been updated
Triggered when an item has been removed
Triggered when an item has been replaced with another
Triggered when the collection has been reset to it's default state
Returns the current length of the Array
Sets the source array triggering an added
event
Resets the source array resulting in a reset
event
Adds all passed list members to source triggering an added
event
Add an individual item to the source triggering an added
event
Adds an individual item to the source at given offset triggering an added
event
Checks if source contains specified item
Get item at given index
Get index of given item in source
Removes all members in source triggering a reset
event
Removes item at given index triggering remove
event
Replaces item at index with given item triggering replaced
event