resig.js
Version:
Universal reactive signal library with complete platform features: signals, animations, CRDTs, scheduling, DOM integration. Works identically across React, SolidJS, Svelte, Vue, and Qwik.
37 lines (36 loc) • 1.2 kB
TypeScript
/**
* Network Algebra - HTTP operations and async data fetching
* React-Query replacement with algebraic composition
*/
import { Effect } from '../core/effect';
import { Time } from './time';
export interface AsyncState<T> {
data?: T;
loading: boolean;
error?: Error;
}
export interface Fetch<A> extends Effect<AsyncState<A>> {
readonly retry: (n: number) => Fetch<A>;
readonly cache: (key: string, ttl?: number) => Fetch<A>;
readonly refetch: () => Fetch<A>;
readonly getState: () => AsyncState<A>;
readonly setRetries: (n: number) => void;
}
/**
* Creates a Fetch effect with network operations
*/
export declare const fetch: <A>(fetcher: () => Promise<A>, deps?: Effect<unknown>[]) => Fetch<A> & {
_set: (value: AsyncState<A>) => void;
};
/**
* GET request helper
*/
export declare const get: <A>(url: string, deps?: Effect<unknown>[]) => Fetch<A>;
/**
* POST request helper
*/
export declare const post: <A, B>(url: string, body: B, deps?: Effect<unknown>[]) => Fetch<A>;
/**
* Natural transformation: Time → Fetch (timeout injection)
*/
export declare const withTimeout: <A>(ms: number) => (fetchEffect: Fetch<A>) => Time<AsyncState<A> | Error>;