import Component from "@glimmer/component"; import type { ComponentLike } from "@glint/template"; import type { RequestManager, Store } from "@warp-drive/core"; import type { RequestLoadingState, RequestState, RequestSubscription } from "@warp-drive/core/reactive"; import type { ContentFeatures, RecoveryFeatures, RequestArgs } from "@warp-drive/core/signals/-leaked"; import type { StructuredErrorDocument } from "@warp-drive/core/types/request"; export { ContentFeatures, RecoveryFeatures }; export interface EmberRequestArgs< RT, E > extends RequestArgs { chrome?: ComponentLike<{ Blocks: { default: []; }; Args: { state: RequestState | null; features: ContentFeatures; }; }>; } interface RequestSignature< RT, E > { Args: EmberRequestArgs; Blocks: { /** * The block to render when the component is idle and waiting to be given a request. * */ idle: []; /** * The block to render when the request is loading. * */ loading: [state: RequestLoadingState]; /** * The block to render when the request was cancelled. * */ cancelled: [error: StructuredErrorDocument, features: RecoveryFeatures]; /** * The block to render when the request failed. If this block is not provided, * the error will be rethrown. * * Thus it is required to provide an error block and proper error handling if * you do not want the error to crash the application. */ error: [error: StructuredErrorDocument, features: RecoveryFeatures]; /** * The block to render when the request succeeded. * */ content: [value: RT, features: ContentFeatures]; always: [state: RequestState>]; }; } /** * The `` component is a powerful tool for managing data fetching and * state in your Ember application. It provides a declarative approach to reactive * control-flow for managing requests and state in your application. * * The `` component is ideal for handling "boundaries", outside which some * state is still allowed to be unresolved and within which it MUST be resolved. * * ## Request States * * `` has five states, only one of which will be active and rendered at a time. * * - `idle`: The component is waiting to be given a request to monitor * - `loading`: The request is in progress * - `error`: The request failed * - `content`: The request succeeded * - `cancelled`: The request was cancelled * * Additionally, the `content` state has a `refresh` method that can be used to * refresh the request in the background, which is available as a sub-state of * the `content` state. * * As with the `` component, if no error block is provided and the request * rejects, the error will be thrown. Cancellation errors are swallowed instead of * rethrown if no error block or cancellation block is present. * * ```gts * import { Request } from '@warp-drive/ember'; * * * ``` * * ## Streaming Data * * The loading state exposes the download `ReadableStream` instance for consumption * * ```gts * import { Request } from '@warp-drive/ember'; * * * ``` * * ## Retry * * Cancelled and error'd requests may be retried by calling the `retry` method. * * Retry will restart the state progression, using the loading, error, cancelled, * and content blocks as appropriate. * * ## Reloading * * The `reload` method will force the request to be fully re-executed, bypassing * cache and restarting the state progression through the loading, error, and * content blocks as appropriate. * * Background reload (refresh) is a special substate of the content state that * allows you to refresh the request in the background. This is useful for when * you want to update the data in the background without blocking the UI. * * Reload and refresh are available as methods on the `content` state. * * ```gts * import { Request } from '@warp-drive/ember'; * * * ``` * * ## Advanced Reloading * * We can nest our usage of `` to handle more advanced * reloading scenarios. * * ```gts * import { Request } from '@warp-drive/ember'; * * * ``` * * ## Autorefresh * * `` supports automatic refresh and reload under certain conditions. * * - `online`: This occurs when a browser window or tab comes back to the foreground * after being backgrounded or when the network reports as being online after * having been offline. * - `interval`: This occurs when a specified amount of time has passed. * - `invalid`: This occurs when the store emits a notification that the request * has become invalid. * * You can specify when autorefresh should occur by setting the `autorefresh` arg * to `true` or a comma-separated list of the above values. * * A value of `true` is equivalent to `'online,invalid'`. * * By default, an autorefresh will only occur if the browser was backgrounded or * offline for more than 30s before coming back available. This amount of time can * be tweaked by setting the number of milliseconds via `@autorefreshThreshold`. * * This arg also controls the interval at which the request will be refreshed * if the `interval` autorefresh type is enabled. * * Finally, the behavior of the request initiated by autorefresh can be adjusted * by setting the `autorefreshBehavior` arg to `'refresh'`, `'reload'`, or `'policy'`. * * - `'refresh'`: Refresh the request in the background * - `'reload'`: Force a reload of the request * - `'policy'` (**default**): Let the store's configured CachePolicy decide whether to * reload, refresh, or do nothing. * * More advanced refresh and reload behaviors can be created by passing the reload and * refresh actions into another component. For instance, refresh could be set up on a * timer or on a websocket subscription. * * * ```gts * import { Request } from '@warp-drive/ember'; * * * ``` * * If a matching request is refreshed or reloaded by any other component, * the `Request` component will react accordingly. * * ## Deduping * * The store dedupes requests by identity. If a request is made for the same identity * from multiple `` components, even if the request is not referentially the * same, only one actual request will be made. * * @category Components * @public */ export declare class Request< RT, E > extends Component> { get store(): Store | RequestManager; _state: RequestSubscription | null; get state(): RequestSubscription; /** * The chrome component to use for rendering the request. * * @private */ get Chrome(): ComponentLike<{ Blocks: { default: []; }; Args: { state: RequestState | null; features: ContentFeatures; }; }>; willDestroy(): void; }