proposal-signals
proposal-signals copied to clipboard
Watchers have inconsistent state inside `watched` callback
Consider the following code:
let watcher
const a = new Signal.State(0, {
[Signal.subtle.watched]: () => {
console.log(Signal.subtle.introspectSinks(a))
console.log(Signal.subtle.introspectSources(watcher))
},
})
watcher = new Signal.subtle.Watcher(() => {
console.log("notified")
});
watcher.watch(a);
Inside the watched callback, a is reported as having no sinks, but watcher does have a as a source – a visibly inconsistent state.
This could be solved either way, by updating both before the callback or both after. I have no opinion on the options.