on-object-change
v1.1.1
Published
Fire a callback when an object changes
Downloads
12
Readme
on-object-change
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
andconst
Object.observe()
setImmediate()
API
observe(obj, callback)
Fires callback()
whenever any of obj
's nested properties change.