adelriosantiago
adelriosantiago

Reputation: 8124

Lowest-level way to observe object changes

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:

Is it possible? How?


I can't use:

Upvotes: 0

Views: 263

Answers (1)

Daniel Perez
Daniel Perez

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

Related Questions