GitXplorerGitXplorer
l

track-mutation

public
0 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
eef9d8915b47dbf3757c0419180843cdb7eabb94

1.0.1

llyonbot committed 4 years ago
Unverified
f8b376ed268860ba1bb97549e9a58e1c062167e9

feat: esm and cjs

llyonbot committed 4 years ago
Unverified
b218d4f8c69e0de38b308c8549bc50cd2e6eaee8

init

llyonbot committed 4 years ago

README

The README file for this repository.

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