S.value multiple updates with no listeners fail
webstrand opened this issue · 1 comments
If you create an S.value
and update it multiple times before attaching any listeners, the Value erroneously reports conflicting values.
var foo = S.value(100);
foo(200); // Succeeds
foo(300);
// Error: conflicting values: 300 is not the same as 200
I believe this happens, because on line 267 the DataNode
does not cause to RootClock
to tick if it has no listeners. So S.value's age
is equal to the RootClock.time
causing the fault.
A fix would be to preserve the age
of the S.value
when RunningClock == null
and no listeners.
if (arguments.length === 0) {
return node.current();
}
else if(RunningClock === null && node.log === null) {
return current = node.next(update!);
} else {
var same = eq ? eq(current, update!) : current === update;
if (!same) {
var time = RootClock.time;
if (age === time)
throw new Error("conflicting values: " + update + " is not the same as " + current);
age = time;
current = update!;
node.next(update!);
}
return update!;
}
Just ran into this ourselves.
This is also hotfixed by always setting this.log = new Log()
in the DataNode
constructor. It looks like an optimization to reduce memory usage (❤️ always appreciated) by not allocating a new Log
object for all data signals that may not be used in computations, but that gets bugged when no computations actually use the value.
@adamhaile any chance of getting a fix for this? :)