Defining Status (States)
In Retomus, a status represents a distinct state of your machine. It determines how the machine reacts to events and what transitions are available.
📌 Why Define Status?
Defining a clear set of statuses allows your logic to be:
- Deterministic: Know exactly what can happen from any given state
- Readable: Easier to visualize and reason about state flow
- Type-safe: Supported by TypeScript enum-like safety
🛠️ Basic Example
const status = ['idle', 'loading', 'success', 'error'];
Each string represents a named state. These can be used in your transitions and component hooks.
🎯 Naming Conventions
Use simple, descriptive names:
Good | Avoid |
---|---|
idle | initState |
fetching | doFetch |
error | failState |
success | doneDoneDone123 |
🔁 Optional: Grouping with comments
const status = [
// Default
'idle',
// Fetch lifecycle
'loading',
'success',
'error',
// Transient
'cooldown',
];
This makes your state machine easy to navigate and extend.