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.
- Host: GitHub
- URL: https://github.com/positlabs/model-o
- Owner: positlabs
- License: unlicense
- Created: 2016-11-12T23:45:51.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-29T18:53:41.000Z (over 7 years ago)
- Last Synced: 2024-10-19T07:06:44.493Z (7 months ago)
- Language: HTML
- Size: 22.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# model-o
Simple observable model. Fires change events when values are assigned. Get excited!
[](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')```