run method
MessageActionDescriptor<M, D, C>
run(
- FutureOr<
void> action(- MessageHandlerContext<
M, D, C>
- MessageHandlerContext<
- String? label,
Runs the action while a message is being handled.
When the action function is called, it is passed a MessageContext, and the message that is being handled.
void onMessage<M>(MessageContext ctx, M message) => print('Handling message');
var state1 = StateKey('s1');
var state2 = StateKey('s2');
var builder = StateTreeBuilder(initialState: state1);
builder.state(state1, (b) {
// Calls the onMessage function as a side effect before the transition occurs
b.onMessage<MyMessage>((b) => b.goTo(state2, action: b.act.run(onMessage);
});
This action can be labeled when formatting a state tree by providing a label.
Implementation
MessageActionDescriptor<M, D, C> run(
FutureOr<void> Function(MessageHandlerContext<M, D, C>) action, {
String? label,
}) {
var info = MessageActionInfo(ActionType.run, null, null, label);
return MessageActionDescriptor<M, D, C>(info, action);
}