The State Machine Mental Model for UI Engineering
Why every complex UI is secretly a finite state machine
Every complex UI is secretly a finite state machine. Modeling that explicitly removes whole categories of bugs.
#The Hidden State Machine
Every UI has states: loading, error, empty, populated, editing, and saving. The question is whether those states are modeled clearly or hidden inside fragile if-else chains.
const machine = {
idle: { FETCH: 'loading' },
loading: { SUCCESS: 'populated', FAILURE: 'error' },
error: { RETRY: 'loading' },
populated: { REFRESH: 'loading' },
empty: { REFRESH: 'loading' },
};
stateDiagram-v2
[*] --> Idle
Idle --> Loading: FETCH
Loading --> Populated: SUCCESS
Loading --> Error: FAILURE
Error --> Loading: RETRY
Populated --> Loading: REFRESH
- No impossible states: the UI cannot be loading and failed at the same time.
- Clear transitions: invalid movements are easier to catch.
- Visualizable logic: the model can be drawn and discussed before code exists.
| State | Particles | Controls | Overlay |
|---|---|---|---|
| Home | Breathing sphere | Rotate + zoom | None |
| Section | Absorption dot | Disabled | Item grid |
| Item | Sculpture | Drag + click | Project page |
| Blog | Scroll thumb | Scroll | Article page |