modella-computed
v1.2.1
Published
Define computed properties on modella models
Downloads
5
Maintainers
Readme
modella-computed
Define computed properties on modella models.
Usage
var computed = require('modella-computed')
var Mustard = model('Mustard')
.use(computed)
.attr('color', {
defaultValue: 'Golden'
})
.attr('flavor', {
// defines a constant
value: 'Spicy'
})
.attr('name', {
// defines a getter, invoked with model bound as `this` context
get: function () {
return this.flavor() + ' ' + this.color()
}
})
var mustard = new Mustard({ color : 'Brown' });
mustard.name(); // 'Spicy Brown'
mustard.set({ color: 'Yellow' })
mustard.name(); // 'Spicy Yellow'