run method
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
_MessageAction<M> run(
FutureOr<void> Function(MessageContext msgCtx, M msg) action, {
String? label,
}) {
return _MessageAction<M>._(_ActionType.run, (msgCtx, msg) {
_logger.fine(() => "State '$_forState' is running a message action.");
action(msgCtx, msg);
}, null, label);
}