import { requestCallback } from "./scheduler"; import type { JSX } from "../jsx"; import type { FlowComponent } from "../render"; export declare const equalFn: (a: T, b: T) => boolean; export declare const $PROXY: unique symbol; export declare const $TRACK: unique symbol; export declare const $DEVCOMP: unique symbol; export declare const NOTPENDING: {}; export declare var Owner: Owner | null; export declare let Transition: TransitionState | null; declare let ExternalSourceFactory: ExternalSourceFactory | null; declare global { var _$afterUpdate: () => void; var _$afterCreateRoot: (root: Owner) => void; } export interface SignalState { value?: T; observers: Computation[] | null; observerSlots: number[] | null; pending: T | {}; tValue?: T; comparator?: (prev: T, next: T) => boolean; name?: string; } export interface Owner { owned: Computation[] | null; cleanups: (() => void)[] | null; owner: Owner | null; context: any | null; sourceMap?: Record; name?: string; componentName?: string; } export interface Computation extends Owner { fn: EffectFunction; state: number; tState?: number; sources: SignalState[] | null; sourceSlots: number[] | null; value?: Init; updatedAt: number | null; pure: boolean; user?: boolean; suspense?: SuspenseContextType; } export interface TransitionState { sources: Set>; effects: Computation[]; promises: Set>; disposed: Set>; queue: Set>; scheduler?: (fn: () => void) => unknown; running: boolean; done?: Promise; resolve?: () => void; } declare type ExternalSourceFactory = (fn: EffectFunction, trigger: () => void) => ExternalSource; export interface ExternalSource { track: EffectFunction; dispose: () => void; } export declare type RootFunction = (dispose: () => void) => T; /** * Creates a new non-tracked reactive context that doesn't auto-dispose * * @param fn a function in which the reactive state is scoped * @param detachedOwner optional reactive context to bind the root to * @returns the output of `fn`. * * @description https://www.solidjs.com/docs/latest/api#createroot */ export declare function createRoot(fn: RootFunction, detachedOwner?: Owner): T; export declare type Accessor = () => T; export declare type Setter = (undefined extends T ? () => undefined : {}) & ((value: (prev: T) => U) => U) & ((value: Exclude) => U) & ((value: Exclude | ((prev: T) => U)) => U); export declare type Signal = [get: Accessor, set: Setter]; export interface SignalOptions extends MemoOptions { internal?: boolean; } /** * Creates a simple reactive state with a getter and setter * ```typescript * const [state: Accessor, setState: Setter] = createSignal( * value: T, * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) } * ) * ``` * @param value initial value of the state; if empty, the state's type will automatically extended with undefined; otherwise you need to extend the type manually if you want setting to undefined not be an error * @param options optional object with a name for debugging purposes and equals, a comparator function for the previous and next value to allow fine-grained control over the reactivity * * @returns ```typescript * [state: Accessor, setState: Setter] * ``` * * the Accessor is merely a function that returns the current value and registers each call to the reactive root * * the Setter is a function that allows directly setting or mutating the value: * ```typescript * const [count, setCount] = createSignal(0); * setCount(count => count + 1); * ``` * * @description https://www.solidjs.com/docs/latest/api#createsignal */ export declare function createSignal(): Signal; export declare function createSignal(value: T, options?: SignalOptions): Signal; export interface BaseOptions { name?: string; } export declare type NoInfer = [T][T extends any ? 0 : never]; export interface EffectOptions extends BaseOptions { } export declare type EffectFunction = (v: Prev) => Next; /** * Creates a reactive computation that runs immediately before render, mainly used to write to other reactive primitives * ```typescript * export function createComputed( * fn: (v: Init | Next) => Next, * value?: Init, * options?: { name?: string } * ): void; * ``` * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument * @param options allows to set a name in dev mode for debugging purposes * * @description https://www.solidjs.com/docs/latest/api#createcomputed */ export declare function createComputed(fn: EffectFunction, Next>): void; export declare function createComputed(fn: EffectFunction, value: Init, options?: EffectOptions): void; /** * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected * ```typescript * export function createRenderEffect( * fn: (v: T) => T, * value?: T, * options?: { name?: string } * ): void; * ``` * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument * @param options allows to set a name in dev mode for debugging purposes * * @description https://www.solidjs.com/docs/latest/api#createrendereffect */ export declare function createRenderEffect(fn: EffectFunction, Next>): void; export declare function createRenderEffect(fn: EffectFunction, value: Init, options?: EffectOptions): void; /** * Creates a reactive computation that runs after the render phase * ```typescript * export function createEffect( * fn: (v: T) => T, * value?: T, * options?: { name?: string } * ): void; * ``` * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument * @param options allows to set a name in dev mode for debugging purposes * * @description https://www.solidjs.com/docs/latest/api#createeffect */ export declare function createEffect(fn: EffectFunction, Next>): void; export declare function createEffect(fn: EffectFunction, value: Init, options?: EffectOptions): void; /** * Creates a reactive computation that runs after the render phase with flexible tracking * ```typescript * export function createReaction( * onInvalidate: () => void, * options?: { name?: string } * ): (fn: () => void) => void; * ``` * @param invalidated a function that is called when tracked function is invalidated. * @param options allows to set a name in dev mode for debugging purposes * * @description https://www.solidjs.com/docs/latest/api#createreaction */ export declare function createReaction(onInvalidate: () => void, options?: EffectOptions): (tracking: () => void) => void; interface Memo extends SignalState, Computation { tOwned?: Computation[]; } export interface MemoOptions extends EffectOptions { equals?: false | ((prev: T, next: T) => boolean); } /** * Creates a readonly derived reactive memoized signal * ```typescript * export function createMemo( * fn: (v: T) => T, * value?: T, * options?: { name?: string, equals?: false | ((prev: T, next: T) => boolean) } * ): () => T; * ``` * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument * @param options allows to set a name in dev mode for debugging purposes and use a custom comparison function in equals * * @description https://www.solidjs.com/docs/latest/api#creatememo */ export declare function createMemo(fn: EffectFunction, Next>): Accessor; export declare function createMemo(fn: EffectFunction, value: Init, options?: MemoOptions): Accessor; export interface Resource extends Accessor { loading: boolean; error: any; latest: T; } export declare type ResourceActions = { mutate: Setter; refetch: (info?: unknown) => T | Promise | undefined | null; }; export declare type ResourceSource = S | false | null | undefined | (() => S | false | null | undefined); export declare type ResourceFetcher = (k: S, info: ResourceFetcherInfo) => T | Promise; export declare type ResourceFetcherInfo = { value: T | undefined; refetching?: unknown; }; export declare type ResourceOptions = undefined extends T ? { initialValue?: T; name?: string; deferStream?: boolean; onHydrated?: (k: S, info: ResourceFetcherInfo) => void; } : { initialValue: T; name?: string; deferStream?: boolean; onHydrated?: (k: S, info: ResourceFetcherInfo) => void; }; export declare type ResourceReturn | undefined, K = T> = [ Resource["initialValue"] extends undefined ? T | undefined : T>, ResourceActions ]; /** * Creates a resource that wraps a repeated promise in a reactive pattern: * ```typescript * const [resource, { mutate, refetch }] = createResource(source, fetcher, options); * ``` * @param source - reactive data function to toggle the request, optional * @param fetcher - function that receives the source (or true) and an accessor for the last or initial value and returns a value or a Promise with the value: * ```typescript * const fetcher: ResourceFetcher = ( * sourceOutput: ReturnValue, * info: ResourceFetcherInfo * ) => T | Promise; * ``` * @param options - an optional object with the initialValue and the name (for debugging purposes) * * @returns ```typescript * [Resource, { mutate: Setter, refetch: () => void }] * ``` * * * Setting an `initialValue` in the options will mean that both the prev() accessor and the resource should never return undefined (if that is wanted, you need to extend the type with undefined) * * `mutate` allows to manually overwrite the resource without calling the fetcher * * `refetch` will re-run the fetcher without changing the source * * @description https://www.solidjs.com/docs/latest/api#createresource */ export declare function createResource(fetcher: ResourceFetcher, options?: ResourceOptions): ResourceReturn; export declare function createResource(fetcher: ResourceFetcher, options: ResourceOptions): ResourceReturn; export declare function createResource(source: ResourceSource, fetcher: ResourceFetcher, options?: ResourceOptions): ResourceReturn; export declare function createResource(source: ResourceSource, fetcher: ResourceFetcher, options: ResourceOptions): ResourceReturn; export interface DeferredOptions { equals?: false | ((prev: T, next: T) => boolean); name?: string; timeoutMs?: number; } /** * Creates a reactive computation that only runs and notifies the reactive context when the browser is idle * ```typescript * export function createDeferred( * fn: (v: T) => T, * options?: { timeoutMs?: number, name?: string, equals?: false | ((prev: T, next: T) => boolean) } * ): () => T); * ``` * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param options allows to set the timeout in milliseconds, use a custom comparison function and set a name in dev mode for debugging purposes * * @description https://www.solidjs.com/docs/latest/api#createdeferred */ export declare function createDeferred(source: Accessor, options?: DeferredOptions): Accessor; export declare type EqualityCheckerFunction = (a: U, b: T) => boolean; /** * Creates a conditional signal that only notifies subscribers when entering or exiting their key matching the value * ```typescript * export function createSelector( * source: () => T * fn: (a: U, b: T) => boolean, * options?: { name?: string } * ): (k: U) => boolean; * ``` * @param source * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation * @param options allows to set a name in dev mode for debugging purposes, optional * * ```typescript * const isSelected = createSelector(selectedId); * * {(item) =>
  • {item.name}
  • } *
    * ``` * * This makes the operation O(2) instead of O(n). * * @description https://www.solidjs.com/docs/latest/api#createselector */ export declare function createSelector(source: Accessor, fn?: EqualityCheckerFunction, options?: BaseOptions): (key: U) => boolean; /** * Holds changes inside the block before the reactive context is updated * @param fn wraps the reactive updates that should be batched * @returns the return value from `fn` * * @description https://www.solidjs.com/docs/latest/api#batch */ export declare function batch(fn: Accessor): T; /** * Ignores tracking context inside its scope * @param fn the scope that is out of the tracking context * @returns the return value of `fn` * * @description https://www.solidjs.com/docs/latest/api#untrack */ export declare function untrack(fn: Accessor): T; /** @deprecated */ export declare type ReturnTypes = T extends readonly Accessor[] ? { [K in keyof T]: T[K] extends Accessor ? I : never; } : T extends Accessor ? I : never; export declare type AccessorArray = [...Extract<{ [K in keyof T]: Accessor; }, readonly unknown[]>]; export declare type OnEffectFunction = (input: S, prevInput: S | undefined, prev: Prev) => Next; export interface OnOptions { defer?: boolean; } /** * on - make dependencies of a computation explicit * ```typescript * export function on( * deps: Accessor | AccessorArray, * fn: (input: S, prevInput: S | undefined, prevValue: U | undefined) => U, * options?: { defer?: boolean } = {} * ): (prevValue: U | undefined) => U; * ``` * @param deps list of reactive dependencies or a single reactive dependency * @param fn computation on input; the current previous content(s) of input and the previous value are given as arguments and it returns a new value * @param options optional, allows deferred computation until at the end of the next change * @returns an effect function that is passed into createEffect. For example: * * ```typescript * createEffect(on(a, (v) => console.log(v, b()))); * * // is equivalent to: * createEffect(() => { * const v = a(); * untrack(() => console.log(v, b())); * }); * ``` * * @description https://www.solidjs.com/docs/latest/api#on */ export declare function on(deps: AccessorArray | Accessor, fn: OnEffectFunction, Next>, options?: OnOptions & { defer?: false; }): EffectFunction, NoInfer>; export declare function on(deps: AccessorArray | Accessor, fn: OnEffectFunction, Next>, options: OnOptions & { defer: true; }): EffectFunction>; /** * onMount - run an effect only after initial render on mount * @param fn an effect that should run only once on mount * * @description https://www.solidjs.com/docs/latest/api#onmount */ export declare function onMount(fn: () => void): void; /** * onCleanup - run an effect once before the reactive scope is disposed * @param fn an effect that should run only once on cleanup * * @description https://www.solidjs.com/docs/latest/api#oncleanup */ export declare function onCleanup(fn: () => void): () => void; /** * onError - run an effect whenever an error is thrown within the context of the child scopes * @param fn an error handler that receives the error * * * If the error is thrown again inside the error handler, it will trigger the next available parent handler * * @description https://www.solidjs.com/docs/latest/api#onerror */ export declare function onError(fn: (err: any) => void): void; export declare function getListener(): Computation | null; export declare function getOwner(): Owner | null; export declare function runWithOwner(o: Owner, fn: () => T): T; export declare function enableScheduling(scheduler?: typeof requestCallback): void; /** * ```typescript * export function startTransition(fn: () => void) => Promise * * @description https://www.solidjs.com/docs/latest/api#usetransition */ export declare function startTransition(fn: () => unknown): Promise; export declare type Transition = [Accessor, (fn: () => void) => Promise]; /** * ```typescript * export function useTransition(): [ * () => boolean, * (fn: () => void, cb?: () => void) => void * ]; * @returns a tuple; first value is an accessor if the transition is pending and a callback to start the transition * * @description https://www.solidjs.com/docs/latest/api#usetransition */ export declare function useTransition(): Transition; export declare function resumeEffects(e: Computation[]): void; export declare function devComponent(Comp: (props: T) => JSX.Element, props: T): JSX.Element; export declare function hashValue(v: any): string; export declare function registerGraph(name: string, value: { value: unknown; }): string; interface GraphRecord { [k: string]: GraphRecord | unknown; } export declare function serializeGraph(owner?: Owner | null): GraphRecord; export declare type ContextProviderComponent = FlowComponent<{ value: T; }>; export interface Context { id: symbol; Provider: ContextProviderComponent; defaultValue: T; } /** * Creates a Context to handle a state scoped for the children of a component * ```typescript * interface Context { * id: symbol; * Provider: FlowComponent<{ value: T }>; * defaultValue: T; * } * export function createContext(defaultValue?: T): Context; * ``` * @param defaultValue optional default to inject into context * @returns The context that contains the Provider Component and that can be used with `useContext` * * @description https://www.solidjs.com/docs/latest/api#createcontext */ export declare function createContext(): Context; export declare function createContext(defaultValue: T): Context; /** * use a context to receive a scoped state from a parent's Context.Provider * * @param context Context object made by `createContext` * @returns the current or `defaultValue`, if present * * @description https://www.solidjs.com/docs/latest/api#usecontext */ export declare function useContext(context: Context): T; export declare type ResolvedJSXElement = Exclude; export declare type ResolvedChildren = ResolvedJSXElement | ResolvedJSXElement[]; /** * Resolves child elements to help interact with children * * @param fn an accessor for the children * @returns a accessor of the same children, but resolved * * @description https://www.solidjs.com/docs/latest/api#children */ export declare function children(fn: Accessor): Accessor; export declare type SuspenseContextType = { increment?: () => void; decrement?: () => void; inFallback?: () => boolean; effects?: Computation[]; resolved?: boolean; }; declare type SuspenseContext = Context & { active?(): boolean; increment?(): void; decrement?(): void; }; declare let SuspenseContext: SuspenseContext; export declare function getSuspenseContext(): SuspenseContext; export declare function enableExternalSource(factory: ExternalSourceFactory): void; export declare function readSignal(this: SignalState | Memo): any; export declare function writeSignal(node: SignalState | Memo, value: any, isComp?: boolean): any; export {};