1 | import { Atom, WritableAtom } from './atom';
|
2 | import { SuspensePromise } from './suspensePromise';
|
3 | type AnyAtomValue = unknown;
|
4 | type AnyAtom = Atom<AnyAtomValue>;
|
5 | type OnUnmount = () => void;
|
6 | type ReadError = unknown;
|
7 | type Revision = number;
|
8 | type ReadDependencies = Map<AnyAtom, Revision>;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | export type AtomState<Value = AnyAtomValue> = {
|
14 | |
15 |
|
16 |
|
17 | r: Revision;
|
18 | |
19 |
|
20 |
|
21 |
|
22 | y: boolean;
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 | d: ReadDependencies;
|
29 | } & ({
|
30 | e: ReadError;
|
31 | } | {
|
32 | p: SuspensePromise;
|
33 | } | {
|
34 | v: Awaited<Value>;
|
35 | });
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export type VersionObject = {
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | p?: VersionObject;
|
61 | };
|
62 | type Listeners = Set<(version?: VersionObject) => void>;
|
63 | type Dependents = Set<AnyAtom>;
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | type Mounted = {
|
72 |
|
73 | l: Listeners;
|
74 |
|
75 | t: Dependents;
|
76 |
|
77 | u?: OnUnmount;
|
78 | };
|
79 | 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 [
|
143 | AnyAtom,
|
144 | AnyAtomValue
|
145 | ]>) => {
|
146 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject) => AtomState<Value>;
|
147 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject) => Result;
|
148 | c: (_atom: AnyAtom | null, version?: VersionObject) => void;
|
149 | s: (atom: AnyAtom, callback: (version?: VersionObject) => void, version?: VersionObject) => () => void;
|
150 | h: (values: Iterable<readonly [
|
151 | AnyAtom,
|
152 | AnyAtomValue
|
153 | ]>, version?: VersionObject) => void;
|
154 | n: (l: StateListener) => () => void;
|
155 | l: () => IterableIterator<AnyAtom>;
|
156 | a: (a: AnyAtom) => AtomState<unknown> | undefined;
|
157 | m: (a: AnyAtom) => Mounted | undefined;
|
158 | } | {
|
159 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject) => AtomState<Value>;
|
160 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject) => Result;
|
161 | c: (_atom: AnyAtom | null, version?: VersionObject) => void;
|
162 | s: (atom: AnyAtom, callback: (version?: VersionObject) => void, version?: VersionObject) => () => void;
|
163 | h: (values: Iterable<readonly [
|
164 | AnyAtom,
|
165 | AnyAtomValue
|
166 | ]>, version?: VersionObject) => void;
|
167 | n?: never;
|
168 | l?: never;
|
169 | a?: never;
|
170 | m?: never;
|
171 | };
|
172 | export type Store = ReturnType<typeof createStore>;
|
173 | export declare const createStoreForExport: (initialValues?: Iterable<readonly [
|
174 | AnyAtom,
|
175 | AnyAtomValue
|
176 | ]>) => {
|
177 | get: <Value>(atom: Atom<Value>) => Awaited<Value> | undefined;
|
178 | asyncGet: <Value_1>(atom: Atom<Value_1>) => Promise<Awaited<Value_1>>;
|
179 | set: <Value_2, Update, Result extends void | Promise<void>>(atom: WritableAtom<Value_2, Update, Result>, update: Update) => Result;
|
180 | sub: (atom: AnyAtom, callback: () => void) => () => void;
|
181 | SECRET_INTERNAL_store: {
|
182 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject) => AtomState<Value>;
|
183 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject) => Result;
|
184 | c: (_atom: AnyAtom | null, version?: VersionObject) => void;
|
185 | s: (atom: AnyAtom, callback: (version?: VersionObject) => void, version?: VersionObject) => () => void;
|
186 | h: (values: Iterable<readonly [
|
187 | AnyAtom,
|
188 | AnyAtomValue
|
189 | ]>, version?: VersionObject) => void;
|
190 | n: (l: StateListener) => () => void;
|
191 | l: () => IterableIterator<AnyAtom>;
|
192 | a: (a: AnyAtom) => AtomState<unknown> | undefined;
|
193 | m: (a: AnyAtom) => Mounted | undefined;
|
194 | } | {
|
195 | r: <Value>(readingAtom: Atom<Value>, version?: VersionObject) => AtomState<Value>;
|
196 | w: <Value_1, Update, Result extends void | Promise<void>>(writingAtom: WritableAtom<Value_1, Update, Result>, update: Update, version?: VersionObject) => Result;
|
197 | c: (_atom: AnyAtom | null, version?: VersionObject) => void;
|
198 | s: (atom: AnyAtom, callback: (version?: VersionObject) => void, version?: VersionObject) => () => void;
|
199 | h: (values: Iterable<readonly [
|
200 | AnyAtom,
|
201 | AnyAtomValue
|
202 | ]>, version?: VersionObject) => void;
|
203 | n?: never;
|
204 | l?: never;
|
205 | a?: never;
|
206 | m?: never;
|
207 | };
|
208 | };
|
209 | export {};
|
210 | declare type Awaited<T> = T extends Promise<infer V> ? V : T; |
\ | No newline at end of file |