submit method Null safety

  1. @protected
Stream<StatefulState<Data>> submit(
  1. {required FutureOr<Outcome<Data>?> body(
      ),
    1. 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
    Stream<StatefulState<Data>> submit({
      required FutureOr<Outcome<Data>?> Function() body,
      Data? initialData,
    }) async* {
      if (state.beingSubmitted) return;
      yield* execute(
        state: state,
        type: ActionType.submission,
        body: body,
        onError: onError,
        initialData: initialData,
      );
    }