Defining Transitions
Transitions define how your machine moves from one status to another in response to actions.
They form the core logic of your state machine and determine its behavior over time.
🔗 Basic Transition Structure
A transition maps:
[currentStatus][action] → nextStatus
Example:
const transitions = {
idle: {
increment: 'incrementing',
decrement: 'decrementing',
},
incrementing: {
reset: 'idle',
},
decrementing: {
reset: 'idle',
},
};
This means:
- From
idle
, callingincrement
goes toincrementing
- From
incrementing
, callingreset
goes back toidle
💡 Tips for Transition Design
Tip | Example |
---|---|
Group similar transitions | reset always returns to idle |
Use default-like states (idle ) | for reset, cancel, etc. |
Reflect domain logic in state flow | submitting → success/error |
❓ Can transitions be dynamic?
Transitions themselves are static, but transition routing (based on conditions or payloads) can be implemented using a custom router or guard logic — covered in the next section.