1 | import type { Atom, WritableAtom } from './atom';
|
2 | import type { SuspensePromise } from './suspensePromise';
|
3 | declare type Awaited<T> = T extends Promise<infer V> ? Awaited<V> : T;
|
4 | declare type AnyAtomValue = unknown;
|
5 | declare type AnyAtom = Atom<AnyAtomValue>;
|
6 | declare type OnUnmount = () => void;
|
7 | declare type ReadError = unknown;
|
8 | declare type Revision = number;
|
9 | declare type InvalidatedRevision = number;
|
10 | declare type ReadDependencies = Map<AnyAtom, Revision>;
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export declare type AtomState<Value = AnyAtomValue> = {
|
16 | |
17 |
|
18 |
|
19 | r: Revision;
|
20 | |
21 |
|
22 |
|
23 |
|
24 | i?: InvalidatedRevision;
|
25 | |
26 |
|
27 |
|
28 |
|
29 |
|
30 | d: ReadDependencies;
|
31 | } & ({
|
32 | e: ReadError;
|
33 | } | {
|
34 | p: SuspensePromise;
|
35 | } | {
|
36 | v: Awaited<Value>;
|
37 | });
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export declare type VersionObject = {
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | p?: VersionObject;
|
61 | };
|
62 | declare type Listeners = Set<(version?: VersionObject) => void>;
|
63 | declare type Dependents = Set<AnyAtom>;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | declare type Mounted = {
|
72 |
|
73 | l: Listeners;
|
74 |
|
75 | t: Dependents;
|
76 |
|
77 | u?: OnUnmount;
|
78 | };
|
79 | declare type StateListener = () => void;
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export declare const READ_ATOM = "r";
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | export declare const WRITE_ATOM = "w";
|
95 |
|
96 |
|
97 |
|
98 |
|
99 | export declare const COMMIT_ATOM = "c";
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | export declare const SUBSCRIBE_ATOM = "s";
|
114 |
|
115 |
|
116 |
|
117 | export declare const RESTORE_ATOMS = "h";
|
118 | export declare const DEV_SUBSCRIBE_STATE = "n";
|
119 | export declare const DEV_GET_MOUNTED_ATOMS = "l";
|
120 | export declare const DEV_GET_ATOM_STATE = "a";
|
121 | export declare const DEV_GET_MOUNTED = "m";
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | export declare const createStore: (initialValues?: Iterable<readonly [AnyAtom, unknown]> | undefined) => {
|
143 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject | undefined) => AtomState<Value>;
|
144 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject | undefined) => Result;
|
145 | c: (_atom: AnyAtom | null, version?: VersionObject | undefined) => void;
|
146 | s: (atom: AnyAtom, callback: (version?: VersionObject | undefined) => void) => () => void;
|
147 | h: (values: Iterable<readonly [AnyAtom, AnyAtomValue]>, version?: VersionObject | undefined) => void;
|
148 | n: (l: StateListener) => () => void;
|
149 | l: () => IterableIterator<AnyAtom>;
|
150 | a: (a: AnyAtom) => AtomState<unknown> | undefined;
|
151 | m: (a: AnyAtom) => Mounted | undefined;
|
152 | } | {
|
153 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject | undefined) => AtomState<Value>;
|
154 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject | undefined) => Result;
|
155 | c: (_atom: AnyAtom | null, version?: VersionObject | undefined) => void;
|
156 | s: (atom: AnyAtom, callback: (version?: VersionObject | undefined) => void) => () => void;
|
157 | h: (values: Iterable<readonly [AnyAtom, AnyAtomValue]>, version?: VersionObject | undefined) => void;
|
158 | n?: never;
|
159 | l?: never;
|
160 | a?: never;
|
161 | m?: never;
|
162 | };
|
163 | export declare type Store = ReturnType<typeof createStore>;
|
164 | export declare const createStoreForExport: (initialValues?: Iterable<readonly [AnyAtom, unknown]> | undefined) => {
|
165 | get: <Value>(atom: Atom<Value>) => Awaited<Value> | undefined;
|
166 | asyncGet: <Value_1>(atom: Atom<Value_1>) => Promise<Awaited<Value_1>>;
|
167 | set: <Value_2, Update, Result extends void | Promise<void>>(atom: WritableAtom<Value_2, Update, Result>, update: Update) => Result;
|
168 | sub: (atom: AnyAtom, callback: () => void) => () => void;
|
169 | SECRET_INTERNAL_store: {
|
170 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject | undefined) => AtomState<Value>;
|
171 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject | undefined) => Result;
|
172 | c: (_atom: AnyAtom | null, version?: VersionObject | undefined) => void;
|
173 | s: (atom: AnyAtom, callback: (version?: VersionObject | undefined) => void) => () => void;
|
174 | h: (values: Iterable<readonly [AnyAtom, AnyAtomValue]>, version?: VersionObject | undefined) => void;
|
175 | n: (l: StateListener) => () => void;
|
176 | l: () => IterableIterator<AnyAtom>;
|
177 | a: (a: AnyAtom) => AtomState<unknown> | undefined;
|
178 | m: (a: AnyAtom) => Mounted | undefined;
|
179 | } | {
|
180 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject | undefined) => AtomState<Value>;
|
181 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject | undefined) => Result;
|
182 | c: (_atom: AnyAtom | null, version?: VersionObject | undefined) => void;
|
183 | s: (atom: AnyAtom, callback: (version?: VersionObject | undefined) => void) => () => void;
|
184 | h: (values: Iterable<readonly [AnyAtom, AnyAtomValue]>, version?: VersionObject | undefined) => void;
|
185 | n?: never;
|
186 | l?: never;
|
187 | a?: never;
|
188 | m?: never;
|
189 | };
|
190 | };
|
191 | export {};
|