obs-model

Extensible observable models.

Synopsis

obs-model provides a minimal baseline for defining MVC or MVVM models with observable attributes.

Basic usage example

var User = model('User')
    .attr('id')
    .attr('username');
 
var bob = new User({id: 1, username: 'bob'});
 
bob.username.subscribe(function(value) {
    console.log("Bob's username is now: " + value);
});
 
bob.username('admin');
// -> "Bob's username is now: admin" 

API

Create a Model with the given name.

The model's name as passed to model().

Defines a new attribute with the given name. The options can be an object containing configuration data for model plugins.

The attribute will appear as an observable property on new model instances.

Adds the given plugin to the model. The function will later be called by the model's constructor with this set to the new model instance.

This method is the backbone of model extensibility.

The Model this model is an instance of.

Runs the model's destructors. Plugins can use these to free event listeners, subscriptions and such.

License

The MIT/Expat license.