when<R> method

R when<R>({
  1. required R idle,
  2. required R data,
  3. required R error,
  4. required R loading,
})

Pattern-matching over the form state with direct values.

Similar to map but with direct return values instead of callbacks. All parameters are required.

Implementation

R when<R>({
  required R idle,
  required R data,
  required R error,
  required R loading,
}) {
  if (this is AsyncFormIdle<Request, Response>) {
    return idle;
  }
  if (this is AsyncFormData<Request, Response>) {
    return data;
  }
  if (this is AsyncFormError<Request, Response>) {
    return error;
  }
  return loading;
}