Skip to content

Documentation / @warp-drive/ember / RequestState

Type Alias: RequestState<RT, E>

ts
type RequestState<RT, E> = 
  | PendingRequest
  | ResolvedRequest<RT>
  | RejectedRequest<RT, E>
| CancelledRequest<RT, E>;

Defined in: warp-drive-packages/core/declarations/store/-private/new-core-tmp/request-state.d.ts:311

RequestState extends the concept of PromiseState to provide a reactive wrapper for a request Future which allows you write declarative code around a Future's control flow.

It is useful in both Template and JavaScript contexts, allowing you to quickly derive behaviors and data from pending, error and success states.

The key difference between a Promise and a Future is that Futures provide access to a stream of their content, the RequestKey of the request (if any) as well as the ability to attempt to abort the request.

ts
interface Future<T> extends Promise<T>> {
  getStream(): Promise<ReadableStream>;
  abort(): void;
  lid: RequestKey | null;
}

These additional APIs allow us to craft even richer state experiences.

To get the state of a request, use getRequestState.

See also:

  • PendingRequest
  • ResolvedRequest
  • RejectedRequest
  • CancelledRequest

Type Parameters

RT

RT = unknown

E

E extends StructuredErrorDocument = StructuredErrorDocument

Released under the MIT License.