Skip to content

State Machine

A state machine drawn and driven on the canvas: states are nodes, transitions are labelled edges routed round the states in their way, and the toolbar fires the events the current state accepts. The current state is marked through RunStates and announced, and the transition just taken is animated.

In Idle:
fetchresolverejectretryrefreshresetdismiss
Idle
Loading
Ready
Error
bit Blow

Try it

  • The toolbar shows the events the current state accepts. Press fetch, then resolve or reject: the ring moves to the new state, the edge just taken is animated, and a screen reader hears where the machine is now.
  • In Ready, refresh follows the loop that leaves Ready and comes straight back to it.
  • Start over returns to Idle.
  • Drag from a state's handle to another state to add a transition. It is named event 1, event 2 and so on, routed like the others, and its button appears whenever the machine is in the state it leaves.
  • Click a transition and press Delete: its button is gone. The states themselves cannot be deleted.
  • Drag a state across another's transitions: the routed edges find a new way round it.

How it works

  • States are BlowNodes with Deletable = false, so the toolbar always has a current state to name. Transitions are BlowEdges whose Label is the event and whose Source and Target are the states before and after it.
  • The toolbar lists the edges leaving the current state, one button each; firing one makes its Target the current state, sets Animated on that edge only, and calls Announce with the new state for screen readers.
  • RunStates marks the current state with new BlowRunState(BlowRunStatus.Running, "Current state"): the running ring and the bit-blow-run-running class, read out with the node. Every other state has no entry, so it shows nothing.
  • BlowEdgeType.Routed routes each edge round the nodes in its way and re-routes it when a node moves. An edge whose Source and Target are the same node is drawn as a loop. Ready and Error leave from the top and the bottom (SourcePosition), so the ways back do not share the ways there.
  • DefaultEdgeOptions gives a transition drawn on the canvas the same routed shape and arrowhead, and OnConnect - raised once the new edge is in the list - gives it a name, so it has a label to show and a button to fire it.
An unhandled error has occurred. Reload 🗙