Trigger a Transition
Once you have a FSM you need to trigger a transition to a new state.
This is done with the StateMachine().applyEvent
method.
The applyEvent
method takes an Event and may cause the FSM to transition to a new state.
Calls to StateMachine.applyEvent
are asynchronous.
Calls to StateMachine.applyEvent
can be made at any time and from any code.
The StateMachine will queue any events and only apply the event once any active or pre existing queued events have completed.
Invalid Transitions
If you call applyEvent with an event you must be in a state that has an handler for that event.
The above call to 'machine.applyEvent' will fail as the initialState is 'Solid' and the 'Solid' state doesn't have a handler for the 'OnFroze' event.
If the statemachine is can't handle the event then a 'InvalidTransitionException' is thrown.
The exception is thrown only when in debug mode. If you pass 'production: true' to the statemachine 'create' method then the exception will be suppressed and instead it will be logged. This is done to make the FSM less brittle in production.
Concurrent Regions
Last updated
Was this helpful?