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.Dmay bevoidif the state does not have any associated state data. -
EntryChannel<
P> -
Indicates that a value of type
Pmust 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 aResultis 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 typeM. -
MessageHandlerContext<
M, D, C> -
Provides access to the context for a message handler, including the
MessageContext, the message of typeMbeing processed, the state data of typeD, and a context value of typeC. -
MessageHandlerWhenBuilder<
M, D, C> -
Provides methods for defining conditional message handling behavior for messages of type
M, for a state carrying state data typeD, and a context value of typeC. -
MessageHandlerWhenResultBuilder<
M, D, C, T> -
Provides methods for error handling behavior for a state carrying state data
of type
Dand a context value of typeC, when aResultis an error value. -
StateBuilder<
D> -
Provides methods for describing the behavior of a state carrying state data of type
D.Dmay bevoidif 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 typeC. -
TransitionHandlerWhenResultBuilder<
D> -
Provides methods for error handling behavior for a state carrying state data
of type
D, when aResultis 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.