@tempots/ui
Version:
Provides a higher level of renderables to help fast development with Tempo.
50 lines (49 loc) • 1.75 kB
TypeScript
import { TNode, Signal, Value, Renderable } from '@tempots/dom';
import { AsyncResult } from '@tempots/std';
/**
* Represents the options for rendering an asynchronous result view.
*
* @typeParam T - The type of the success value.
* @typeParam E - The type of the error value.
* @public
*/
export type AsyncResultViewOptions<T, E> = {
/**
* The function to render the view when the operation succeeds.
* @param value - The value of the success result.
* @returns The rendered view.
* @public
*/
success: (value: Signal<T>) => TNode;
/**
* The function to render the view when the operation fails.
* @param error - The error of the failure result.
* @returns The rendered view.
* @public
*/
failure?: (error: Signal<E>) => TNode;
/**
* The function to render the view when the operation is not requested yet.
* @returns The rendered view.
* @public
*/
notAsked?: () => TNode;
/**
* The function to render the view when the operation is in progress.
* @param previousValue - The previous value.
* @returns The rendered view.
* @public
*/
loading?: (previousValue: Signal<T | undefined>) => TNode;
};
/**
* Renders the view based on the result of an asynchronous operation.
*
* @typeParam T - The type of the success value.
* @typeParam E - The type of the error value.
* @param result - The result of the asynchronous operation.
* @param options - The options object or a function that returns a TNode.
* @returns The rendered view.
* @public
*/
export declare const AsyncResultView: <T, E>(result: Value<AsyncResult<T, E>>, options: AsyncResultViewOptions<T, E> | ((value: Signal<T>) => TNode)) => Renderable;