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