Skip to content

State

A State defines a named state of an entity. It references a type that defines the data structure for the state, and optionally contains handlers that define how messages are processed while the entity is in that state.

An entity can have multiple state definitions. When an entity has multiple states with their own handlers, it naturally models a Finite State Machine —each state responds to messages differently. Use the finite state machine option to make this intent explicit.

States are branches in the AST, meaning they can contain their own definitions. The morph statement transitions an entity from one state to another, changing which handlers are active.

Syntax

state ActiveOrder of ActiveOrderData is {
  handler ActiveOrderHandler is {
    on command CancelOrder { ??? }
    on command ShipOrder { ??? }
  }
}

The state body (with handlers) is optional—a state can also be defined simply as:

state ActiveOrder of ActiveOrderData

Occurs In

Contains