1 | import type { Atom, WritableAtom } from './atom';
|
2 | declare type AnyAtom = Atom<unknown>;
|
3 | declare type OnUnmount = () => void;
|
4 | declare type NonPromise<T> = T extends Promise<infer V> ? V : T;
|
5 | declare const IS_EQUAL_PROMISE: unique symbol;
|
6 | declare const INTERRUPT_PROMISE: unique symbol;
|
7 | declare type InterruptablePromise = Promise<void> & {
|
8 | [IS_EQUAL_PROMISE]: (p: Promise<void>) => boolean;
|
9 | [INTERRUPT_PROMISE]: () => void;
|
10 | };
|
11 | declare type Revision = number;
|
12 | declare type InvalidatedRevision = number;
|
13 | declare type ReadDependencies = Map<AnyAtom, Revision>;
|
14 | export declare type AtomState<Value = unknown> = {
|
15 | e?: Error;
|
16 | p?: InterruptablePromise;
|
17 | c?: () => void;
|
18 | w?: Promise<void>;
|
19 | v?: NonPromise<Value>;
|
20 | r: Revision;
|
21 | i?: InvalidatedRevision;
|
22 | d: ReadDependencies;
|
23 | };
|
24 | declare type AtomStateMap = WeakMap<AnyAtom, AtomState>;
|
25 | declare type Listeners = Set<() => void>;
|
26 | declare type Dependents = Set<AnyAtom>;
|
27 | declare type Mounted = {
|
28 | l: Listeners;
|
29 | d: Dependents;
|
30 | u: OnUnmount | void;
|
31 | };
|
32 | declare type MountedMap = WeakMap<AnyAtom, Mounted>;
|
33 | declare type StateListener = (updatedAtom: AnyAtom, isNewAtom: boolean) => void;
|
34 | declare type StateVersion = number;
|
35 | declare type PendingAtoms = Set<AnyAtom>;
|
36 | export declare type State = {
|
37 | l?: StateListener;
|
38 | v: StateVersion;
|
39 | a: AtomStateMap;
|
40 | m: MountedMap;
|
41 | p: PendingAtoms;
|
42 | };
|
43 | export declare const createState: (initialValues?: Iterable<readonly [AnyAtom, unknown]> | undefined, stateListener?: StateListener | undefined) => State;
|
44 | export declare const readAtom: <Value>(state: State, readingAtom: Atom<Value>) => AtomState<Value>;
|
45 | export declare const writeAtom: <Value, Update>(state: State, writingAtom: WritableAtom<Value, Update>, update: Update) => void | Promise<void>;
|
46 | export declare const subscribeAtom: (state: State, atom: AnyAtom, callback: () => void) => () => void;
|
47 | export declare const restoreAtoms: (state: State, values: Iterable<readonly [AnyAtom, unknown]>) => void;
|
48 | export {};
|