/** * Represents a signal-based computation. */ export interface SignalLike { /** * Gets the current value of the signal with tracking by default. */ (): T; } /** * Represents a value that tracks changes over time. */ export interface Signal extends SignalLike { /** @ignore */ _effects: Set; /** * Accesses the current value of the signal without tracking. */ peek(): T; } export interface SignalOptions extends SetSignalOptions { /** * A custom equality function to compare the new value with the old value. */ equals?: (a: T, b: T) => boolean; } export interface SetSignalOptions { /** * Whether to force the update of the signal even if the new value has the * same reference. */ force?: boolean; /** * Whether to suppress the update of the signal's effects. */ silent?: boolean; } /** * Can be used to update a signal with a new value. */ export interface SignalSetter { (update: (value: U) => T, opts?: SetSignalOptions): void; (value: T extends Function ? never : T, opts?: SetSignalOptions): void; } export interface SubscopeOptions { details?: object; } interface Effect { _scope: Scope; _pure: boolean; _clean?: Cleanup; _deps: Set>; _run(): void; } /** * Represents the cleanup function of an effect. */ export type Cleanup = (() => void) | void | undefined | null; export interface Scope { readonly _parent?: Scope; _effects: Set; _subscopes: Set; _details: T; _run(fn: () => T): T; _cleanup(): void; } /** @ignore */ export declare const useScope: () => Scope; /** * Creates a new signal with the given value. * @returns A tuple with the signal and its setter. */ export declare const useSignal: ((value: T, opts?: SignalOptions) => readonly [Signal, SignalSetter]) & ((value?: T, opts?: SignalOptions) => readonly [Signal, SignalSetter]); /** * Runs the given function in a batch. * * @param fn Any calls to signal setters inside the function will be batched * and updated at the same time. */ export declare const useBatch: (fn: () => T) => T; export declare const flushBatch: () => void; /** * Creates an effect which will rerun when any accessed signal changes. * * @param fn The function to run; it can return a cleanup function. */ export declare const useEffect: (fn: () => Cleanup, deps?: SignalLike[]) => void; /** * Creates a memoized signal. * * @param fn The computation function. */ export declare const useMemo: (fn: () => T, opts?: SignalOptions) => Signal; /** * Executes a function inside a subscope which can be manually destroyed. * * @param fn The function to run in the subscope. * @returns A function to manually destroy the subscope. */ export declare const useSubscope: (fn: () => T, opts?: SubscopeOptions) => [T, () => void]; /** * Provide write capabilities to a signal. */ export interface RefSignal extends Signal, RefSignalSetter { /** * Sets the value of the signal. */ set: SignalSetter; } /** * A contravariant variant of {@link RefSignal}. */ export interface RefSignalSetter { /** * Sets the value of the signal. */ set: SignalSetter; } /** * Creates a new signal with write capabilities. */ export declare const useRef: ((value: T, opts?: SignalOptions) => RefSignal) & ((value?: T, opts?: SignalOptions) => RefSignal); /** * Represents a value that can be a signal or a constant value. * * Note that functions are not allowed as constant values. */ export type MaybeSignal = SignalLike | (T extends Function ? never : T); /** * @namespace */ export declare const MaybeSignal: { /** * Transforms the given {@link MaybeSignal} into a {@link Signal}. */ upgrade: (signal: MaybeSignal) => SignalLike; /** * Gets the value of the given {@link MaybeSignal}. */ get: (signal: MaybeSignal) => T; /** * Accesses the value of the given {@link MaybeSignal} without tracking. */ peek(signal: MaybeSignal): T; }; export {};