model
ES5 minimalistic extensible model component.
By using Object.defineProperty
, change
event is automaticaly emited on value set.
this feature can make it works with reactive.
You may need polyfill code for ie < 9
Install
npm i model-component
API
Model(name)
Factory method, Create a new model with the given name
.
var Model = var User =
Model.attr(name, [meta])
Define an attribute name
with optional meta
data object (used by plugins).
Model.method(name, fn)
Add function with name to model prototype
.changed([attr])
Return false
or an object
containing the "dirty" attributes.
Optionally check for a specific attr
.
.clean()
Set current attrs as original attrs
.set(attrs)
Set multiple attrs
.
.has(attr)
Check if attr
is present (not null
or undefined
).
.use(plugin)
Plugin is called with Model class
Events
change
event emitted on model instance.
user
change $stat
event emitted on model stat change
user
Add methods to model
Usermethod'destroy' {var self = thisapi}
Testing
using webpack-dev-server
$ npm install webpack webpack-dev-server -g
$ npm install
$ make test
License
MIT