Navigated to /docs/core/api/data-actions-and-async

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 guide

ActionContext#

type ActionContext<TInput> = {
    input: TInput;
    signal: AbortSignal;
};

Provides the context passed to action in the application runtime.

Related guide

ActionState#

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 guide

ActionStatus#

type ActionStatus = "idle" | "running" | "success" | "error";

Defines the action status contract used by the application runtime.

Related guide

createAction#

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 guide

createDeferredValue#

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 guide

createFormAction#

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 guide

createResource#

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 guide

createServerFormAction#

createServerFormAction<TResult = unknown>(url: string, options?: ServerFormActionOptions<TResult> | undefined): FormAction<TResult>

Creates a form action that submits to an SSR route action endpoint.

Related guide

Deferred#

Deferred<T>(props: DeferredProps<T>): Child

Progressive SSR boundary that renders stable fallback UI during pure CSR rendering.

Related guide

DeferredProps#

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 guide

DeferredState#

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 guide

DeferredTimeoutError#

type DeferredTimeoutError = {
    code: "TAVO_DEFERRED_TIMEOUT";
    id?: string;
    timeoutMs: number;
    message: string;
};

Represents a failure raised by deferred timeout in the application runtime.

Related guide

DeferredValue#

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 guide

FormAction#

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 guide

formDataToObject#

formDataToObject(formData: FormData): FormValues

Converts browser FormData into a plain object while preserving repeated field names.

Related guide

FormState#

type FormState<TResult = unknown> = ActionState<TResult> & {
    values: FormValues;
};

Represents the observable state of form in the application runtime.

Related guide

FormValues#

type FormValues = Record<string, FormDataEntryValue | FormDataEntryValue[]>;

Defines the form values contract used by the application runtime.

Related guide

Resource#

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 guide

ResourceState#

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 guide

ServerFormActionBody#

type ServerFormActionBody = ServerFormActionBodyValue | Partial<Record<TavoBootMode | "default", ServerFormActionBodyValue>>;

Defines the server form action body contract used by the application runtime.

Related guide

ServerFormActionBodyContext#

type ServerFormActionBodyContext = {
    bootMode: TavoBootMode;
    url: string;
};

Provides the context passed to server form action body in the application runtime.

Related guide

ServerFormActionBodyValue#

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 guide

ServerFormActionContentType#

type ServerFormActionContentType = ActionContentType | Partial<Record<TavoBootMode | "default", ActionContentType>>;

Defines the server form action content type contract used by the application runtime.

Related guide

ServerFormActionOptions#

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 guide

TavoAction#

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