Signal Graphs and Propagation
You'll learn how signals create dependency graphs that optimize change propagation through your reactive system.
Understanding the Graph Structure
When you create computed signals and effects, you're building a directed acyclic graph (DAG) where each node is a signal or effect, and edges represent dependencies. The graph flows in one direction: from source signals through computeds to effects, never looping back.
Think of it like a spreadsheet: when cell A1 changes, only the cells that reference it (directly or indirectly) need to recalculate—Excel doesn't update every cell on every change.
const count = signal(0);
const doubled = computed(() => count() * 2);
const quadrupled = computed(() => doubled() * 2);
// Graph: count → doubled → quadrupled
Efficient Propagation
When a source signal updates, the system walks the graph efficiently:
- Marks dependent nodes as potentially stale
- Topologically sorts updates to ensure parent nodes compute before children
- Skips unnecessary work if a computed's value didn't actually change
This means quadrupled won't recalculate if doubled produces the same value, even when count changed.
Why DAGs Matter
The "acyclic" part is crucial—no signal can depend on itself through any path. This prevents infinite update loops and makes propagation predictable and efficient. The system can guarantee every signal settles to a consistent state in a single pass.
Key Takeaway: Signals form directed acyclic graphs where changes propagate efficiently by only updating affected nodes in topological order, avoiding redundant recalculations and infinite loops.