@westacks/vortex
Version:
Server-based routing for SPAs
35 lines (34 loc) • 1.7 kB
TypeScript
import { Signal } from './signals';
import { RouterRequestConfig, RouterResponse } from './router';
export type VortexForm<T extends object> = T & Form<T>;
declare class Form<TForm extends object> {
_defaults: TForm;
_transform: unknown;
_recentlySuccessfulTimeout: NodeJS.Timeout | null;
readonly _handler: ProxyHandler<VortexForm<TForm>>;
wasSuccessful: boolean;
recentlySuccessful: boolean;
processing: boolean;
errors: Record<string, string>;
get hasErrors(): boolean;
get isDirty(): boolean;
constructor(initial: TForm, handler: ProxyHandler<VortexForm<TForm>>);
data(): TForm;
transform(fn: (data: TForm) => unknown): this;
reset(...fields: string[]): this;
fill(data: TForm): this;
defaults(field?: string | Record<string, unknown>, value?: unknown): this;
clearErrors(...fields: string[]): this;
setError(field: string | Record<string, string>, message?: string): this;
request<TForm>(options: RouterRequestConfig<TForm>): Promise<RouterResponse<any, any>>;
get(url: string, options?: RouterRequestConfig): Promise<RouterResponse<any, any>>;
post(url: string, options?: RouterRequestConfig): Promise<RouterResponse<any, any>>;
put(url: string, options?: RouterRequestConfig): Promise<RouterResponse<any, any>>;
patch(url: string, options?: RouterRequestConfig): Promise<RouterResponse<any, any>>;
delete(url: string, options?: RouterRequestConfig): Promise<RouterResponse<any, any>>;
}
export declare const useForm: {
<T extends object>(data: T | (() => T), rememberKey?: string): Signal<VortexForm<T>>;
resolveErrors(_response: RouterResponse): Record<string, string>;
};
export {};