Skip to content

Commit

Permalink
add test file simple_signal2.test.ts, which shows that my current w…
Browse files Browse the repository at this point in the history
…ay of traversing in `Context.fireUpdateCycle` and `Context.propagateSignalUpdate` are not ordered topologically.

- expected traversal: A, B, D, G, C, E, H, F, I, J
- actual traversal: A, B, D, G, C, E, H,I, J, F
- reason: F gets skipped in the middle because it is already visited once from either B or D, but its resolution is delayed because of unvisited dependencies C and E. however, when C and E are visited, they propagate forward to H and then I. in I's perspective, F has been resolved, since it has been visited. however, the reality is that while it has been visited, it was awaiting dependency resolution of C and E, and it hasn't been resolved yet. the forward propagation model is indeed problematic. you should either stick backward resolution or forward propagation, but not both at the same time.
  • Loading branch information
omar-azmi committed Feb 16, 2024
1 parent 4376b9c commit 3eff039
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions test/simple_signal2.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { DEBUG } from "../src/deps.ts"
import { Context } from "../src/context.ts"
import { EffectSignal_Factory, LazySignal_Factory, MemoSignal_Factory, StateSignal_Factory } from "../src/signal.ts"

const
ctx = new Context(),
createState = ctx.addClass(StateSignal_Factory),
createMemo = ctx.addClass(MemoSignal_Factory),
createLazy = ctx.addClass(LazySignal_Factory),
createEffect = ctx.addClass(EffectSignal_Factory),
setFn = ctx.dynamic.setFn

const
[, A, setA] = createState(1, { equals: false, name: "A" }),
[, B] = createMemo((id) => A(id), { equals: false, name: "B" }),
[, C] = createMemo((id) => A(id), { equals: false, name: "C" }),
[, D] = createMemo((id) => B(id), { equals: false, name: "D" }),
[, E] = createMemo((id) => C(id), { equals: false, name: "E" }),
[, F] = createMemo((id) => B(id) + C(id) + D(id) + E(id), { equals: false, name: "F" }),
[, G] = createMemo((id) => D(id), { equals: false, name: "G" }),
[, H] = createMemo((id) => E(id), { equals: false, name: "H" }),
[, I] = createMemo((id) => F(id) + G(id) + H(id), { equals: false, name: "I" }),
[, J] = createMemo((id) => I(id), { equals: false, name: "J" })

// @ts-ignore: enums can't be modified, but we want to control our logging here
// DEBUG.LOG = 1
// I()
// J()

Deno.test("test1", () => {
// @ts-ignore: enums can't be modified, but we want to control our logging here
DEBUG.LOG = 1
I()
J()
})

Deno.test("test2", () => {
DEBUG.LOG = 1
setA(2)
})

0 comments on commit 3eff039

Please sign in to comment.