1.0.0 • Published 6 years ago
@teleology/observer v1.0.0
@teleology/observer
A recursive, proxy-based observer for JS objects
Installation
npm install --save @teleology/observer
or
yarn add @teleology/observer
Usage
Example:
// es6+
import observer from '@teleology/observer';
// require
// const { default: observer } = require('@teleology/observer');
const account = {
name: {
firstName: 'chris',
lastName: 'Sullivan',
}
};
const observedAccount = observer(account, (change) => {
console.log('Changed', change);
});
observedAccount.name.firstName = 'Chris';
// Changed { prop: 'firstName', value: 'Chris', oldValue: 'chris' }
Change
Key | Type | Description |
---|---|---|
value | any | The value currently being set |
oldValue | any | The value being replaced |
prop | string | The property key name |
Notes
- The original object is not modified
- The returned proxy is observable, not the original object
- Changes only occur when the value changes (redundancies are ignored)
1.0.0
6 years ago