oModel

Simplest JS Model with listeners

View the Project on GitHub oscarmorrison/oModel

oModel

oModel is a work in progress, with no public release yet.

Goal

Build a super simple js model that allows for onChange call backs.

Insperation

Docs

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);
person.update('name', 'george');

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: 25}