Signals and Fine-Grained Reactivity (Reactive Graph) vs Finite State Machines for UI
Signals propagate arbitrary reactive value changes, whereas finite state machines enforce explicit transition guards.
Structured Comparison Matrix
| Dimension | Signals and Fine-Grained Reactivity (Reactive Graph) | Finite State Machines for UI |
|---|---|---|
| Mental Model | Reactive model built on a directed acyclic dependency graph (Signal, Computed, Effect) updating only subscribed DOM nodes without virtual tree diffing. | Replaces overlapping boolean flags (isLoading, isError, isRetrying) with a discriminated union and explicit (state, event) transition table that makes invalid states unrepresentable. |
| Maturity & Domain | State & Architecture | State & Architecture |
| Prerequisites | Foundational primitive | |
| When Not to Use | When not to use Signals: For simple forms or mostly static pages, native DOM primitives avoid unnecessary abstraction overhead; for multi-step workflows with illegal state combinations, pair or replace raw signals with Finite State Machines. | When not to use an FSM: For continuous numeric values (scroll offset, canvas coordinates) or simple independent form fields, plain state or reactive signals are far lighter. |
Engine Mechanics & Trade-Offs
Glitch-free push-pull propagation over an acyclic observer graph.
Key Pitfalls: Effects writing to tracked signals (infinite loop): An effect mutating a signal it reads re-triggers the graph indefinitely until stack overflow. Losing reactivity via destructuring: Extracting const v = signal.get() outside the tracked execution scope breaks dynamic subscription.
Replaces N overlapping boolean flags (2^N states) with a discriminated union of valid states and an explicit (state, event) -> nextState transition table.
Key Pitfalls: Event explosion on simple toggles: Writing a 60-line statechart configuration for an open/closed disclosure panel adds ceremony with zero safety gain. Forgetting cleanup on state exit: Cancelling an in-flight AbortController when leaving loading -> idle must happen deterministically on transition, or stale responses st