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 | export class Snapshot {
|
97 | getID(): SnapshotID;
|
98 | getLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
99 | getPromise<T>(recoilValue: RecoilValue<T>): Promise<T>;
|
100 | getNodes_UNSTABLE(opts?: { isModified?: boolean }): Iterable<RecoilValue<unknown>>;
|
101 | getInfo_UNSTABLE<T>(recoilValue: RecoilValue<T>): {
|
102 | loadable?: Loadable<T>,
|
103 | isActive: boolean,
|
104 | isSet: boolean,
|
105 | isModified: boolean,
|
106 | type: 'atom' | 'selector' | undefined,
|
107 | deps: Iterable<RecoilValue<T>>,
|
108 | subscribers: {
|
109 | nodes: Iterable<RecoilValue<T>>,
|
110 | },
|
111 | };
|
112 | map(cb: (mutableSnapshot: MutableSnapshot) => void): Snapshot;
|
113 | asyncMap(cb: (mutableSnapshot: MutableSnapshot) => Promise<void>): Promise<Snapshot>;
|
114 | }
|
115 |
|
116 | export class MutableSnapshot extends Snapshot {
|
117 | set: SetRecoilState;
|
118 | reset: ResetRecoilState;
|
119 | }
|
120 |
|
121 |
|
122 | export type SetterOrUpdater<T> = (valOrUpdater: ((currVal: T) => T) | T) => void;
|
123 | export type Resetter = () => void;
|
124 | export type CallbackInterface = Readonly<{
|
125 | set: <T>(recoilVal: RecoilState<T>, valOrUpdater: ((currVal: T) => T) | T) => void;
|
126 | reset: (recoilVal: RecoilState<any>) => void;
|
127 | snapshot: Snapshot,
|
128 | gotoSnapshot: (snapshot: Snapshot) => void,
|
129 | }>;
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | export function useRecoilValue<T>(recoilValue: RecoilValue<T>): T;
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | export function useRecoilValueLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | export function useRecoilState<T>(recoilState: RecoilState<T>): [T, SetterOrUpdater<T>];
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | export function useRecoilStateLoadable<T>(recoilState: RecoilState<T>): [Loadable<T>, SetterOrUpdater<T>];
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | export function useSetRecoilState<T>(recoilState: RecoilState<T>): SetterOrUpdater<T>;
|
164 |
|
165 |
|
166 |
|
167 |
|
168 | export function useResetRecoilState(recoilState: RecoilState<any>): Resetter;
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | export function useRecoilCallback<Args extends ReadonlyArray<unknown>, Return>(
|
176 | fn: (interface: CallbackInterface) => (...args: Args) => Return,
|
177 | deps?: ReadonlyArray<unknown>,
|
178 | ): (...args: Args) => Return;
|
179 |
|
180 | export function useRecoilTransactionObserver_UNSTABLE(
|
181 | callback: (opts: {
|
182 | snapshot: Snapshot,
|
183 | previousSnapshot: Snapshot,
|
184 | }) => void,
|
185 | ): void;
|
186 |
|
187 | export function useGotoRecoilSnapshot(): (snapshot: Snapshot) => void;
|
188 |
|
189 | export function useRecoilSnapshot(): Snapshot;
|
190 |
|
191 |
|
192 | export const RecoilBridge: React.FC;
|
193 | export function useRecoilBridgeAcrossReactRoots_UNSTABLE(): typeof RecoilBridge;
|
194 |
|
195 |
|
196 | type ResolvedLoadablePromiseInfo<T> = Readonly<{
|
197 | value: T;
|
198 | }>;
|
199 |
|
200 | export type LoadablePromise<T> = Promise<ResolvedLoadablePromiseInfo<T>>;
|
201 |
|
202 | interface BaseLoadable<T> {
|
203 | getValue: () => T;
|
204 | toPromise: () => Promise<T>;
|
205 | valueMaybe: () => T | void;
|
206 | valueOrThrow: () => T;
|
207 | errorMaybe: () => Error | void;
|
208 | errorOrThrow: () => Error;
|
209 | promiseMaybe: () => Promise<T> | void;
|
210 | promiseOrThrow: () => Promise<T>;
|
211 | map: <S>(map: (from: T) => Promise<S> | S) => Loadable<S>;
|
212 | }
|
213 |
|
214 | interface ValueLoadable<T> extends BaseLoadable<T> {
|
215 | state: 'hasValue';
|
216 | contents: T;
|
217 | }
|
218 |
|
219 | interface LoadingLoadable<T> extends BaseLoadable<T> {
|
220 | state: 'loading';
|
221 | contents: LoadablePromise<T>;
|
222 | }
|
223 |
|
224 | interface ErrorLoadable<T> extends BaseLoadable<T> {
|
225 | state: 'error';
|
226 | contents: Error;
|
227 | }
|
228 |
|
229 | type Loadable<T> =
|
230 | | ValueLoadable<T>
|
231 | | LoadingLoadable<T>
|
232 | | ErrorLoadable<T>;
|
233 |
|
234 |
|
235 | declare class AbstractRecoilValue<T> {
|
236 | __tag: [T];
|
237 | __cTag: (t: T) => void;
|
238 |
|
239 | key: NodeKey;
|
240 | constructor(newKey: NodeKey);
|
241 | }
|
242 |
|
243 | declare class AbstractRecoilValueReadonly<T> {
|
244 | __tag: [T];
|
245 |
|
246 | key: NodeKey;
|
247 | constructor(newKey: NodeKey);
|
248 | }
|
249 |
|
250 | export class RecoilState<T> extends AbstractRecoilValue<T> {}
|
251 | export class RecoilValueReadOnly<T> extends AbstractRecoilValueReadonly<T> {}
|
252 | export type RecoilValue<T> = RecoilValueReadOnly<T> | RecoilState<T>;
|
253 |
|
254 | export function isRecoilValue(val: unknown): val is RecoilValue<any>;
|
255 |
|
256 |
|
257 |
|
258 |
|
259 | type Primitive = undefined | null | boolean | number | symbol | string;
|
260 |
|
261 | export type SerializableParam = Primitive | ReadonlyArray<SerializableParam> | Readonly<{[key: string]: SerializableParam}>;
|
262 |
|
263 | export interface AtomFamilyOptions<T, P extends SerializableParam> {
|
264 | key: NodeKey;
|
265 | dangerouslyAllowMutability?: boolean;
|
266 | default: RecoilValue<T> | Promise<T> | T | ((param: P) => T | RecoilValue<T> | Promise<T>);
|
267 | effects_UNSTABLE?: | ReadonlyArray<AtomEffect<T>> | ((param: P) => ReadonlyArray<AtomEffect<T>>);
|
268 | }
|
269 |
|
270 | export function atomFamily<T, P extends SerializableParam>(
|
271 | options: AtomFamilyOptions<T, P>,
|
272 | ): (param: P) => RecoilState<T>;
|
273 |
|
274 | export interface ReadOnlySelectorFamilyOptions<T, P extends SerializableParam> {
|
275 | key: string;
|
276 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | dangerouslyAllowMutability?: boolean;
|
282 | }
|
283 |
|
284 | export interface ReadWriteSelectorFamilyOptions<T, P extends SerializableParam> {
|
285 | key: string;
|
286 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
287 | set: (
|
288 | param: P,
|
289 | ) => (
|
290 | opts: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState },
|
291 | newValue: T | DefaultValue,
|
292 | ) => void;
|
293 |
|
294 |
|
295 |
|
296 |
|
297 | dangerouslyAllowMutability?: boolean;
|
298 | }
|
299 |
|
300 | export function selectorFamily<T, P extends SerializableParam>(
|
301 | options: ReadWriteSelectorFamilyOptions<T, P>,
|
302 | ): (param: P) => RecoilState<T>;
|
303 |
|
304 | export function selectorFamily<T, P extends SerializableParam>(
|
305 | options: ReadOnlySelectorFamilyOptions<T, P>,
|
306 | ): (param: P) => RecoilValueReadOnly<T>;
|
307 |
|
308 | export function constSelector<T extends SerializableParam>(constant: T): RecoilValueReadOnly<T>;
|
309 |
|
310 | export function errorSelector(message: string): RecoilValueReadOnly<never>;
|
311 |
|
312 | export function readOnlySelector<T>(atom: RecoilValue<T>): RecoilValueReadOnly<T>;
|
313 |
|
314 | export function noWait<T>(state: RecoilValue<T>): RecoilValueReadOnly<Loadable<T>>;
|
315 |
|
316 |
|
317 |
|
318 | export type UnwrapRecoilValue<T> = T extends RecoilValue<infer R> ? R : never;
|
319 |
|
320 | export type UnwrapRecoilValues<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
321 | [P in keyof T]: UnwrapRecoilValue<T[P]>;
|
322 | };
|
323 | export type UnwrapRecoilValueLoadables<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
324 | [P in keyof T]: Loadable<UnwrapRecoilValue<T[P]>>;
|
325 | };
|
326 |
|
327 | export function waitForNone<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
328 | param: RecoilValues,
|
329 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
330 |
|
331 | export function waitForNone<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
332 | param: RecoilValues,
|
333 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
334 |
|
335 | export function waitForAny<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
336 | param: RecoilValues,
|
337 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
338 |
|
339 | export function waitForAny<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
340 | param: RecoilValues,
|
341 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
342 |
|
343 | export function waitForAll<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
344 | param: RecoilValues,
|
345 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
346 |
|
347 | export function waitForAll<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
348 | param: RecoilValues,
|
349 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
350 |
|
351 |
|
352 |
|
353 | export function snapshot_UNSTABLE(initializeState?: (shapshot: MutableSnapshot) => void): Snapshot;
|