Observable-Model
Package deliver light-weight model with ability to set-up custom validation and attribute change comparator.
Usage
let Model = let model =
Features
Setting and Getting Attributes
You can set, get and remove attributes from Model.
model // 'change:value' event emited model // handle attribute change model // --> value
You can set multiple attributes by passing object.
model model // --> namemodel // --> 1
Changing attribute emits 'change:${attributeName}'
event with new value as argument.
Basic comparator is ===
operator.
Comparator
You can set custom compare function for looking for changes
model model // -> emits 'change:value' event model // -> doesn't emit 'change:value' event model // -> emit 'change:value' event
model // You can use functions from external libraries.
model // Removes Comparator
Validation
modelmodelmodel // -> emits 'unvalid:value' eventmodel // value: 2model // returns falsemodel // removes value validationmodel // now you are free to set value again
Validation on failiture emits 'unvalid:${attributeName}'
event with unvalid value as argument.
Event Driver
Model extends event-driven-object https://www.npmjs.com/package/event-driven-object