1.1.1 • Published 9 years ago

on-object-change v1.1.1

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

on-object-change

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Fire a callback when an object changes. Similar to other observe implementations like observed except it doesn't doesn't care for the type of changes, just the fact that the object changed.

let obj = {
  some: {
    nested: {
      property: true
    }
  }
}

const observe = require('on-object-change')

observe(obj, function () {
  console.log('object changed!')
})

obj.some.nested.property = false

Use case: reactive templating where you don't actually want to manually update the state.

const state = {}

const View = React.createClass({
  getInitialState: function () {
    return state
  }
})

const Component = React.render(<View />, document.query('#container'))

observe(state, function () {
  Component.replaceState(state)
})

Requirements

You are expected to supply the relevant polyfills for these functionality whenever appropriate:

  • ES6 let and const
  • Object.observe()
  • setImmediate()

API

observe(obj, callback)

Fires callback() whenever any of obj's nested properties change.

1.1.1

9 years ago

1.1.0

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.0.0

9 years ago