Skip to content

Like ES6 proxies but deeper. Will notify you whenever a property of an object is updated, no matter how nested it is.

License

Notifications You must be signed in to change notification settings

alessioalex/recursive-object-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

recursive-object-proxy

Like ES6 proxies but deeper. Will notify you whenever a property of an object is updated, no matter how nested it is.

npm i recursive-object-proxy

const proxyObject = require('recursive-object-proxy');

const o = {
  a: [
    1, 2, 3, 4, [ 5, 6, 7]
  ],
  b: {
    c: { d: [1, 2, 3], e: 5 }
  }
};

const obj = proxyObject(o, (path, val, isRemoved) => {
  console.log('proxy notification: ');

  if (isRemoved) {
    console.log(`removed ${path}`);
  } else {
    console.log(`${path} =`, val);
  }
});

obj.a[3] = { bb: 22, cc: 44 };
// console output: proxy notification: a[3] = { bb: 22, cc: 44 }

See example.js for more examples.

Extra

More about proxies: http://exploringjs.com/es6/ch_proxies.html

Similar projects:

License MIT

https://alessioalex.mit-license.org/

About

Like ES6 proxies but deeper. Will notify you whenever a property of an object is updated, no matter how nested it is.

Resources

License

Stars

Watchers

Forks

Packages