Simple Data Models
See timoxley/react for a cleaner
solution without all this get
/set
nonsense.
$ component install timoxley/model
Initialize a new Model
with data
properties, or use as a mixin.
var Model = require('model')
var user = new Model({
name: 'Tim',
age: 27
})
// or as a mixin:
var User = function(data) {
this.set('name', data.name)
this.set('age', data.age)
}
Model(User.prototype)
Get the value of Model property specified by name
or if name
is not supplied, return the
whole current model.
var model = new Model({
name: 'Tim'
})
model.get('name') //=> 'Tim'
Set a property specified by name
to value
or
if supplied an Object
, add or update properties
on the model, as specified by the given Object
.
Will trigger change
events on the model if
the model changes.
var model = new Model({
name: 'Tim'
})
model.set('name', 'Tim Oxley')
model.set({
age: 27
)
model.get('name') //=> 'Tim Oxley'
model.get('age') //=> 27
MIT