submit method
Wrapper for a user defined submission logic that handles state setting
How it works:
- If the status is already set to ActionStatus.ongoing it returns
immediately, otherwise ActionStatus.ongoing status is set
along with the
initialData
(if provided) - User provided
body
function is executed - Upon completion the Outcome.data is set (if provided) along
with the final status determined by the Outcome constructor:
- Outcome.finished sets ActionStatus.done (default if no value is returned)
- Outcome.failed sets ActionStatus.failed
- Outcome.canceled sets ActionStatus.canceled
If anything is thrown from body
a ActionStatus.failed
status is set and the details are forwarded to onError
Implementation
@protected
Future submit({
required FutureOr<Outcome<Data>?> Function() body,
Data? initialData,
}) async {
if (state.beingSubmitted) return;
return execute(
state: state,
type: ActionType.submission,
body: body,
onError: onError,
initialData: initialData,
).forEach(emit);
}