UNPKG

1.45 kBTypeScriptView Raw
1import { Atom, WritableAtom, AnyAtom, OnUnmount } from './types';
2declare type Revision = number;
3declare type ReadDependencies = Map<AnyAtom, Revision>;
4export declare type AtomState<Value = unknown> = {
5 re?: Error;
6 rp?: Promise<void>;
7 wp?: Promise<void>;
8 v?: Value;
9 r: Revision;
10 d: ReadDependencies;
11};
12declare type AtomStateMap = WeakMap<AnyAtom, AtomState>;
13declare type UseAtomSymbol = symbol;
14declare type Dependents = Set<AnyAtom | UseAtomSymbol>;
15declare type MountedMap = Map<AnyAtom, [
16 Dependents,
17 OnUnmount | void
18]>;
19declare type WorkInProgress = Map<AnyAtom, AtomState>;
20export declare type UpdateState = (updater: (prev: State) => State) => void;
21export declare type State = {
22 a: AtomStateMap;
23 m: MountedMap;
24 w: WorkInProgress;
25};
26export declare const createState: (initialValues?: Iterable<readonly [
27 Atom<unknown>,
28 unknown
29]> | undefined) => State;
30export declare const readAtom: <Value>(state: State, updateState: UpdateState, readingAtom: Atom<Value>) => AtomState<Value>;
31export declare const addAtom: (updateState: UpdateState, addingAtom: AnyAtom, useId: symbol) => void;
32export declare const delAtom: (updateState: UpdateState, deletingAtom: AnyAtom, useId: symbol) => void;
33export declare const writeAtom: <Value, Update>(updateState: UpdateState, writingAtom: WritableAtom<Value, Update>, update: Update) => void | Promise<void>;
34export {};