model-o
v1.1.0
Published
Simple observable model. Fires change events when values are assigned.
Downloads
11
Readme
model-o
Simple observable model. Fires change events when values are assigned. Get excited!
npm install --save model-o
usage
var model = new Model_O({
str: 'hello',
obj: {
a: 'a' // NOTE: unwatchable
},
subModel: new Model_O({
a: 'a' // watchable
}),
bool: true,
num: 123.4567,
arr: [1, 2, 3, 4, 5]
})
console.log(model)
var onChange = function(newval, oldval, key){
console.log(key, 'newval: ' + newval + ', oldval: ' + oldval)
}
model.on('str', onChange)
model.str = 'asdf'
model.str += 'asdf'
model.subModel.on('a', onChange)
model.subModel.a = 'A'
model.on('arr', onChange)
model.arr = model.arr.concat('extra')