Skip to content

Swatinem/model-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Model-array

Array properties for Swatinem/model

Build Status Coverage Status Dependency Status

Installation

$ component install Swatinem/model-array

.array(name, [options])

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.

Usage

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 event

License

LGPLv3

Released as free software as part of ChatGrape

About

Array properties for Swatinem/model

Resources

Stars

Watchers

Forks

Packages

No packages published