fw-03 step 02 — computed, cleanup, and the diamond
Goal
The two hardest correctness problems in reactivity: lazy caching, and stale dependencies.
Tasks
computed(fn)— lazy (not evaluated until read), cached while dependencies are unchanged, and both a dependent and a dependency.- Cleanup. Clear an effect's dependencies before each re-run. Then remove the cleanup and
reproduce stage 5's dependency leak: an effect that stopped reading
astill firing ona. - Nested effects. Replace your stack with a single global and reproduce stage 6 — the inner effect stealing the outer's dependencies.
- The diamond / glitch test. Build
a → b → d,a → c → d. Count how many timesdevaluates, and check whether it ever computes from inconsistent inputs. Most hand-written systems have this bug and never notice. watch(source, cb)reporting old and new values.
Done when
- Stages 4–6 green
- Dependency leak reproduced deliberately, then fixed
-
devaluates exactly once per change, never from a transient value