angular/watchtower.js

Reaction functions should always get the current value

Opened this issue · 2 comments

When doing two watches with a reaction function that updates the value for the other watch, we get an infinite cycle right now:

setup({a:null, b:null});
watchGrp.watch(parse('a'), function(newValue) { context.b = newValue; });
watchGrp.watch(parse('b'), function(newValue) { context.a = newValue; });

context.a = 1;
context.b = 2;
var count;
do (
  count = watchGroup.detectChanged();
} while (count);

The problem here is that the value passed to the reaction function might have been updated by another reaction function and therefore might be stale. The right thing would be to read the current value again just before calling the reaction function.

Note that the people who created Object.observe must have thought about this problem, as the change record that Object.observe returns only contains the old value, but not the new value...

Also talked to @jbdeboer and he wants to change this for AngularDart as well...