tc39 / proposal-signals

A proposal to add signals to JavaScript.
MIT License
2.87k stars 54 forks source link

Watchers have inconsistent state inside `watched` callback #208

Open prophile opened 2 weeks ago

prophile commented 2 weeks ago

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.