submit method

  1. @protected
Future submit({
  1. required FutureOr<Outcome<Data>?> body(),
  2. Data? initialData,
})

Wrapper for a user defined submission logic that handles state setting

How it works:

  1. If the status is already set to ActionStatus.ongoing it returns immediately, otherwise ActionStatus.ongoing status is set along with the initialData (if provided)
  2. User provided body function is executed
  3. Upon completion the Outcome.data is set (if provided) along with the final status determined by the Outcome constructor:

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);
}