Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a watcher for a computed depending on two sources is notified, if one source updates and a watcher is added during notification to the other source, an internal error is thrown #192

Open
dead-claudia opened this issue Apr 24, 2024 · 3 comments

Comments

@dead-claudia
Copy link
Contributor

Repro for 0.1.0: link

Source:

const WA = new Signal.subtle.Watcher(() => {
  console.log("watch WA")
  WC.watch(C)
})

const WC = new Signal.subtle.Watcher(() => {
  console.log("watch WC")
})

const A = new Signal.Computed(() => {
  console.log("get A")
  B.get()
  C.get()
  console.log("get A end")
})

const B = new Signal.State(1)
const C = new Signal.State(1)

A.get()
WA.watch(A)

B.set(2)
@dead-claudia
Copy link
Contributor Author

Same issue when reusing WA: link

Source:

const WA = new Signal.subtle.Watcher(() => {
  console.log("watch WA")
  WA.watch(C)
})

const A = new Signal.Computed(() => {
  console.log("get A")
  B.get()
  C.get()
  console.log("get A end")
})

const B = new Signal.State(1)
const C = new Signal.State(1)

A.get()
WA.watch(A)

B.set(2)

@robbiespeed
Copy link

I suspect this Error is intentional in order to avoid any mutation of the graph (other than dirtying) during the dirtying phase. Calling .watch(signal) will potentially and add new consumer<->producer links to the graph, which might or might not trigger the Watchers notify callback again in the same dirtying phase.

@dead-claudia
Copy link
Contributor Author

C isn't dirty, only A and B are. And when pre-added, WC isn't notified, only WA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants