@solidjs/signals
Version:
SolidJS' standalone reactivity implementation
20 lines (19 loc) • 1.21 kB
TypeScript
import { $REFRESH } from "../core/index.js";
import { type NoFn, type ProjectionOptions, type Store, type StoreSetter } from "./store.js";
/**
* Creates an optimistic store that can be used to optimistically update a value
* and then revert it back to the previous value at end of transition.
*
* When called with a plain value, creates an optimistic store.
* When called with a function, creates a derived optimistic store with `ProjectionOptions` (name, key, all).
*
* @param fn a function that receives the current store and can be used to mutate it directly inside a transition
* @param initial The initial value of the store.
* @param options Optional projection options for reconciliation.
*
* @returns A tuple containing a store accessor and a setter function to apply changes.
*/
export declare function createOptimisticStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>): [get: Store<T>, set: StoreSetter<T>];
export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store?: NoFn<T> | Store<NoFn<T>>, options?: ProjectionOptions): [get: Store<T> & {
[$REFRESH]: any;
}, set: StoreSetter<T>];