Signals & Effects
Lume uses a signal-based reactivity system. Signals hold values, and effects automatically re-run when their dependencies change.
Signals
Section titled “Signals”A signal is a reactive value container:
Signal API
Section titled “Signal API”| Method | Description |
|---|---|
signal() | Read the current value |
signal.set(value) | Set a new value |
signal.update(fn) | Transform the current value |
Effects
Section titled “Effects”Effects are functions that automatically re-run when any signal they read changes:
How Tracking Works
Section titled “How Tracking Works”Effects use synchronous tracking. When an effect runs:
- Lume records which signals are read (called)
- When any of those signals change, the effect re-runs
- Dependencies are re-computed on every run (dynamic tracking)
Effect Cleanup
Section titled “Effect Cleanup”Effects can return a cleanup function that runs before each re-execution and on unmount:
Practical Example
Section titled “Practical Example”Key Principles
Section titled “Key Principles”- Synchronous: Signal reads are synchronous and tracked automatically
- Fine-grained: Only effects that depend on a changed signal re-run
- No batching needed: Updates are immediate and predictable
- Auto-cleanup: All effects are cleaned up when the component unmounts