A custom text notation used to describe and prototype nested state machines
We can create a basic statemachine to describes the phases that a butterfly enters during its life as follows.
---
Organism
---
egg
grow
hatch >> caterpillar
caterpillar
eat
crawl
cocoon >> butterfly
butterfly
fly
mate >> egg
The basic syntax can be described as follows:
- The value between the
---
lines provides a name for the machine - All lines with no whitespace at the front describe phases (in this case
egg
,caterpillar
andbutterfly
) - Any indented line (with whitespace at the front) describe an action nested inside a phase.
- Any actions that have
>>
at the end indicates that the action causes a transition to a new phase (the name of the target phase after the>>
) - Actions that do not have
>>
do not trigger transitions, but usually causes some side-effect outside the statemachine itself.
You can view the Basic Example Demo to see this in action. Remember to open the panes on the right-hand side (since they are closed by default) and click on an action in the current phase to transition.