An open API service indexing awesome lists of open source software.

https://github.com/positlabs/model-o

Simple observable model. Fires change events when values are assigned.
https://github.com/positlabs/model-o

Last synced: about 2 months ago
JSON representation

Simple observable model. Fires change events when values are assigned.

Awesome Lists containing this project

README

        

# model-o

Simple observable model. Fires change events when values are assigned. Get excited!

[![npm version](https://badge.fury.io/js/model-o.svg)](https://badge.fury.io/js/model-o)

`npm install --save model-o`

[View the demo](https://positlabs.github.io/model-o/)

## usage

```javascript

var model = new Model_O({
str: 'hello',
obj: {
a: 'a' // NOTE: unwatchable
},
subModel: new Model_O({
a: 'a' // watchable
}),
bool: true,
num: 123.4567,
arr: [1, 2, 3, 4, 5]
})

console.log(model)

var onChange = function(newval, oldval, key){
console.log(key, 'newval: ' + newval + ', oldval: ' + oldval)
}
model.on('str', onChange)
model.str = 'asdf'
model.str += 'asdf'

model.subModel.on('a', onChange)
model.subModel.a = 'A'

model.on('arr', onChange)
model.arr = model.arr.concat('extra')

```