Reputation: 8124
A real-time app that must broadcast a big object to all clients as soon as it changes.
What is the the lowest-level way to observe any change in a Node.JS object?
For example, given the object:
var obj = {
num: 3,
deep: {
num: 5
}
}
A function would be triggered after calling any of these:
obj.num = 10;
obj.num.deep.num = 10;
obj.num.deep = undefined;
Is it possible? How?
I can't use:
Upvotes: 0
Views: 263
Reputation: 6903
Depending on your requirements, this should be doable by exposing a proxy of your object instead of the object itself. You could then intercept the setter in the proxy, and trigger an event from there.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy https://caniuse.com/#feat=proxy
Upvotes: 1