node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



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

For an example of extending models with plugins, see the validation plugin.

browser support

Build Status NPM version Dependencies



With NPM

npm install obs

From source

git clone
cd obs-model
npm install
make && make dist


With component

component install pluma/obs-model

Learn more about component.

With a CommonJS module loader

Download the latest minified CommonJS release and add it to your project.

Make sure you also have a compatible copy of assimilate and obs.

Learn more about CommonJS modules.

With an AMD module loader

Download the latest minified AMD release and add it to your project.

Make sure you also have a compatible copy of assimilate and obs.

Learn more about AMD modules.

Basic usage example

var model = require('obs-model');
var User = model('User')
    .attr('fullname', {
        read: function() {
            return this.firstname() + ' ' + this.lastname();
        write: function(value) {
            var tokens = value.split(' ');
            this.lastname(tokens.join(' '));
        watch: ['firstname', 'lastname']
var john = new User({id: 1, username: 'jdoe', firstname: 'John', lastname: 'Doe'});
console.log(john.fullname()); // "John Doe" 
console.log(john.fullname()); // "John Smith" 
john.fullname('John von Johnson');
console.log(john.lastname()); // "von Johnson" 
john.username.subscribe(function(value) {
    console.log("john's username is now: " + value);
// -> "john's username is now: admin" 



Create a Model with the given name.


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

Model.attr(name, [options])

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

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

If either of these options is given, a computed observable with its context bound to the model will be created instead of a regular observable property.

If is given, may optionally be an array of attribute names the computed observable will monitor for changes.


If is given, options.lazy may optionally be a boolean determining whether the computed observable will use lazy evaluation.


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. If you add the same plugin multiple times, it will only be added once.

This method is the backbone of model extensibility.


If this function exists, it will be applied to the Model definition when the plugin is added.

This function can provide additional properties or behaviour to the Model type itself.

new Model([values])

Creates a new model instance. values is optionally an object mapping attribute names to their initial values.


The Model this model is an instance of.


An observable property representing each attribute.


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


This is free and unencumbered public domain software. For more information, see or the accompanying UNLICENSE file.