Array properties for Swatinem/model
$ component install Swatinem/model-array
Registers an array property with name.
By default, it emits simle change events when any change to the array is made.
note: This is not working and pending some upstream changes
to MatthewMueller/array.
If options.events is set to false, no change events will be emitted when
the array changes.
If options.detailedEvents is set, more detailed events are emitted such as:
('add', element, index)
('remove', element, index)
('sort')
('reverse')If options.childEvents is set, the array is assumed to contain Models itself.
Events of the child models are emitted like this:
('child', element, childProperty, value, previousValue)note: The array instance is fixed and can not be overwritten. There is a transparent setter that replaces all the elements but the array itself will not be overwritten.
var Model = require('model');
var MArray = require('model-array');
var User = new Model(['first', 'last'])
.use(MArray)
.array('pets');
var instance = new User({first: 'Arpad', last: 'Borsos', pets: ['Ansa']});
instance.on('change pets', function () {});
instance.pets.push('Zwara'); // triggers change eventLGPLv3
Released as free software as part of ChatGrape


