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 interface AtomOptions<T> {
|
28 | key: NodeKey;
|
29 | default: RecoilValue<T> | Promise<T> | T;
|
30 | dangerouslyAllowMutability?: boolean;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 | export function atom<T>(options: AtomOptions<T>): RecoilState<T>;
|
36 |
|
37 |
|
38 | export type GetRecoilValue = <T>(recoilVal: RecoilValue<T>) => T;
|
39 |
|
40 | export type SetRecoilState = <T>(
|
41 | recoilVal: RecoilState<T>,
|
42 | newVal: T | DefaultValue | ((prevValue: T) => T | DefaultValue),
|
43 | ) => void;
|
44 |
|
45 | export type ResetRecoilState = (recoilVal: RecoilState<any>) => void;
|
46 |
|
47 | export interface ReadOnlySelectorOptions<T> {
|
48 | key: string;
|
49 | get: (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
50 | dangerouslyAllowMutability?: boolean;
|
51 | }
|
52 |
|
53 | export interface ReadWriteSelectorOptions<T> extends ReadOnlySelectorOptions<T> {
|
54 | set: (
|
55 | opts: {
|
56 | set: SetRecoilState;
|
57 | get: GetRecoilValue;
|
58 | reset: ResetRecoilState;
|
59 | },
|
60 | newValue: T | DefaultValue,
|
61 | ) => void;
|
62 | }
|
63 |
|
64 | export function selector<T>(options: ReadWriteSelectorOptions<T>): RecoilState<T>;
|
65 | export function selector<T>(options: ReadOnlySelectorOptions<T>): RecoilValueReadOnly<T>;
|
66 |
|
67 |
|
68 | declare const SnapshotID_OPAQUE: unique symbol;
|
69 | export interface SnapshotID {
|
70 | readonly [SnapshotID_OPAQUE]: true;
|
71 | }
|
72 |
|
73 | export class Snapshot {
|
74 | getID(): SnapshotID;
|
75 | getLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
76 | getPromise<T>(recoilValue: RecoilValue<T>): Promise<T>;
|
77 | map(cb: (mutableSnapshot: MutableSnapshot) => void): Snapshot;
|
78 | asyncMap(cb: (mutableSnapshot: MutableSnapshot) => Promise<void>): Promise<Snapshot>;
|
79 | }
|
80 |
|
81 | export class MutableSnapshot extends Snapshot {
|
82 | set: SetRecoilState;
|
83 | reset: ResetRecoilState;
|
84 | }
|
85 |
|
86 |
|
87 | export type SetterOrUpdater<T> = (valOrUpdater: ((currVal: T) => T) | T) => void;
|
88 | export type Resetter = () => void;
|
89 | export type CallbackInterface = Readonly<{
|
90 | set: <T>(recoilVal: RecoilState<T>, valOrUpdater: ((currVal: T) => T) | T) => void;
|
91 | reset: (recoilVal: RecoilState<any>) => void;
|
92 | snapshot: Snapshot,
|
93 | gotoSnapshot: (snapshot: Snapshot) => void,
|
94 | }>;
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | export function useRecoilValue<T>(recoilValue: RecoilValue<T>): T;
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 | export function useRecoilValueLoadable<T>(recoilValue: RecoilValue<T>): Loadable<T>;
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | export function useRecoilState<T>(recoilState: RecoilState<T>): [T, SetterOrUpdater<T>];
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | export function useRecoilStateLoadable<T>(recoilState: RecoilState<T>): [Loadable<T>, SetterOrUpdater<T>];
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export function useSetRecoilState<T>(recoilState: RecoilState<T>): SetterOrUpdater<T>;
|
129 |
|
130 |
|
131 |
|
132 |
|
133 | export function useResetRecoilState(recoilState: RecoilState<any>): Resetter;
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | export function useRecoilCallback<Args extends ReadonlyArray<unknown>, Return>(
|
141 | fn: (interface: CallbackInterface) => (...args: Args) => Return,
|
142 | deps?: ReadonlyArray<unknown>,
|
143 | ): (...args: Args) => Return;
|
144 |
|
145 | export function useRecoilTransactionObserver_UNSTABLE(
|
146 | callback: (opts: {
|
147 | snapshot: Snapshot,
|
148 | previousSnapshot: Snapshot,
|
149 | }) => void,
|
150 | ): void;
|
151 |
|
152 | export function useGotoRecoilSnapshot(): (snapshot: Snapshot) => void;
|
153 |
|
154 | export function useRecoilSnapshot(): Snapshot;
|
155 |
|
156 |
|
157 | export const RecoilBridge: React.FC;
|
158 | export function useRecoilBridgeAcrossReactRoots_UNSTABLE(): typeof RecoilBridge;
|
159 |
|
160 |
|
161 | type ResolvedLoadablePromiseInfo<T> = Readonly<{
|
162 | value: T;
|
163 | }>;
|
164 |
|
165 | export type LoadablePromise<T> = Promise<ResolvedLoadablePromiseInfo<T>>;
|
166 |
|
167 | export type Loadable<T> =
|
168 | | Readonly<{
|
169 | state: 'hasValue';
|
170 | contents: T;
|
171 | }>
|
172 | | Readonly<{
|
173 | state: 'hasError';
|
174 | contents: Error;
|
175 | }>
|
176 | | Readonly<{
|
177 | state: 'loading';
|
178 | contents: LoadablePromise<T>;
|
179 | }>;
|
180 |
|
181 |
|
182 | declare class AbstractRecoilValue<T> {
|
183 | __tag: [T];
|
184 | __cTag: (t: T) => void;
|
185 |
|
186 | key: NodeKey;
|
187 | constructor(newKey: NodeKey);
|
188 | }
|
189 |
|
190 | declare class AbstractRecoilValueReadonly<T> {
|
191 | __tag: [T];
|
192 |
|
193 | key: NodeKey;
|
194 | constructor(newKey: NodeKey);
|
195 | }
|
196 |
|
197 | export class RecoilState<T> extends AbstractRecoilValue<T> {}
|
198 | export class RecoilValueReadOnly<T> extends AbstractRecoilValueReadonly<T> {}
|
199 | export type RecoilValue<T> = RecoilValueReadOnly<T> | RecoilState<T>;
|
200 |
|
201 | export function isRecoilValue(val: unknown): val is RecoilValue<any>;
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | type Primitive = undefined | null | boolean | number | symbol | string;
|
207 |
|
208 | export type SerializableParam = Primitive | ReadonlyArray<SerializableParam> | Readonly<{[key: string]: SerializableParam}>;
|
209 |
|
210 | export interface AtomFamilyOptions<T, P extends SerializableParam> {
|
211 | key: NodeKey;
|
212 | dangerouslyAllowMutability?: boolean;
|
213 | default: RecoilValue<T> | Promise<T> | T | ((param: P) => T | RecoilValue<T> | Promise<T>);
|
214 | }
|
215 |
|
216 | export function atomFamily<T, P extends SerializableParam>(
|
217 | options: AtomFamilyOptions<T, P>,
|
218 | ): (param: P) => RecoilState<T>;
|
219 |
|
220 | export interface ReadOnlySelectorFamilyOptions<T, P extends SerializableParam> {
|
221 | key: string;
|
222 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | dangerouslyAllowMutability?: boolean;
|
228 | }
|
229 |
|
230 | export interface ReadWriteSelectorFamilyOptions<T, P extends SerializableParam> {
|
231 | key: string;
|
232 | get: (param: P) => (opts: { get: GetRecoilValue }) => Promise<T> | RecoilValue<T> | T;
|
233 | set: (
|
234 | param: P,
|
235 | ) => (
|
236 | opts: { set: SetRecoilState; get: GetRecoilValue; reset: ResetRecoilState },
|
237 | newValue: T | DefaultValue,
|
238 | ) => void;
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | dangerouslyAllowMutability?: boolean;
|
244 | }
|
245 |
|
246 | export function selectorFamily<T, P extends SerializableParam>(
|
247 | options: ReadWriteSelectorFamilyOptions<T, P>,
|
248 | ): (param: P) => RecoilState<T>;
|
249 |
|
250 | export function selectorFamily<T, P extends SerializableParam>(
|
251 | options: ReadOnlySelectorFamilyOptions<T, P>,
|
252 | ): (param: P) => RecoilValueReadOnly<T>;
|
253 |
|
254 | export function constSelector<T extends SerializableParam>(constant: T): RecoilValueReadOnly<T>;
|
255 |
|
256 | export function errorSelector(message: string): RecoilValueReadOnly<never>;
|
257 |
|
258 | export function readOnlySelector<T>(atom: RecoilValue<T>): RecoilValueReadOnly<T>;
|
259 |
|
260 | export function noWait<T>(state: RecoilValue<T>): RecoilValueReadOnly<Loadable<T>>;
|
261 |
|
262 |
|
263 |
|
264 | export type UnwrapRecoilValue<T> = T extends RecoilValue<infer R> ? R : never;
|
265 |
|
266 | export type UnwrapRecoilValues<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
267 | [P in keyof T]: UnwrapRecoilValue<T[P]>;
|
268 | };
|
269 | export type UnwrapRecoilValueLoadables<T extends Array<RecoilValue<any>> | { [key: string]: RecoilValue<any> }> = {
|
270 | [P in keyof T]: Loadable<UnwrapRecoilValue<T[P]>>;
|
271 | };
|
272 |
|
273 | export function waitForNone<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
274 | param: RecoilValues,
|
275 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
276 |
|
277 | export function waitForNone<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
278 | param: RecoilValues,
|
279 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
280 |
|
281 | export function waitForAny<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
282 | param: RecoilValues,
|
283 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
284 |
|
285 | export function waitForAny<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
286 | param: RecoilValues,
|
287 | ): RecoilValueReadOnly<UnwrapRecoilValueLoadables<RecoilValues>>;
|
288 |
|
289 | export function waitForAll<RecoilValues extends Array<RecoilValue<any>> | [RecoilValue<any>]>(
|
290 | param: RecoilValues,
|
291 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
292 |
|
293 | export function waitForAll<RecoilValues extends { [key: string]: RecoilValue<any> }>(
|
294 | param: RecoilValues,
|
295 | ): RecoilValueReadOnly<UnwrapRecoilValues<RecoilValues>>;
|
296 |
|
297 |
|