Data, actions, and async API
Actions, forms, resources, deferred values, and their data contracts.
Data, actions, and async exports
26 public exports, grouped under their canonical import boundary.
@tavojs/core
Canonical import boundary for every symbol in this section.
Action#
type Action<TInput, TResult> = {
store: Store<ActionState<TResult>>;
getState(): ActionState<TResult>;
run(input: TInput): Promise<ActionState<TResult>>;
abort(): void;
reset(): void;
};Defines the action contract used by the application runtime.
Related guideActionContext#
type ActionContext<TInput> = {
input: TInput;
signal: AbortSignal;
};Provides the context passed to action in the application runtime.
Related guideActionState#
type ActionState<TResult = unknown> = {
status: ActionStatus;
data: TResult | null;
error: unknown;
submittedAt: number | null;
completedAt: number | null;
};Represents the observable state of action in the application runtime.
Related guideActionStatus#
type ActionStatus = "idle" | "running" | "success" | "error";Defines the action status contract used by the application runtime.
Related guidecreateAction#
createAction<TInput = void, TResult = unknown>(handler: (context: ActionContext<TInput>) => TResult | Promise<TResult>): Action<TInput, TResult>Creates an MVC-friendly mutation primitive with status, result, error, and abort handling.
Related guidecreateDeferredValue#
createDeferredValue<T>(promise: Promise<T>, options?: { id?: string | undefined; serialize?: ((value: T) => unknown) | undefined; deserialize?: ((value: unknown) => T) | undefined; timeoutMs?: number | undefined; timeoutFallback?: DeferredTimeoutFallback; signal?: AbortSignal | undefined; } | undefined): DeferredValue<T>Creates a reusable deferred wrapper so nested SSR trees can share one async unit by id.
Related guidecreateFormAction#
createFormAction<TResult = unknown>(handler: (values: FormValues, context: { signal: AbortSignal; }) => TResult | Promise<TResult>): FormAction<TResult>Creates a form-oriented action for MVC controllers without introducing hook-style APIs.
Related guidecreateResource#
createResource<T>(loader: (context: { signal: AbortSignal; }) => Promise<T>): Resource<T>Creates an MVC-friendly async resource with explicit load/reset methods and observable state.
Related guidecreateServerFormAction#
createServerFormAction<TResult = unknown>(url: string, options?: ServerFormActionOptions<TResult> | undefined): FormAction<TResult>Creates a form action that submits to an SSR route action endpoint.
Related guideDeferred#
Deferred<T>(props: DeferredProps<T>): ChildProgressive SSR boundary that renders stable fallback UI during pure CSR rendering.
Related guideDeferredProps#
type DeferredProps<T> = {
value: Promise<T> | T | DeferredValue<T>;
fallback?: Child;
children: DeferredRender<T> | Child;
id?: string;
as?: string;
errorFallback?: DeferredErrorFallback;
serialize?: (value: T) => unknown;
deserialize?: (value: unknown) => T;
timeoutMs?: number;
timeoutFallback?: DeferredTimeoutFallback;
signal?: AbortSignal;
};Defines the props accepted by deferred in the application runtime.
Related guideDeferredState#
type DeferredState<T> = {
status: "pending";
data: null;
error: null;
} | {
status: "resolved";
data: T;
error: null;
} | {
status: "rejected";
data: null;
error: unknown;
};Represents the observable state of deferred in the application runtime.
Related guideDeferredTimeoutError#
type DeferredTimeoutError = {
code: "TAVO_DEFERRED_TIMEOUT";
id?: string;
timeoutMs: number;
message: string;
};Represents a failure raised by deferred timeout in the application runtime.
Related guideDeferredValue#
type DeferredValue<T> = {
id?: string;
promise: Promise<T>;
serialize?: (value: T) => unknown;
deserialize?: (value: unknown) => T;
timeoutMs?: number;
timeoutFallback?: DeferredTimeoutFallback;
signal?: AbortSignal;
};Defines the deferred value contract used by the application runtime.
Related guideFormAction#
type FormAction<TResult = unknown> = {
action: Action<FormValues, TResult>;
store: Store<FormState<TResult>>;
submit(form: HTMLFormElement | FormData | FormValues): Promise<FormState<TResult>>;
reset(): void;
};Defines the form action contract used by the application runtime.
Related guideformDataToObject#
formDataToObject(formData: FormData): FormValuesConverts browser FormData into a plain object while preserving repeated field names.
Related guideFormState#
type FormState<TResult = unknown> = ActionState<TResult> & {
values: FormValues;
};Represents the observable state of form in the application runtime.
Related guideFormValues#
type FormValues = Record<string, FormDataEntryValue | FormDataEntryValue[]>;Defines the form values contract used by the application runtime.
Related guideResource#
type Resource<T> = {
store: Store<ResourceState<T>>;
read(): ResourceState<T>;
load(options?: {
signal?: AbortSignal;
}): Promise<ResourceState<T>>;
preload(options?: {
signal?: AbortSignal;
}): Promise<ResourceState<T>>;
abort(reason?: unknown): void;
reset(): void;
};Defines the resource contract used by the application runtime.
Related guideResourceState#
type ResourceState<T> = {
status: "idle" | "loading" | "success" | "error";
data: T | null;
error: unknown;
updatedAt: number | null;
};Represents the observable state of resource in the application runtime.
Related guideServerFormActionBody#
type ServerFormActionBody = ServerFormActionBodyValue | Partial<Record<TavoBootMode | "default", ServerFormActionBodyValue>>;Defines the server form action body contract used by the application runtime.
Related guideServerFormActionBodyContext#
type ServerFormActionBodyContext = {
bootMode: TavoBootMode;
url: string;
};Provides the context passed to server form action body in the application runtime.
Related guideServerFormActionBodyValue#
type ServerFormActionBodyValue = "form-data" | "json" | ((values: FormValues, context: ServerFormActionBodyContext) => BodyInit | Promise<BodyInit>);Defines the server form action body value contract used by the application runtime.
Related guideServerFormActionContentType#
type ServerFormActionContentType = ActionContentType | Partial<Record<TavoBootMode | "default", ActionContentType>>;Defines the server form action content type contract used by the application runtime.
Related guideServerFormActionOptions#
type ServerFormActionOptions<TResult = unknown> = {
body?: ServerFormActionBody;
contentType?: ServerFormActionContentType;
credentials?: RequestCredentials;
fetch?: typeof fetch;
headers?: HeadersInit;
method?: string;
parseResponse?: (response: Response) => Promise<TResult> | TResult;
};Configures server form action in the application runtime.
Related guideTavoAction#
type TavoAction<TResult, TArgs extends unknown[]> = {
readonly pending: boolean;
readonly error: unknown;
readonly result: TResult | null;
run(...args: TArgs): Promise<TResult>;
reset(): void;
};Defines the tavo action contract used by the application runtime.
Related guide