import { type Accessor, type Setter, type AccessorArray, type EffectFunction, type MemoOptions, type NoInfer, type SignalOptions } from "solid-js"; import { type EffectOptions } from "@solid-primitives/utils"; export type MemoOptionsWithValue = MemoOptions & { value?: T; }; export type AsyncMemoCalculation = (prev: T | Init) => Promise | T; /** * Solid's `createReaction` that is based on pure computation *(runs before render, and is non-batching)* * * @param onInvalidate callback that runs when the tracked sources trigger update * @param options set computation name for debugging pourposes * - `options.initial` — an array of functions to be run initially and tracked. *(useful for runing code before other pure computations)* * @returns track() function * * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createPureReaction * * @example * const [count, setCount] = createSignal(0); * const track = createPureReaction(() => {...}); * track(count); * setCount(1); // triggers callback * * // sources need to be re-tracked every time * setCount(2); // doesn't trigger callback */ export declare function createPureReaction(onInvalidate: VoidFunction, options?: EffectOptions): (tracking: VoidFunction) => void; /** * A combined memo of multiple sources, last updated source will be the value of the returned signal. * @param sources list of reactive calculations/signals/memos * @param options signal options * @returns signal with value of the last updated source * @example * const [count, setCount] = createSignal(1); * const [text, setText] = createSignal("hello"); * const lastUpdated = createLatest([count, text]); * lastUpdated() // => "hello" * setCount(4) * lastUpdated() // => 4 */ export declare function createLatest[]>(sources: T, options?: MemoOptions>): Accessor>; /** * A combined memo of multiple sources, returns the values of sources updated in the last tick. * @param sources list of reactive calculations/signals/memos * @param options signal options * @returns signal with value of the last updated sources * @example * const [count, setCount] = createSignal(1); * const [text, setText] = createSignal("hello"); * const lastUpdated = createLatest([count, text]); * lastUpdated() // => [1, "hello"] * setCount(4) * lastUpdated() // => [4] */ export declare function createLatestMany[]>(sources: T, options?: EffectOptions): Accessor[]>; /** * Solid's `createMemo` which value can be overwritten by a setter. Signal value will be the last one, set by a setter or a memo calculation. * @param fn callback that calculates the value * @param value initial value (for calcultion) * @param options give a name to the reactive computation, or change `equals` method. * @returns signal returning value of the last change. * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createWritableMemo * @example * const [count, setCount] = createSignal(1); * const [result, setResult] = createWritableMemo(() => count() * 2); * setResult(5) // overwrites calculation result */ export declare function createWritableMemo(fn: EffectFunction, Next>): [signal: Accessor, setter: Setter]; export declare function createWritableMemo(fn: EffectFunction, value: Init, options?: MemoOptions): [signal: Accessor, setter: Setter]; /** * @deprecated Please use `createSchedule` from `@solid-primitives/schedule` instead. */ export declare function createDebouncedMemo(fn: EffectFunction, Next>, timeoutMs: number): Accessor; export declare function createDebouncedMemo(fn: EffectFunction, timeoutMs: number, value: Init, options?: MemoOptions): Accessor; /** * @deprecated Please use `createSchedule` from `@solid-primitives/schedule` instead. */ export declare function createDebouncedMemoOn(deps: AccessorArray | Accessor, fn: (input: S, prevInput: S | undefined, prev: undefined | NoInfer) => Next, timeoutMs: number): Accessor; export declare function createDebouncedMemoOn(deps: AccessorArray | Accessor, fn: (input: S, prevInput: S | undefined, prev: Prev | Init) => Next, timeoutMs: number, value: Init, options?: MemoOptions): Accessor; /** * @deprecated Please use `createSchedule` from `@solid-primitives/schedule` instead. */ export declare function createThrottledMemo(fn: EffectFunction, Next>, timeoutMs: number): Accessor; export declare function createThrottledMemo(fn: EffectFunction, timeoutMs: number, value: Init, options?: MemoOptions): Accessor; /** * @deprecated Please just use `createResource` instead. */ export declare function createAsyncMemo(calc: AsyncMemoCalculation, options: MemoOptionsWithValue & { value: T; }): Accessor; export declare function createAsyncMemo(calc: AsyncMemoCalculation, options?: MemoOptionsWithValue): Accessor; /** * Lazily evaluated `createMemo`. Will run the calculation only if is being listened to. * * @param calc pure reactive calculation returning some value * @param value the initial previous value *(in callback)* * @param options set computation name for debugging pourposes * @returns signal of a value that was returned by the calculation * * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createLazyMemo * * @example * const double = createLazyMemo(() => count() * 2) */ export declare function createLazyMemo(calc: (prev: T) => T, value: T, options?: EffectOptions): Accessor; export declare function createLazyMemo(calc: (prev: T | undefined) => T, value?: undefined, options?: EffectOptions): Accessor; /** * Reference counted `createMemo`. The memo calculation will only run when there is at least one listener. * * Once the number of listeners drops to zero, the internal memo will be disposed after a microtask. * If a new listener is added later, the internal memo will be re-constructed. * * Unlike `createLazyMemo`, the internal memo's lifetime is managed by the number of listeners, * and it will stop updating when there are no listeners. * * It can be created outside of a reactive root, as it manages its own internal owner. * If it is created inside a reactive root, it will carry the context of that root. * * On the server, it will calculate the value lazily when first accessed and then cache it. * * **Note:** Because the internal memo is disposed when there are no listeners, the `prev` value in the calculation function will become stale if the internal memo is reconstructed. * * @param calc pure reactive calculation returning some value * @param value initial value for the calculation * @param options computation options * @returns accessor of the calculated value * * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createRcMemo * * @example * ```ts * const double = createRcMemo(() => count() * 2) * ``` */ export declare function createRcMemo(calc: (prev: T) => T, value: T, options?: EffectOptions): Accessor; export declare function createRcMemo(calc: (prev: T | undefined) => T, value?: undefined, options?: EffectOptions): Accessor; export type CacheCalculation = (key: Key, prev: Value | undefined) => Value; export type CacheKeyAccessor = (key: Key) => Value; export type CacheOptions = MemoOptions & { size?: number; }; /** * Custom, lazily-evaluated, cached memo. The caching is based on a `key`, it has to be declared up-front as a reactive source, or passed to the signal access function. * * @param key a reactive source, that will serve as cache key (later value access for the same key will be taken from cache instead of recalculated) * @param calc calculation function returning value to cache. the function is **tracking** - will recalculate when the accessed signals change. * @param options set maximum **size** of the cache, or memo options. * @returns signal access function * * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createMemoCache * * @example * set the reactive key up-front * ```ts * const [count, setCount] = createSignal(1) * const double = createMemoCache(count, n => n * 2) * // access value: * double() * ``` * or pass it to the access function (let's accessing different keys in different places) * ```ts * const double = createMemoCache((n: number) => n * 2) * // access with key * double(count()) * ``` */ export declare function createMemoCache(key: Accessor, calc: CacheCalculation, options?: CacheOptions): Accessor; export declare function createMemoCache(calc: CacheCalculation, options?: CacheOptions): CacheKeyAccessor; /** * Primitive for updating signal in a predictable way. SolidJS equivalent of React's [useReducer](https://reactjs.org/docs/hooks-reference.html#usereducer). * @see https://github.com/solidjs-community/solid-primitives/tree/main/packages/memo#createReducer * @param dispatcher is the reducer, it's 1st parameter always is the current state of the reducer and it returns the new state of the reducer. * @param initialValue initial value of the signal * @returns * ```ts * [accessor: Accessor, dispatch: (...args: ActionData) => void] * ``` * - `accessor` can be used as you use a normal signal: `accessor()`. It contains the state of the reducer. * - `dispatch` is the action of the reducer, it is a sort of `setSignal` that does NOT receive the new state, but instructions to create it from the current state. */ export declare function createReducer>(dispatcher: (state: T, ...args: ActionData) => T, initialValue: T, options?: SignalOptions): [accessor: Accessor, dispatch: (...args: ActionData) => void];