proposal-signals icon indicating copy to clipboard operation
proposal-signals copied to clipboard

Avoid creating a dependency edge when reading something which was written in the same computed?

Open littledan opened this issue 1 year ago • 1 comments
trafficstars

@trueadm pointed out that the following would be an infinite loop in our current signal design, but is not one in most existing signal implementations:

createEffect(() => {
  x.set(Math.random())
  console.log(x.get())
})

Given that the write occurred before the read, there is no actual data dependency on the prior value of x. Should we avoid creating this false edge?

littledan avatar Mar 30 '24 01:03 littledan

What would we expect from this?

const f = createComputed(() => x.get())
createEffect(() => {
  x.set(Math.random())
  console.log(f.get())
})

Are we looking for something that avoids these sorts of false edges in general, or just in the shallow/direct case?

shaylew avatar Mar 30 '24 03:03 shaylew