observable_property

0.0.3 • Public • Published

Observable Property

A small utility to convert an object property into an observable.

Install

Install on NPM or Bower: observable_property.

Usage

Create an observable

> var Observable = require('observable_property')
  var person = { name : 'bob' }
  var val = Observable(person, 'name')

Getting the value

> val() 
'bob'

Setting the value

> val('dan')
> val()
'dan'
> person.name
'dan'

Getting notified

> var stopNotifying = val(function(newVal){
    console.log('Was changed to', newVal)
  })
> val('james')
Was changed to james

Stop getting notified

> stopNotifying()

Getting notified via Emmitt

> var E = require('emmitt')

> E.on(person, 'change:name', function(value){
    console.log('Name was changed to', value)
  })

> val('jamison')
Name was changed to jamison

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.0.30latest

Version History

VersionDownloads (Last 7 Days)Published
0.0.30
0.0.20
0.0.10

Package Sidebar

Install

npm i observable_property

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • airportyh