Skip to content

Lifecycle

All machine types implement the same generic EventLifecycle and hook methods for consistency. This allows you to use the same patterns across different machine types, whether you’re using a FactoryMachine, a StateMachine, or a StoreMachine.

When you call machine.send(type, ...params), the following flow occurs:

Called with an event type and parameters.

Determines the target state for the event.

Checks if the transition is allowed.

  • If false, exit early.

First opportunity to process the event.

  • If returns undefined, exit early.

Called before the state change.

  • If returns undefined, exit early.

Updates the internal state.

Runs side effects.

Called when leaving the previous state.

Called when entering the new state.

Notifies subscribers.

Final hook after transition completes.

  • If guard returns false, or handle/before return undefined, the transition stops and no further steps run.