UNPKG

jotai

Version:

👻 Next gen state management that will spook you

30 lines (29 loc) • 1.48 kB
import { Atom, WritableAtom, AnyAtom, OnUnmount } from './types'; declare type Revision = number; declare type ReadDependencies = Map<AnyAtom, Revision>; export declare type AtomState<Value = unknown> = { re?: Error; rp?: Promise<void>; wp?: Promise<void>; v?: Value; r: Revision; d: ReadDependencies; }; declare type AtomStateMap = WeakMap<AnyAtom, AtomState>; declare type UseAtomSymbol = symbol; declare type Dependents = Set<AnyAtom | UseAtomSymbol>; declare type MountedMap = Map<AnyAtom, [Dependents, OnUnmount | void]>; declare type WorkInProgress = Map<AnyAtom, AtomState>; declare type UpdateState = (updater: (prev: State) => State) => void; export declare type State = { a: AtomStateMap; m: MountedMap; w: WorkInProgress; }; export declare const createState: (initialValues?: Iterable<readonly [Atom<unknown>, unknown]> | undefined) => State; export declare const readAtom: <Value>(state: State, updateState: UpdateState, readingAtom: Atom<Value>) => AtomState<Value>; export declare const addAtom: (state: State, updateState: UpdateState, addingAtom: AnyAtom, useId: symbol) => void; export declare const delAtom: (state: State, deletingAtom: AnyAtom, useId: symbol) => void; export declare const writeAtom: <Value, Update>(updateState: UpdateState, writingAtom: WritableAtom<Value, Update>, update: Update) => void | Promise<void>; export declare const commitState: (state: State, updateState: UpdateState) => void; export {};