You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you'd like to be notified about any possible change that could happen to a JSON compatible model / data / object / array / structure,
including the possibility to retrieve the exact full path of the object that changed and eventually walk through it,
you've reached your destination.
constdata=Introspected(// any object or JSON compatible structure// even with nested properties, objects, arraysJSON.parse('{}'),(root,path)=>{// the root object that changedconsole.log(root);// the path that just changedconsole.log(path);});// now try the following in consoledata.a.b.c.d.e.f.g='whatever';data.array.value=[1,2,3];data.array.value.push(4);// see all notifications about all changes 🎉JSON.stringify(data);// {"a":{"b":{"c":{"d":{"e":{"f":{"g":"whatever"}}}}}},"array":{"value":[1,2,3,4]}}
API
Introspected(objectOrArray[, callback]) create a new Introspected object capable of having infinite depth without ever throwing errors
Introspected.observe(objectOrArray, callback) crate a Introspected with a notifier per each change, or set a notifier per each change to an existent Introspected object
Introspected.pathValue(objectOrArray, path) walk through an object via a provided path. A path is an Array of properties, it is usually the one received through the notifier whenever a Introspected object is observed.
Compatibility
Any spec compliant ES2015 JavaScript engine.
(that means native WeakMap, Proxy and Symbol.toPrimitive too)