https://github.com/lyonbot/track-mutation
Track object mutations with ES6 Proxy
https://github.com/lyonbot/track-mutation
Last synced: 5 months ago
JSON representation
Track object mutations with ES6 Proxy
- Host: GitHub
- URL: https://github.com/lyonbot/track-mutation
- Owner: lyonbot
- Created: 2021-06-11T11:40:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-06-11T12:29:51.000Z (about 5 years ago)
- Last Synced: 2025-10-02T04:49:23.460Z (9 months ago)
- Language: TypeScript
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# track-mutation
Track object mutations with ES6 Proxy. Simple and tested.
[](https://www.npmjs.com/package/track-mutation)
## Usage
```js
// import { createTrackingProxy } from 'track-mutation';
const { createTrackingProxy } = require('track-mutation');
const data = {
foo: 'hello',
bar: [1, 2, 3, 4],
baz: {
name: 'xxx',
age: 1234,
},
}
const controller = createTrackingProxy(data)
const proxy = controller.proxy
controller.addListener((type, path, value) => {
console.log(type, path, value)
})
proxy.baz.name = 'yyy' // => Console Output: set, ['baz', 'name'], 'yyy'
proxy.bar.push(5) // => Console Output: arrayMutation, ['bar'], ['push', 5]
delete proxy.foo // => Console Output: delete, ['foo'], undefined
// Note: all changes will apply to `data` the original object
// To stop observing changes, call this
controller.teardown()
```