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

False positive in cycle detection for asymmetric cycles #201

Open
prophile opened this issue Apr 29, 2024 · 0 comments
Open

False positive in cycle detection for asymmetric cycles #201

prophile opened this issue Apr 29, 2024 · 0 comments

Comments

@prophile
Copy link
Contributor

Consider the following code:

import { Signal } from './dist/index.js'

let switchFlag = false

const state = new Signal.State({})
let b
const a = new Signal.Computed(() => {
  if (switchFlag) {
    return b.get()
  } else {
    return state.get()
  }
})
b = new Signal.Computed(() => {
  if (switchFlag) {
    return state.get()
  } else {
    return a.get()
  }
})
const c = new Signal.Computed(() => [a.get(), b.get()])

c.get()
switchFlag = true
state.set({})
c.get()

For either value of switchFlag the dependency graph is acyclic, but this code currently raises "Detected cycle in computations" according to the polyfill at f7c550b.

The "Algorithm: recalculate dirty computed Signal" specification heavily implies that sources aren't retained between evaluations of a Computed's callback.

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

1 participant