track-mutation
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

track-mutation

Track object mutations with ES6 Proxy. Simple and tested.

npm

Usage

// 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()

Package Sidebar

Install

npm i track-mutation

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

14.3 kB

Total Files

5

Last publish

Collaborators

  • lyonbot