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