post<M2> method
_MessageActionWithData<M, D>
post<M2>({
- FutureOr<
M2> getMessage(- MessageContext msgCtx,
- M msg,
- D data
- M2? message,
- String? label,
Posts a new message to be processed by the state machine while a message is being handled.
If getMessage is provided, the function will be evaluated when the transition occurs, and
the returned message will be posted. Otherwise a message must be provided.
This action can be labeled when formatting a state tree by providing a label.
Implementation
_MessageActionWithData<M, D> post<M2>({
FutureOr<M2> Function(MessageContext msgCtx, M msg, D data)? getMessage,
M2? message,
String? label,
}) {
// TODO: try and combine implementation with post
if (getMessage == null && message == null) {
throw ArgumentError('getMessage or message must be provided');
} else if (getMessage != null && message != null) {
throw ArgumentError('One of getMessage or message must be provided');
}
var _getMessage = getMessage ?? (_, __, ___) => message!;
return _MessageActionWithData<M, D>._(
_ActionType.post,
(msgCtx, msg, data) => _getMessage(msgCtx, msg, data).bind(
(scheduleMsg) {
_logger.fine(() => "State '$_forState' is posting message of type $M2");
msgCtx.post(scheduleMsg as Object);
},
),
TypeLiteral<M2>().type,
label,
);
}