Effects
effect(|| { ... }) registers a reaction: the closure runs once when created
and again whenever any signal read inside it changes.
Any call to .get() inside the body registers a dependency
automatically — there is no manual deps list.
Effects are ideal for side effects: logging, persistence, UI updates — anything that needs to mirror reactive state.
Effect creation, automatic dependency tracking and re-run on write.
02-effect-tracking.zolo
// Feature: effect — runs once on creation, re-runs when tracked signals change
// Syntax: `effect(|| { ... })`. Any `Signal.get` inside the closure
// registers as a dependency of this effect.
// When to use: side effects that must mirror reactive state — DOM
// updates, logging, persistence, derived computations with side effects.
let count = signal(0)
// Initial creation runs the closure once and records `count` as a dep.
let e = effect(|| {
print("count = {count.get()}")
})
// expected: count = 0
// Each set retriggers the effect.
count.set(1)
// expected: count = 1
count.set(2)
// expected: count = 2
// Setting to the same value still triggers (no equality check).
count.set(2)
// expected: count = 2
See also