Debugging your FSM
FSM2 provides a number of tools to help debug your FSM.
Firstly we strongly recommend that you only use the static transitions (i.e. don't use onDynamic). As yet we have found no use cases where onDynamic is needed and it makes debugging your FSM much harder.
Static Analysis
The first thing you should ALWAYS check is that your FSM is consistent.
You can do this by calling analysis().
You should create a unit test that tests your statemachine.
Visualise your FSM
If you have followed our recommendation to not use 'onDynamic' then you can create a visualisation of your FSM.
See details on visualisation for details on viewing the .gv file.
Simplify your FSM
We are not big fans of humongous state machines. Rather we recommend that you create a statemachine for each part of your code.
You might have an FSM for each screen or particular db updates but avoid the temptation to model your entire app as a single statemachine. This will never end well.
Log Transitions
The statemachine allows you to hook every transition by calling 'onTransition'.
The above code prints the eventType, fromState, and toState for every transition.
A single event can result in multiple transitions if your state machine is in a concurrent region.
Unit Testing
We provide a number of helper functions that make it easier to unit test your statemachine.
StateMachine.waitUntilQuiescent
StateMachine.isInState
StateMachine.stateOfMind
Last updated