https://github.com/azer/new-object
Objects that you can subscribe to changes.
https://github.com/azer/new-object
Last synced: 11 months ago
JSON representation
Objects that you can subscribe to changes.
- Host: GitHub
- URL: https://github.com/azer/new-object
- Owner: azer
- Created: 2013-04-30T08:56:00.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-07-24T00:41:47.000Z (almost 13 years ago)
- Last Synced: 2024-04-15T03:09:39.092Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 47.9 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## new-object [](https://travis-ci.org/azer/new-object)
Objects that you can subscribe to changes. See also: [new-list](https://github.com/azer/new-list)
## Install
```bash
$ npm install new-object
```
## Usage
```js
prices = newObject({ apple: 3, grape: 4 })
prices('banana', 1)
prices('apple')
// => 3
prices('banana')
// => 1
```
Subscribing to changes:
```js
prices('cherry', 5)
prices('apple', 2)
prices.rm('banana')
prices.subscribe(function(update){
update.set
// => { cherry: 5, apple: 2 }
update.rm
// => ['banana']
})
```
## Publishing Custom Updates
```js
people = newObject({ john: { age: 21 city: 'SF' }, smith: { age: 23, city: 'NYC' } })
people.subscribe(function(update){
if(update.person)
debug('%s was updated', update.person)
})
people('john').age = 22;
people.publish({ person: 'john' })
```
See tests for more information.