1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | export { };
|
8 |
|
9 | import * as React from 'react';
|
10 |
|
11 |
|
12 | type NodeKey = string;
|
13 |
|
14 |
|
15 | export class DefaultValue {
|
16 | private __tag: 'DefaultValue';
|
17 | }
|
18 |
|
19 |
|
20 | export type RecoilRootProps = {
|
21 | initializeState?: (mutableSnapshot: MutableSnapshot) => void,
|
22 | override?: true,
|
23 | } | {override: false};
|
24 |
|
25 | export const RecoilRoot: React.FC<RecoilRootProps>;
|
26 |
|
27 |
|
28 | declare const SnapshotID_OPAQUE: unique symbol;
|
29 | export interface SnapshotID {
|
30 | readonly [SnapshotID_OPAQUE]: true;
|
31 | }
|
32 |
|
33 | interface ComponentInfo {
|
34 | name: string;
|
35 | }
|
36 |
|
37 | interface AtomInfo<T> {
|
38 | loadable?: Loadable<T>;
|
39 | isActive: boolean;
|
40 | isSet: boolean;
|
41 | isModified: boolean;
|
42 | type: 'atom' | 'selector' | undefined;
|
43 | deps: Iterable<RecoilValue<T>>;
|
44 | subscribers: {
|
45 | nodes: Iterable<RecoilValue<T>>,
|
46 | components: Iterable<ComponentInfo>,
|
47 | };
|
48 | }
|
49 |
|
50 | export class Snapshot {
|
51 | getID(): SnapshotID;
|
52 | getLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
53 | getPromise<T>(recoilValue: RecoilValue<T>): Promise<T>;
|
54 | getNodes_UNSTABLE(opts?: { isModified?: boolean }): Iterable<RecoilValue<unknown>>;
|
55 | getInfo_UNSTABLE<T>(recoilValue: RecoilValue<T>): AtomInfo<T>;
|
56 | map(cb: (mutableSnapshot: MutableSnapshot) => void): Snapshot;
|
57 | asyncMap(cb: (mutableSnapshot: MutableSnapshot) => Promise<void>): Promise<Snapshot>;
|
58 | }
|
59 |
|
60 | export class MutableSnapshot extends Snapshot {
|
61 | set: SetRecoilState;
|
62 | reset: ResetRecoilState;
|
63 | }
|
64 |
|
65 |
|
66 | export type AtomEffect<T> = (param: {
|
67 | node: RecoilState<T>,
|
68 | trigger: 'set' | 'get',
|
69 |
|
70 |
|
71 | setSelf: (param:
|
72 | | T
|
73 | | DefaultValue
|
74 | | Promise<T | DefaultValue>
|
75 | | ((param: T | DefaultValue) => T | DefaultValue),
|
76 | ) => void,
|
77 | resetSelf: () => void,
|
78 |
|
79 |
|
80 |
|
81 | onSet: (
|
82 | param: (newValue: T | DefaultValue, oldValue: T | DefaultValue) => void,
|
83 | ) => void,
|
84 | }) => void | (() => void);
|
85 |
|
86 | // atom.d.ts
|
87 | export interface AtomOptions<T> {
|
88 | key: NodeKey;
|
89 | default: RecoilValue<T> | Promise<T> | T;
|
90 | effects_UNSTABLE?: ReadonlyArray<AtomEffect<T>>;
|
91 | dangerouslyAllowMutability?: boolean;
|
92 | }
|
93 |
|
94 | /**
|
95 | * Creates an atom, which represents a piece of writeable state
|
96 | */
|
97 | export function atom<T>(options: AtomOptions<T>): RecoilState<T>;
|
98 |
|
99 | // selector.d.ts
|
100 | export type GetRecoilValue = <T>(recoilVal: RecoilValue<T>) => T;
|
101 | export type GetCallback = <Args extends ReadonlyArray<unknown>, Return>(
|
102 | fn: (interface: Readonly<{snapshot: Snapshot}>) => (...args: Args) => Return,
|
103 | ) => (...args: Args) => Return;
|
104 |
|
105 | export type SetRecoilState = <T>(
|
106 | recoilVal: RecoilState<T>,
|
107 | newVal: T | DefaultValue | ((prevValue: T) => T | DefaultValue),
|
108 | ) => void;
|
109 |
|
110 | export type ResetRecoilState = (recoilVal: RecoilState<any>) => void;
|
111 |
|
112 | export interface ReadOnlySelectorOptions<T> {
|
113 | key: string;
|
114 | get: (opts: { get: GetRecoilValue, getCallback: GetCallback }) => Promise<T> | RecoilValue<T> | T;
|
115 | dangerouslyAllowMutability?: boolean;
|
116 | }
|
117 |
|
118 | export interface ReadWriteSelectorOptions<T> extends ReadOnlySelectorOptions<T> {
|
119 | set: (
|
120 | opts: {
|
121 | set: SetRecoilState;
|
122 | get: GetRecoilValue;
|
123 | reset: ResetRecoilState;
|
124 | },
|
125 | newValue: T | DefaultValue,
|
126 | ) => void;
|
127 | }
|
128 |
|
129 | export function selector<T>(options: ReadWriteSelectorOptions<T>): RecoilState<T>;
|
130 | export function selector<T>(options: ReadOnlySelectorOptions<T>): RecoilValueReadOnly<T>;
|
131 |
|
132 |
|
133 | export type SetterOrUpdater<T> = (valOrUpdater: ((currVal: T) => T) | T) => void;
|
134 | export type Resetter = () => void;
|
135 | export type CallbackInterface = Readonly<{
|
136 | set: <T>(recoilVal: RecoilState<T>, valOrUpdater: ((currVal: T) => T) | T) => void;
|
137 | reset: (recoilVal: RecoilState<any>) => void;
|
138 | snapshot: Snapshot,
|
139 | gotoSnapshot: (snapshot: Snapshot) => void,
|
140 | }>;
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | export function useRecoilValue<T>(recoilValue: RecoilValue<T>): T;
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 | export function useRecoilValueLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 | export function useRecoilState<T>(recoilState: RecoilState<T>): [T, SetterOrUpdater<T>];
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 | export function useRecoilStateLoadable<T>(recoilState: RecoilState<T>): [Loadable<T>, SetterOrUpdater<T>];
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | export function useSetRecoilState<T>(recoilState: RecoilState<T>): SetterOrUpdater<T>;
|
175 |
|
176 |
|
177 |
|
178 |
|
179 | export function useResetRecoilState(recoilState: RecoilState<any>): Resetter;
|
180 |
|
181 |
|
182 |
|
183 |
|
184 | export function useGetRecoilValueInfo_UNSTABLE<T>(recoilValue: RecoilValue<T>): AtomInfo<T>;
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | export function useRecoilCallback<Args extends ReadonlyArray<unknown>, Return>(
|
192 | fn: (interface: CallbackInterface) => (...args: Args) => Return,
|
193 | deps?: ReadonlyArray<unknown>,
|
194 | ): (...args: Args) => Return;
|
195 |
|
196 | export function useRecoilTransactionObserver_UNSTABLE(
|
197 | callback: (opts: {
|
198 | snapshot: Snapshot,
|
199 | previousSnapshot: Snapshot,
|
200 | }) => void,
|
201 | ): void;
|
202 |
|
203 | export function useGotoRecoilSnapshot(): (snapshot: Snapshot) => void;
|
204 |
|
205 | export function useRecoilSnapshot(): Snapshot;
|
206 |
|
207 |
|
208 | export const RecoilBridge: React.FC;
|
209 | export function useRecoilBridgeAcrossReactRoots_UNSTABLE(): typeof RecoilBridge;
|
210 |
|
211 |
|
212 | declare const LoadablePromiseValue_OPAQUE: unique symbol;
|
213 | interface LoadablePromiseValue {
|
214 | readonly [LoadablePromiseValue_OPAQUE]: true;
|
215 | }
|
216 | type LoadablePromise<T> = Promise<LoadablePromiseValue>;
|
217 |
|
218 | interface BaseLoadable<T> {
|
219 | getValue: () => T;
|
220 | toPromise: () => Promise<T>;
|
221 | valueOrThrow: () => T;
|
222 | errorOrThrow: () => any;
|
223 | promiseOrThrow: () => Promise<T>;
|
224 | is: (other: Loadable<any>) => boolean;
|
225 | map: <S>(map: (from: T) => Promise<S> | S) => Loadable<S>;
|
226 | }
|
227 |
|
228 | interface ValueLoadable<T> extends BaseLoadable<T> {
|
229 | state: 'hasValue';
|
230 | contents: T;
|
231 | valueMaybe: () => T;
|
232 | errorMaybe: () => undefined;
|
233 | promiseMaybe: () => undefined;
|
234 | }
|
235 |
|
236 | interface LoadingLoadable<T> extends BaseLoadable<T> {
|
237 | state: 'loading';
|
238 | contents: LoadablePromise<T>;
|
239 | valueMaybe: () => undefined;
|
240 | errorMaybe: () => undefined;
|
241 | promiseMaybe: () => Promise<T>;
|
242 | }
|
243 |
|
244 | interface ErrorLoadable<T> extends BaseLoadable<T> {
|
245 | state: 'hasError';
|
246 | contents: any;
|
247 | valueMaybe: () => undefined;
|
248 | errorMaybe: () => any;
|
249 | promiseMaybe: () => undefined;
|
250 | }
|
251 |
|
252 | export type Loadable<T> =
|
253 | | ValueLoadable<T>
|
254 | | LoadingLoadable<T>
|
255 | | ErrorLoadable<T>;
|
256 |
|
257 |
|
258 | declare class AbstractRecoilValue<T> {
|
259 | __tag: [T];
|
260 | __cTag: (t: T) => void;
|
261 |
|
262 | key: NodeKey;
|
263 | constructor(newKey: NodeKey);
|
264 | }
|
265 |
|
266 | declare class AbstractRecoilValueReadonly<T> {
|
267 | __tag: [T];
|
268 |
|
269 | key: NodeKey;
|
270 | constructor(newKey: NodeKey);
|
271 | }
|
272 |
|
273 | export class RecoilState<T> extends AbstractRecoilValue<T> {}
|
274 | export class RecoilValueReadOnly<T> extends AbstractRecoilValueReadonly<T> {}
|
275 | export type RecoilValue<T> = RecoilValueReadOnly<T> | RecoilState<T>;
|
276 |
|
277 | export function isRecoilValue(val: unknown): val is RecoilValue<any>;
|
278 |
|
279 |
|
280 |
|
281 |
|
282 | type Primitive = undefined | null | boolean | number | symbol | string;
|
283 |
|
284 | export type SerializableParam =
|
285 | | Primitive
|
286 | | {toJSON: () => string}
|
287 | | ReadonlyArray<SerializableParam>
|
288 | | Readonly<{[key: string]: SerializableParam}>;
|
289 |
|
290 | export interface AtomFamilyOptions<T, P extends SerializableParam> {
|
291 | key: NodeKey;
|
292 | dangerouslyAllowMutability?: boolean;
|
293 | default: RecoilValue<T> | Promise<T> | T | ((param: P) => T | RecoilValue<T> | Promise<T>);
|
294 | effects_UNSTABLE?: | ReadonlyArray<AtomEffect<T>> | ((param: P) => ReadonlyArray<AtomEffect<T>>);
|
295 | }
|
296 |
|
297 | export function atomFamily<T, P extends SerializableParam>(
|
298 | options: AtomFamilyOptions<T, P>,
|
299 | ): (param: P) => RecoilState<T>;
|
300 |
|
301 | export interface ReadOnlySelectorFamilyOptions<T, P extends SerializableParam> {
|
302 | key: string;
|
303 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
304 |
|
305 |
|
306 |
|
307 |
|
308 | dangerouslyAllowMutability?: boolean;
|
309 | }
|
310 |
|
311 | export interface ReadWriteSelectorFamilyOptions<T, P extends SerializableParam> {
|
312 | key: string;
|
313 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
314 | set: (
|
315 | param: P,
|
316 | ) => (
|
317 | opts: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState },
|
318 | newValue: T | DefaultValue,
|
319 | ) => void;
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | dangerouslyAllowMutability?: boolean;
|
325 | }
|
326 |
|
327 | export function selectorFamily<T, P extends SerializableParam>(
|
328 | options: ReadWriteSelectorFamilyOptions<T, P>,
|
329 | ): (param: P) => RecoilState<T>;
|
330 |
|
331 | export function selectorFamily<T, P extends SerializableParam>(
|
332 | options: ReadOnlySelectorFamilyOptions<T, P>,
|
333 | ): (param: P) => RecoilValueReadOnly<T>;
|
334 |
|
335 | export function constSelector<T extends SerializableParam>(constant: T): RecoilValueReadOnly<T>;
|
336 |
|
337 | export function errorSelector(message: string): RecoilValueReadOnly<never>;
|
338 |
|
339 | export function readOnlySelector<T>(atom: RecoilValue<T>): RecoilValueReadOnly<T>;
|
340 |
|
341 | export function noWait<T>(state: RecoilValue<T>): RecoilValueReadOnly<Loadable<T>>;
|
342 |
|
343 |
|
344 |
|
345 | export type UnwrapRecoilValue<T> = T extends RecoilValue<infer R> ? R : never;
|
346 |
|
347 | export type UnwrapRecoilValues<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
348 | [P in keyof T]: UnwrapRecoilValue<T[P]>;
|
349 | };
|
350 | export type UnwrapRecoilValueLoadables<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
351 | [P in keyof T]: Loadable<UnwrapRecoilValue<T[P]>>;
|
352 | };
|
353 |
|
354 | export function waitForNone<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
355 | param: RecoilValues,
|
356 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
357 |
|
358 | export function waitForNone<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
359 | param: RecoilValues,
|
360 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
361 |
|
362 | export function waitForAny<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
363 | param: RecoilValues,
|
364 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
365 |
|
366 | export function waitForAny<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
367 | param: RecoilValues,
|
368 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
369 |
|
370 | export function waitForAll<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
371 | param: RecoilValues,
|
372 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
373 |
|
374 | export function waitForAll<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
375 | param: RecoilValues,
|
376 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
377 |
|
378 | export function waitForAllSettled<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
379 | param: RecoilValues,
|
380 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
381 |
|
382 | export function waitForAllSettled<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
383 | param: RecoilValues,
|
384 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
385 |
|
386 |
|
387 |
|
388 | export function snapshot_UNSTABLE(initializeState?: (shapshot: MutableSnapshot) => void): Snapshot;
|