observer-util: Not accessing the changed property doesn't call observe second time

.observe() callback is not called if the changed property getter is not executed in the .observe() callback. Take a look at the example below. Execute it then try uncommenting the line and commenting the one above.

const observer = require('@risingstack/nx-observe');

const observable = observer.observable();

// This way doesn't call the callback twice
observer.observe(() => console.log(observable));

// This way works
// observer.observe(() => console.log(observable.value));

observable.value = 3;

setTimeout(() => observable.value = 4);

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

Going to also add some basic benchmarks (nx-observe vs vanilla js for now). I guess it might be interesting for you too. (Right now I only have benchmarks for the whole nx-framework together)

Just to clarify: instead of binding on observable properties once, nx-observe looks for yet unregistered parts of the function (hidden by conditionals or loops) on every run and binds on the newly revealed properties.