/** The MIT License (MIT) Copyright (c) 2017 Adam Haile Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import { requestCallback } from "./scheduler.js"; import type { JSX } from "../jsx.js"; import type { FlowComponent } from "../render/index.js"; 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 var Owner: Owner | null; export declare let Transition: TransitionState | null; declare let ExternalSourceFactory: ExternalSourceFactory | null; /** Object storing callbacks for debugging during development */ export declare const DevHooks: { afterUpdate: (() => void) | null; afterCreateOwner: ((owner: Owner) => void) | null; }; export type ComputationState = 0 | 1 | 2; export interface SourceMapValue { value: unknown; name?: string; graph?: Owner; } export interface SignalState extends SourceMapValue { value: T; observers: Computation[] | null; observerSlots: number[] | null; tValue?: T; comparator?: (prev: T, next: T) => boolean; } export interface Owner { owned: Computation[] | null; cleanups: (() => void)[] | null; owner: Owner | null; context: any | null; sourceMap?: SourceMapValue[]; name?: string; } export interface Computation extends Owner { fn: EffectFunction; state: ComputationState; tState?: ComputationState; 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; } type ExternalSourceFactory = (fn: EffectFunction, trigger: () => void) => ExternalSource; export interface ExternalSource { track: EffectFunction; dispose: () => void; } export 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?: typeof Owner): T; export type Accessor = () => T; export type Setter = (undefined extends T ? () => undefined : {}) & ((value: (prev: T) => U) => U) & ((value: Exclude) => U) & ((value: Exclude | ((prev: T) => U)) => U); export 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 type NoInfer = [T][T extends any ? 0 : never]; export interface EffectOptions extends BaseOptions { } export 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 & { render?: boolean; }): 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; export interface Memo extends SignalState, Computation { value: Next; 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; interface Unresolved { state: "unresolved"; loading: false; error: undefined; latest: undefined; (): undefined; } interface Pending { state: "pending"; loading: true; error: undefined; latest: undefined; (): undefined; } interface Ready { state: "ready"; loading: false; error: undefined; latest: T; (): T; } interface Refreshing { state: "refreshing"; loading: true; error: undefined; latest: T; (): T; } interface Errored { state: "errored"; loading: false; error: any; latest: never; (): never; } export type Resource = Unresolved | Pending | Ready | Refreshing | Errored; export type InitializedResource = Ready | Refreshing | Errored; export type ResourceActions = { mutate: Setter; refetch: (info?: R) => T | Promise | undefined | null; }; export type ResourceSource = S | false | null | undefined | (() => S | false | null | undefined); export type ResourceFetcher = (k: S, info: ResourceFetcherInfo) => T | Promise; export type ResourceFetcherInfo = { value: T | undefined; refetching: R | boolean; }; export type ResourceOptions = { initialValue?: T; name?: string; deferStream?: boolean; ssrLoadFrom?: "initial" | "server"; storage?: (init: T | undefined) => [Accessor, Setter]; onHydrated?: (k: S | undefined, info: { value: T | undefined; }) => void; }; export type InitializedResourceOptions = ResourceOptions & { initialValue: T; }; export type ResourceReturn = [Resource, ResourceActions]; export type InitializedResourceReturn = [ InitializedResource, ResourceActions ]; /** * Creates a resource that wraps a repeated promise in a reactive pattern: * ```typescript * // Without source * const [resource, { mutate, refetch }] = createResource(fetcher, options); * // With source * const [resource, { mutate, refetch }] = createResource(source, fetcher, options); * ``` * @param source - reactive data function which has its non-nullish and non-false values passed to the fetcher, optional * @param fetcher - function that receives the source (true if source not provided), the last or initial value, and whether the resource is being refetched, and returns a value or a Promise: * ```typescript * const fetcher: ResourceFetcher = ( * sourceOutput: S, * info: { value: T | undefined, refetching: R | boolean } * ) => T | Promise; * ``` * @param options - an optional object with the initialValue and the name (for debugging purposes); see {@link ResourceOptions} * * @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, and if called with a value, that value will be passed to the fetcher via the `refetching` property on the fetcher's second parameter * * @description https://www.solidjs.com/docs/latest/api#createresource */ export declare function createResource(fetcher: ResourceFetcher, options: InitializedResourceOptions, true>): InitializedResourceReturn; export declare function createResource(fetcher: ResourceFetcher, options?: ResourceOptions, true>): ResourceReturn; export declare function createResource(source: ResourceSource, fetcher: ResourceFetcher, options: InitializedResourceOptions, S>): InitializedResourceReturn; export declare function createResource(source: ResourceSource, fetcher: ResourceFetcher, options?: ResourceOptions, S>): 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 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 type ReturnTypes = T extends readonly Accessor[] ? { [K in keyof T]: T[K] extends Accessor ? I : never; } : T extends Accessor ? I : never; export type AccessorArray = [...Extract<{ [K in keyof T]: Accessor; }, readonly unknown[]>]; export 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 * * @returns the same {@link fn} function that was passed in * * @description https://www.solidjs.com/docs/latest/api#oncleanup */ export declare function onCleanup any>(fn: T): T; /** * catchError - run an effect whenever an error is thrown within the context of the child scopes * @param fn boundary for the error * @param handler 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#catcherror */ export declare function catchError(fn: () => T, handler: (err: Error) => void): T | undefined; /** * @deprecated since version 1.7.0 and will be removed in next major - use catchError instead * 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: Error) => void): void; export declare function getListener(): Computation | null; export declare function getOwner(): Owner | null; export declare function runWithOwner(o: typeof Owner, fn: () => T): T | undefined; 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 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 interface DevComponent extends Memo { props: T; name: string; component: (props: T) => unknown; } export declare function devComponent(Comp: (props: P) => V, props: P): V; export declare function registerGraph(value: SourceMapValue): void; export 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, * options?: { name?: string } * ): Context; * ``` * @param defaultValue optional default to inject into context * @param options allows to set a name in dev mode for debugging purposes * @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(defaultValue?: undefined, options?: EffectOptions): Context; export declare function createContext(defaultValue: T, options?: EffectOptions): 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 type ResolvedJSXElement = Exclude; export type ResolvedChildren = ResolvedJSXElement | ResolvedJSXElement[]; export type ChildrenReturn = Accessor & { toArray: () => 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): ChildrenReturn; export type SuspenseContextType = { increment?: () => void; decrement?: () => void; inFallback?: () => boolean; effects?: Computation[]; resolved?: boolean; }; 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 {};