oModel is a work in progress, with no public release yet.
Build a super simple js model that allows for onChange call backs.
- Backbone.Model (Jeremy Ashkenas you're brilliant!)
- Mettle
TBD bower and npm dependency
- compatible as client or node dependancy
Create a new model (without any attributes)
var person = new Model();or with attributes / properties
var person = new Model({
name: 'oscar'
});Set / Update attributes
person.set('age', 25);...or multiple at once
person.update({
name: 'george',
age: 20
});update is an alias for set
Listen to models
var callback = function(attributes) {
console.log(attributes);
}
person.onChange(callback);OnChange
person.update('name', 'edward');
// callback log
// {name: 'edward', age: 20}Stop listening to models for callback
person.off(callback)Stop listening to models all
person.off()