Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Make an observable based on an object property.
JavaScript
tag: v0.0.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.md
index.js
package.json
tests.js

README.md

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
Something went wrong with that request. Please try again.