https://github.com/oscarmorrison/omodel
Simplest JS Model with listeners
https://github.com/oscarmorrison/omodel
Last synced: about 1 year ago
JSON representation
Simplest JS Model with listeners
- Host: GitHub
- URL: https://github.com/oscarmorrison/omodel
- Owner: oscarmorrison
- Created: 2016-12-04T16:11:25.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-06T02:44:46.000Z (over 9 years ago)
- Last Synced: 2025-01-22T13:16:30.920Z (over 1 year ago)
- Language: JavaScript
- Homepage: http://oscarmorrison.com/oModel
- Size: 33.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
- [Backbone.Model](http://backbonejs.org) (Jeremy Ashkenas you're brilliant!)
- [Mettle](https://github.com/jmoyers/mettle)
## Installation
*TBD bower and npm dependency*
- compatible as client or node dependancy
## API Docs
**Create a new model** (without any attributes)
```javascript
var person = new Model();
```
**or with attributes / properties**
```javascript
var person = new Model({
name: 'oscar'
});
```
**Set / Update attributes**
```javascript
person.set('age', 25);
```
**...or multiple at once**
```javascript
person.update({
name: 'george',
age: 20
});
```
*update is an alias for set*
**Listen to models**
```javascript
var callback = function(attributes) {
console.log(attributes);
}
person.onChange(callback);
```
**OnChange**
```javascript
person.update('name', 'edward');
// callback log
// {name: 'edward', age: 20}
```
**Stop listening to models for callback**
```javascript
person.off(callback)
```
**Stop listening to models all**
```javascript
person.off()
```