declarative library

Provides support for defining state trees in a declarative fashion.

When defining state and their behavior with this library, DeclarativeStateTreeBuilder captures a description of the resulting state tree that can be used to generate a diagram of the tree, which may be useful for documentation purposes.

class States {
  static final locked = StateKey('locked');
  static final unlocked = StateKey('unlocked');
}

var builder = DeclarativeStateTreeBuilder(initialChild: States.locked)
  ..state(States.locked, (b) {
    b.onMessageValue(Messages.insertCoin, (b) => b.goTo(States.unlocked));
  })
  ..state(States.unlocked, (b) {
    b.onMessageValue(Messages.push, (b) => b.goTo(States.locked),
        messageName: 'push');
  });

 var sb = StringBuffer();
 declBuilder.format(sb, DotFormatter());
 print(sb.toString());

Classes

DeclarativeStateTreeBuilder
Provides methods to describe a state tree.
DotFormatter
Generates a description of a DeclarativeStateTreeBuilder in Graphviz DOT graph format.
EnterStateBuilder<D>
Provides methods for describing the behavior of a state, carrying state data of type D, when is entered. D may be void if the state does not have any associated state data.
EntryChannel<P>
Indicates that a value of type P must be provided when entering a state.
MachineDoneHandlerBuilder<C>
Provides methods for describing how a DeclarativeStateTreeBuilder.machineState behaves when its nested state machine completes.
MachineDoneWhenBuilder<C>
Provides methods for defining conditional behavior of a DeclarativeStateTreeBuilder.machineState, when the nested state machine completes.
MachineDoneWhenResultBuilder<C, T>
Provides methods for error handling behavior for a DeclarativeStateTreeBuilder.machineState carrying context value of type C, when a nested state machine has completted, and when a Result is an error value.
MachineStateBuilder
Provides methods for describing the transition from a DeclarativeStateTreeBuilder.machineState that occurs when the nested state machine completes.
MessageActionBuilder<M, D, C>
Provides methods for describing actions that can be taken while a state handles a message.
MessageHandlerBuilder<M, D, C>
Provides methods for describing how a state, carrying state data of type D, behaves in response to a message of type M.
MessageHandlerContext<M, D, C>
Provides access to the context for a message handler, including the MessageContext, the message of type M being processed, the state data of type D, and a context value of type C.
MessageHandlerWhenBuilder<M, D, C>
Provides methods for defining conditional message handling behavior for messages of type M, for a state carrying state data type D, and a context value of type C.
MessageHandlerWhenResultBuilder<M, D, C, T>
Provides methods for error handling behavior for a state carrying state data of type D and a context value of type C, when a Result is an error value.
StateBuilder<D>
Provides methods for describing the behavior of a state carrying state data of type D. D may be void if the state does not have any associated state data.
StateBuilderExtensionInfo
StateExtensionBuilder
StateTreeFormatter
Defines methods for writing a textual description of the state tree represented by a DeclarativeStateTreeBuilder.
TransitionHandlerBuilder<D, C>
Provides methods for describing how a state behaves during a transition.
TransitionHandlerContext<D, C>
Provides access to the context for a transition handler, including the transitionContext, the state data, and a context value.
TransitionHandlerWhenBuilder<D, C>
Provides methods for defining conditional transition behavior for a state carrying state data of type D, and a context value of type C.
TransitionHandlerWhenResultBuilder<D>
Provides methods for error handling behavior for a state carrying state data of type D, when a Result is an error value.

Enums

ActionResult
Describes the message processing result of runnin an action with MessageHandlerBuilder.action.
NodeType

Functions

emptyFinalState<D>(EnterStateBuilder<D> builder) → void
A state builder callback that adds no behavior to a final state.
emptyState<D>(StateBuilder<D> builder) → void
A state builder callback that adds no behavior to a state.