1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var reactDom = _interopDefault(require('react-dom'));
|
8 | var react = _interopDefault(require('react'));
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const gks = new Map();
|
22 |
|
23 | function Recoil_gkx(gk) {
|
24 | var _gks$get;
|
25 |
|
26 | return (_gks$get = gks.get(gk)) !== null && _gks$get !== void 0 ? _gks$get : false;
|
27 | }
|
28 |
|
29 | Recoil_gkx.setPass = gk => {
|
30 | gks.set(gk, true);
|
31 | };
|
32 |
|
33 | Recoil_gkx.setFail = gk => {
|
34 | gks.set(gk, false);
|
35 | };
|
36 |
|
37 | var Recoil_gkx_1 = Recoil_gkx;
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 | function mapMap(map, callback) {
|
55 | const result = new Map();
|
56 | map.forEach((value, key) => {
|
57 | result.set(key, callback(value, key));
|
58 | });
|
59 | return result;
|
60 | }
|
61 |
|
62 | var Recoil_mapMap = mapMap;
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | function nullthrows(x, message) {
|
76 | if (x != null) {
|
77 | return x;
|
78 | }
|
79 |
|
80 | throw new Error(message !== null && message !== void 0 ? message : 'Got unexpected null or undefined');
|
81 | }
|
82 |
|
83 | var Recoil_nullthrows = nullthrows;
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | function recoverableViolation(message, projectName, {
|
97 | error
|
98 | } = {}) {
|
99 | if (process.env.NODE_ENV !== "production") {
|
100 | console.error(message, error);
|
101 | }
|
102 |
|
103 | return null;
|
104 | }
|
105 |
|
106 | var recoverableViolation_1 = recoverableViolation;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | var Recoil_recoverableViolation = recoverableViolation_1;
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | function trace(message, node, fn) {
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 | return fn();
|
158 | }
|
159 |
|
160 | function wrap(fn) {
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 | return fn;
|
172 | }
|
173 |
|
174 | var Recoil_Tracing = {
|
175 | trace,
|
176 | wrap
|
177 | };
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | function setByAddingToSet(set, v) {
|
193 | const next = new Set(set);
|
194 | next.add(v);
|
195 | return next;
|
196 | }
|
197 |
|
198 | function setByDeletingFromSet(set, v) {
|
199 | const next = new Set(set);
|
200 | next.delete(v);
|
201 | return next;
|
202 | }
|
203 |
|
204 | function mapBySettingInMap(map, k, v) {
|
205 | const next = new Map(map);
|
206 | next.set(k, v);
|
207 | return next;
|
208 | }
|
209 |
|
210 | function mapByUpdatingInMap(map, k, updater) {
|
211 | const next = new Map(map);
|
212 | next.set(k, updater(next.get(k)));
|
213 | return next;
|
214 | }
|
215 |
|
216 | function mapByDeletingFromMap(map, k) {
|
217 | const next = new Map(map);
|
218 | next.delete(k);
|
219 | return next;
|
220 | }
|
221 |
|
222 | function mapByDeletingMultipleFromMap(map, ks) {
|
223 | const next = new Map(map);
|
224 | ks.forEach(k => next.delete(k));
|
225 | return next;
|
226 | }
|
227 |
|
228 | var Recoil_CopyOnWrite = {
|
229 | setByAddingToSet,
|
230 | setByDeletingFromSet,
|
231 | mapBySettingInMap,
|
232 | mapByUpdatingInMap,
|
233 | mapByDeletingFromMap,
|
234 | mapByDeletingMultipleFromMap
|
235 | };
|
236 |
|
237 |
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | function sprintf(format, ...args) {
|
249 | let index = 0;
|
250 | return format.replace(/%s/g, () => String(args[index++]));
|
251 | }
|
252 |
|
253 | var sprintf_1 = sprintf;
|
254 |
|
255 | function expectationViolation(format, ...args) {
|
256 | if (process.env.NODE_ENV !== "production") {
|
257 | const message = sprintf_1.call(null, format, ...args);
|
258 | const error = new Error(message);
|
259 | error.name = 'Expectation Violation';
|
260 | console.error(error);
|
261 | }
|
262 | }
|
263 |
|
264 | var expectationViolation_1 = expectationViolation;
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | var Recoil_expectationViolation = expectationViolation_1;
|
270 |
|
271 | function _defineProperty(obj, key, value) {
|
272 | if (key in obj) {
|
273 | Object.defineProperty(obj, key, {
|
274 | value: value,
|
275 | enumerable: true,
|
276 | configurable: true,
|
277 | writable: true
|
278 | });
|
279 | } else {
|
280 | obj[key] = value;
|
281 | }
|
282 |
|
283 | return obj;
|
284 | }
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 | class AbstractRecoilValue {
|
299 | constructor(newKey) {
|
300 | _defineProperty(this, "key", void 0);
|
301 |
|
302 | this.key = newKey;
|
303 | }
|
304 |
|
305 | }
|
306 |
|
307 | class RecoilState extends AbstractRecoilValue {}
|
308 |
|
309 | class RecoilValueReadOnly extends AbstractRecoilValue {}
|
310 |
|
311 | function isRecoilValue(x) {
|
312 | return x instanceof RecoilState || x instanceof RecoilValueReadOnly;
|
313 | }
|
314 |
|
315 | var Recoil_RecoilValue = {
|
316 | AbstractRecoilValue,
|
317 | RecoilState,
|
318 | RecoilValueReadOnly,
|
319 | isRecoilValue
|
320 | };
|
321 |
|
322 | var Recoil_RecoilValue_1 = Recoil_RecoilValue.AbstractRecoilValue;
|
323 | var Recoil_RecoilValue_2 = Recoil_RecoilValue.RecoilState;
|
324 | var Recoil_RecoilValue_3 = Recoil_RecoilValue.RecoilValueReadOnly;
|
325 | var Recoil_RecoilValue_4 = Recoil_RecoilValue.isRecoilValue;
|
326 |
|
327 | var Recoil_RecoilValue$1 = Object.freeze({
|
328 | __proto__: null,
|
329 | AbstractRecoilValue: Recoil_RecoilValue_1,
|
330 | RecoilState: Recoil_RecoilValue_2,
|
331 | RecoilValueReadOnly: Recoil_RecoilValue_3,
|
332 | isRecoilValue: Recoil_RecoilValue_4
|
333 | });
|
334 |
|
335 | class DefaultValue {}
|
336 |
|
337 | const DEFAULT_VALUE = new DefaultValue();
|
338 |
|
339 | class RecoilValueNotReady extends Error {
|
340 | constructor(key) {
|
341 | super(`Tried to set the value of Recoil selector ${key} using an updater function, but it is an async selector in a pending or error state; this is not supported.`);
|
342 | }
|
343 |
|
344 | }
|
345 |
|
346 |
|
347 | const nodes = new Map();
|
348 |
|
349 | const recoilValues = new Map();
|
350 |
|
351 |
|
352 | function registerNode(node) {
|
353 | if (nodes.has(node.key)) {
|
354 | const message = `Duplicate atom key "${node.key}". This is a FATAL ERROR in
|
355 | production. But it is safe to ignore this warning if it occurred because of
|
356 | hot module replacement.`;
|
357 |
|
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |
|
367 |
|
368 |
|
369 | console.warn(message);
|
370 | }
|
371 |
|
372 | nodes.set(node.key, node);
|
373 | const recoilValue = node.set == null ? new Recoil_RecoilValue$1.RecoilValueReadOnly(node.key) : new Recoil_RecoilValue$1.RecoilState(node.key);
|
374 | recoilValues.set(node.key, recoilValue);
|
375 | return recoilValue;
|
376 | }
|
377 |
|
378 |
|
379 |
|
380 | class NodeMissingError extends Error {}
|
381 |
|
382 |
|
383 | function getNode(key) {
|
384 | const node = nodes.get(key);
|
385 |
|
386 | if (node == null) {
|
387 | throw new NodeMissingError(`Missing definition for RecoilValue: "${key}""`);
|
388 | }
|
389 |
|
390 | return node;
|
391 | }
|
392 |
|
393 |
|
394 | function getNodeMaybe(key) {
|
395 | return nodes.get(key);
|
396 | }
|
397 |
|
398 | var Recoil_Node = {
|
399 | nodes,
|
400 | recoilValues,
|
401 | registerNode,
|
402 | getNode,
|
403 | getNodeMaybe,
|
404 | NodeMissingError,
|
405 | DefaultValue,
|
406 | DEFAULT_VALUE,
|
407 | RecoilValueNotReady
|
408 | };
|
409 |
|
410 | const {
|
411 | mapByDeletingFromMap: mapByDeletingFromMap$1,
|
412 | mapBySettingInMap: mapBySettingInMap$1,
|
413 | setByAddingToSet: setByAddingToSet$1
|
414 | } = Recoil_CopyOnWrite;
|
415 |
|
416 | const {
|
417 | getNode: getNode$1,
|
418 | getNodeMaybe: getNodeMaybe$1
|
419 | } = Recoil_Node;
|
420 |
|
421 |
|
422 | const emptySet = Object.freeze(new Set());
|
423 |
|
424 | class ReadOnlyRecoilValueError extends Error {}
|
425 |
|
426 |
|
427 |
|
428 |
|
429 | function getNodeLoadable(store, state, key) {
|
430 | return getNode$1(key).get(store, state);
|
431 | }
|
432 |
|
433 |
|
434 | function peekNodeLoadable(store, state, key) {
|
435 | return getNode$1(key).peek(store, state);
|
436 | }
|
437 |
|
438 |
|
439 |
|
440 | function setUnvalidatedAtomValue_DEPRECATED(state, key, newValue) {
|
441 | var _node$invalidate;
|
442 |
|
443 | const node = getNodeMaybe$1(key);
|
444 | node === null || node === void 0 ? void 0 : (_node$invalidate = node.invalidate) === null || _node$invalidate === void 0 ? void 0 : _node$invalidate.call(node, state);
|
445 | return { ...state,
|
446 | atomValues: mapByDeletingFromMap$1(state.atomValues, key),
|
447 | nonvalidatedAtoms: mapBySettingInMap$1(state.nonvalidatedAtoms, key, newValue),
|
448 | dirtyAtoms: setByAddingToSet$1(state.dirtyAtoms, key)
|
449 | };
|
450 | }
|
451 |
|
452 |
|
453 |
|
454 |
|
455 | function setNodeValue(store, state, key, newValue) {
|
456 | const node = getNode$1(key);
|
457 |
|
458 | if (node.set == null) {
|
459 | throw new ReadOnlyRecoilValueError(`Attempt to set read-only RecoilValue: ${key}`);
|
460 | }
|
461 |
|
462 | return node.set(store, state, newValue);
|
463 | }
|
464 |
|
465 | function cleanUpNode(store, key) {
|
466 | const node = getNode$1(key);
|
467 | node.cleanUp(store);
|
468 | }
|
469 |
|
470 |
|
471 | function getDownstreamNodes(store, state, keys) {
|
472 | const visitedNodes = new Set();
|
473 | const visitingNodes = Array.from(keys);
|
474 | const graph = store.getGraph(state.version);
|
475 |
|
476 | for (let key = visitingNodes.pop(); key; key = visitingNodes.pop()) {
|
477 | var _graph$nodeToNodeSubs;
|
478 |
|
479 | visitedNodes.add(key);
|
480 | const subscribedNodes = (_graph$nodeToNodeSubs = graph.nodeToNodeSubscriptions.get(key)) !== null && _graph$nodeToNodeSubs !== void 0 ? _graph$nodeToNodeSubs : emptySet;
|
481 |
|
482 | for (const downstreamNode of subscribedNodes) {
|
483 | if (!visitedNodes.has(downstreamNode)) {
|
484 | visitingNodes.push(downstreamNode);
|
485 | }
|
486 | }
|
487 | }
|
488 |
|
489 | return visitedNodes;
|
490 | }
|
491 |
|
492 | var Recoil_FunctionalCore = {
|
493 | getNodeLoadable,
|
494 | peekNodeLoadable,
|
495 | setNodeValue,
|
496 | cleanUpNode,
|
497 | setUnvalidatedAtomValue_DEPRECATED,
|
498 | getDownstreamNodes
|
499 | };
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 |
|
516 |
|
517 |
|
518 |
|
519 | function differenceSets(set, ...setsWithValuesToRemove) {
|
520 | const ret = new Set();
|
521 |
|
522 | FIRST: for (const value of set) {
|
523 | for (const otherSet of setsWithValuesToRemove) {
|
524 | if (otherSet.has(value)) {
|
525 | continue FIRST;
|
526 | }
|
527 | }
|
528 |
|
529 | ret.add(value);
|
530 | }
|
531 |
|
532 | return ret;
|
533 | }
|
534 |
|
535 | var Recoil_differenceSets = differenceSets;
|
536 |
|
537 | function graph() {
|
538 | return {
|
539 | nodeDeps: new Map(),
|
540 | nodeToNodeSubscriptions: new Map()
|
541 | };
|
542 | }
|
543 |
|
544 | function cloneGraph(graph) {
|
545 | return {
|
546 | nodeDeps: Recoil_mapMap(graph.nodeDeps, s => new Set(s)),
|
547 | nodeToNodeSubscriptions: Recoil_mapMap(graph.nodeToNodeSubscriptions, s => new Set(s))
|
548 | };
|
549 | }
|
550 |
|
551 |
|
552 |
|
553 | function mergeDependencyMapIntoGraph(deps, graph, // If olderGraph is given then we will not overwrite changes made to the given
|
554 | // graph compared with olderGraph:
|
555 | olderGraph) {
|
556 | const {
|
557 | nodeDeps,
|
558 | nodeToNodeSubscriptions
|
559 | } = graph;
|
560 | deps.forEach((upstreams, downstream) => {
|
561 | const existingUpstreams = nodeDeps.get(downstream);
|
562 |
|
563 | if (existingUpstreams && olderGraph && existingUpstreams !== olderGraph.nodeDeps.get(downstream)) {
|
564 | return;
|
565 | }
|
566 |
|
567 |
|
568 | nodeDeps.set(downstream, new Set(upstreams));
|
569 |
|
570 | const addedUpstreams = existingUpstreams == null ? upstreams : Recoil_differenceSets(upstreams, existingUpstreams);
|
571 | addedUpstreams.forEach(upstream => {
|
572 | if (!nodeToNodeSubscriptions.has(upstream)) {
|
573 | nodeToNodeSubscriptions.set(upstream, new Set());
|
574 | }
|
575 |
|
576 | const existing = Recoil_nullthrows(nodeToNodeSubscriptions.get(upstream));
|
577 | existing.add(downstream);
|
578 | });
|
579 |
|
580 | if (existingUpstreams) {
|
581 | const removedUpstreams = Recoil_differenceSets(existingUpstreams, upstreams);
|
582 | removedUpstreams.forEach(upstream => {
|
583 | if (!nodeToNodeSubscriptions.has(upstream)) {
|
584 | return;
|
585 | }
|
586 |
|
587 | const existing = Recoil_nullthrows(nodeToNodeSubscriptions.get(upstream));
|
588 | existing.delete(downstream);
|
589 |
|
590 | if (existing.size === 0) {
|
591 | nodeToNodeSubscriptions.delete(upstream);
|
592 | }
|
593 | });
|
594 | }
|
595 | });
|
596 | }
|
597 |
|
598 | function saveDependencyMapToStore(dependencyMap, store, version) {
|
599 | var _storeState$nextTree, _storeState$previousT, _storeState$previousT2, _storeState$previousT3;
|
600 |
|
601 | const storeState = store.getState();
|
602 |
|
603 | if (!(version === storeState.currentTree.version || version === ((_storeState$nextTree = storeState.nextTree) === null || _storeState$nextTree === void 0 ? void 0 : _storeState$nextTree.version) || version === ((_storeState$previousT = storeState.previousTree) === null || _storeState$previousT === void 0 ? void 0 : _storeState$previousT.version))) {
|
604 | Recoil_recoverableViolation('Tried to save dependencies to a discarded tree');
|
605 | }
|
606 |
|
607 |
|
608 |
|
609 | const graph = store.getGraph(version);
|
610 | mergeDependencyMapIntoGraph(dependencyMap, graph);
|
611 |
|
612 |
|
613 | if (version === ((_storeState$previousT2 = storeState.previousTree) === null || _storeState$previousT2 === void 0 ? void 0 : _storeState$previousT2.version)) {
|
614 | const currentGraph = store.getGraph(storeState.currentTree.version);
|
615 | mergeDependencyMapIntoGraph(dependencyMap, currentGraph, graph);
|
616 | }
|
617 |
|
618 | if (version === ((_storeState$previousT3 = storeState.previousTree) === null || _storeState$previousT3 === void 0 ? void 0 : _storeState$previousT3.version) || version === storeState.currentTree.version) {
|
619 | var _storeState$nextTree2;
|
620 |
|
621 | const nextVersion = (_storeState$nextTree2 = storeState.nextTree) === null || _storeState$nextTree2 === void 0 ? void 0 : _storeState$nextTree2.version;
|
622 |
|
623 | if (nextVersion !== undefined) {
|
624 | const nextGraph = store.getGraph(nextVersion);
|
625 | mergeDependencyMapIntoGraph(dependencyMap, nextGraph, graph);
|
626 | }
|
627 | }
|
628 | }
|
629 |
|
630 | function mergeDepsIntoDependencyMap(from, into) {
|
631 | from.forEach((upstreamDeps, downstreamNode) => {
|
632 | if (!into.has(downstreamNode)) {
|
633 | into.set(downstreamNode, new Set());
|
634 | }
|
635 |
|
636 | const deps = Recoil_nullthrows(into.get(downstreamNode));
|
637 | upstreamDeps.forEach(dep => deps.add(dep));
|
638 | });
|
639 | }
|
640 |
|
641 | function addToDependencyMap(downstream, upstream, dependencyMap) {
|
642 | if (!dependencyMap.has(downstream)) {
|
643 | dependencyMap.set(downstream, new Set());
|
644 | }
|
645 |
|
646 | Recoil_nullthrows(dependencyMap.get(downstream)).add(upstream);
|
647 | }
|
648 |
|
649 | var Recoil_Graph = {
|
650 | addToDependencyMap,
|
651 | cloneGraph,
|
652 | graph,
|
653 | mergeDepsIntoDependencyMap,
|
654 | saveDependencyMapToStore
|
655 | };
|
656 |
|
657 | const {
|
658 | getDownstreamNodes: getDownstreamNodes$1,
|
659 | getNodeLoadable: getNodeLoadable$1,
|
660 | setNodeValue: setNodeValue$1
|
661 | } = Recoil_FunctionalCore;
|
662 |
|
663 | const {
|
664 | saveDependencyMapToStore: saveDependencyMapToStore$1
|
665 | } = Recoil_Graph;
|
666 |
|
667 | const {
|
668 | getNodeMaybe: getNodeMaybe$2
|
669 | } = Recoil_Node;
|
670 |
|
671 | const {
|
672 | DefaultValue: DefaultValue$1,
|
673 | RecoilValueNotReady: RecoilValueNotReady$1
|
674 | } = Recoil_Node;
|
675 |
|
676 | const {
|
677 | AbstractRecoilValue: AbstractRecoilValue$1,
|
678 | RecoilState: RecoilState$1,
|
679 | RecoilValueReadOnly: RecoilValueReadOnly$1,
|
680 | isRecoilValue: isRecoilValue$1
|
681 | } = Recoil_RecoilValue$1;
|
682 |
|
683 | function getRecoilValueAsLoadable(store, {
|
684 | key
|
685 | }, treeState = store.getState().currentTree) {
|
686 | var _storeState$nextTree, _storeState$previousT;
|
687 |
|
688 |
|
689 |
|
690 | const storeState = store.getState();
|
691 |
|
692 | if (!(treeState.version === storeState.currentTree.version || treeState.version === ((_storeState$nextTree = storeState.nextTree) === null || _storeState$nextTree === void 0 ? void 0 : _storeState$nextTree.version) || treeState.version === ((_storeState$previousT = storeState.previousTree) === null || _storeState$previousT === void 0 ? void 0 : _storeState$previousT.version))) {
|
693 | Recoil_recoverableViolation('Tried to read from a discarded tree');
|
694 | }
|
695 |
|
696 | const [dependencyMap, loadable] = getNodeLoadable$1(store, treeState, key);
|
697 |
|
698 | if (!Recoil_gkx_1('recoil_async_selector_refactor')) {
|
699 | |
700 |
|
701 |
|
702 | saveDependencyMapToStore$1(dependencyMap, store, treeState.version);
|
703 | }
|
704 |
|
705 | return loadable;
|
706 | }
|
707 |
|
708 | function applyAtomValueWrites(atomValues, writes) {
|
709 | const result = Recoil_mapMap(atomValues, v => v);
|
710 | writes.forEach((v, k) => {
|
711 | if (v.state === 'hasValue' && v.contents instanceof DefaultValue$1) {
|
712 | result.delete(k);
|
713 | } else {
|
714 | result.set(k, v);
|
715 | }
|
716 | });
|
717 | return result;
|
718 | }
|
719 |
|
720 | function valueFromValueOrUpdater(store, state, {
|
721 | key
|
722 | }, valueOrUpdater) {
|
723 | if (typeof valueOrUpdater === 'function') {
|
724 |
|
725 |
|
726 |
|
727 |
|
728 | const current = getNodeLoadable$1(store, state, key)[1];
|
729 |
|
730 | if (current.state === 'loading') {
|
731 | throw new RecoilValueNotReady$1(key);
|
732 | } else if (current.state === 'hasError') {
|
733 | throw current.contents;
|
734 | }
|
735 |
|
736 |
|
737 | return valueOrUpdater(current.contents);
|
738 | } else {
|
739 | return valueOrUpdater;
|
740 | }
|
741 | }
|
742 |
|
743 | function applyAction(store, state, action) {
|
744 | if (action.type === 'set') {
|
745 | const {
|
746 | recoilValue,
|
747 | valueOrUpdater
|
748 | } = action;
|
749 | const newValue = valueFromValueOrUpdater(store, state, recoilValue, valueOrUpdater);
|
750 | const [depMap, writes] = setNodeValue$1(store, state, recoilValue.key, newValue);
|
751 | saveDependencyMapToStore$1(depMap, store, state.version);
|
752 |
|
753 | for (const [key, loadable] of writes.entries()) {
|
754 | writeLoadableToTreeState(state, key, loadable);
|
755 | }
|
756 | } else if (action.type === 'setLoadable') {
|
757 | const {
|
758 | recoilValue: {
|
759 | key
|
760 | },
|
761 | loadable
|
762 | } = action;
|
763 | writeLoadableToTreeState(state, key, loadable);
|
764 | } else if (action.type === 'markModified') {
|
765 | const {
|
766 | recoilValue: {
|
767 | key
|
768 | }
|
769 | } = action;
|
770 | state.dirtyAtoms.add(key);
|
771 | } else if (action.type === 'setUnvalidated') {
|
772 | var _node$invalidate;
|
773 |
|
774 |
|
775 |
|
776 | const {
|
777 | recoilValue: {
|
778 | key
|
779 | },
|
780 | unvalidatedValue
|
781 | } = action;
|
782 | const node = getNodeMaybe$2(key);
|
783 | node === null || node === void 0 ? void 0 : (_node$invalidate = node.invalidate) === null || _node$invalidate === void 0 ? void 0 : _node$invalidate.call(node, state);
|
784 | state.atomValues.delete(key);
|
785 | state.nonvalidatedAtoms.set(key, unvalidatedValue);
|
786 | state.dirtyAtoms.add(key);
|
787 | } else {
|
788 | Recoil_recoverableViolation(`Unknown action ${action.type}`);
|
789 | }
|
790 | }
|
791 |
|
792 | function writeLoadableToTreeState(state, key, loadable) {
|
793 | if (loadable.state === 'hasValue' && loadable.contents instanceof DefaultValue$1) {
|
794 | state.atomValues.delete(key);
|
795 | } else {
|
796 | state.atomValues.set(key, loadable);
|
797 | }
|
798 |
|
799 | state.dirtyAtoms.add(key);
|
800 | state.nonvalidatedAtoms.delete(key);
|
801 | }
|
802 |
|
803 | function applyActionsToStore(store, actions) {
|
804 | store.replaceState(state => {
|
805 | const newState = copyTreeState(state);
|
806 |
|
807 | for (const action of actions) {
|
808 | applyAction(store, newState, action);
|
809 | }
|
810 |
|
811 | invalidateDownstreams(store, newState);
|
812 | return newState;
|
813 | });
|
814 | }
|
815 |
|
816 | function queueOrPerformStateUpdate(store, action, key, message) {
|
817 | if (batchStack.length) {
|
818 | const actionsByStore = batchStack[batchStack.length - 1];
|
819 | let actions = actionsByStore.get(store);
|
820 |
|
821 | if (!actions) {
|
822 | actionsByStore.set(store, actions = []);
|
823 | }
|
824 |
|
825 | actions.push(action);
|
826 | } else {
|
827 | Recoil_Tracing.trace(message, key, () => applyActionsToStore(store, [action]));
|
828 | }
|
829 | }
|
830 |
|
831 | const batchStack = [];
|
832 |
|
833 | function batchStart() {
|
834 | const actionsByStore = new Map();
|
835 | batchStack.push(actionsByStore);
|
836 | return () => {
|
837 | for (const [store, actions] of actionsByStore) {
|
838 | Recoil_Tracing.trace('Recoil batched updates', '-', () => applyActionsToStore(store, actions));
|
839 | }
|
840 |
|
841 | const popped = batchStack.pop();
|
842 |
|
843 | if (popped !== actionsByStore) {
|
844 | Recoil_recoverableViolation('Incorrect order of batch popping');
|
845 | }
|
846 | };
|
847 | }
|
848 |
|
849 | function copyTreeState(state) {
|
850 | return { ...state,
|
851 | atomValues: new Map(state.atomValues),
|
852 | nonvalidatedAtoms: new Map(state.nonvalidatedAtoms),
|
853 | dirtyAtoms: new Set(state.dirtyAtoms)
|
854 | };
|
855 | }
|
856 |
|
857 | function invalidateDownstreams(store, state) {
|
858 |
|
859 |
|
860 | const downstreams = getDownstreamNodes$1(store, state, state.dirtyAtoms);
|
861 |
|
862 | for (const key of downstreams) {
|
863 | var _getNodeMaybe, _getNodeMaybe$invalid;
|
864 |
|
865 | (_getNodeMaybe = getNodeMaybe$2(key)) === null || _getNodeMaybe === void 0 ? void 0 : (_getNodeMaybe$invalid = _getNodeMaybe.invalidate) === null || _getNodeMaybe$invalid === void 0 ? void 0 : _getNodeMaybe$invalid.call(_getNodeMaybe, state);
|
866 | }
|
867 | }
|
868 |
|
869 | function setRecoilValue(store, recoilValue, valueOrUpdater) {
|
870 | queueOrPerformStateUpdate(store, {
|
871 | type: 'set',
|
872 | recoilValue,
|
873 | valueOrUpdater
|
874 | }, recoilValue.key, 'set Recoil value');
|
875 | }
|
876 |
|
877 | function setRecoilValueLoadable(store, recoilValue, loadable) {
|
878 | if (loadable instanceof DefaultValue$1) {
|
879 | return setRecoilValue(store, recoilValue, loadable);
|
880 | }
|
881 |
|
882 | queueOrPerformStateUpdate(store, {
|
883 | type: 'setLoadable',
|
884 | recoilValue,
|
885 | loadable
|
886 | }, recoilValue.key, 'set Recoil value');
|
887 | }
|
888 |
|
889 | function markRecoilValueModified(store, recoilValue) {
|
890 | queueOrPerformStateUpdate(store, {
|
891 | type: 'markModified',
|
892 | recoilValue
|
893 | }, recoilValue.key, 'mark RecoilValue modified');
|
894 | }
|
895 |
|
896 | function setUnvalidatedRecoilValue(store, recoilValue, unvalidatedValue) {
|
897 | queueOrPerformStateUpdate(store, {
|
898 | type: 'setUnvalidated',
|
899 | recoilValue,
|
900 | unvalidatedValue
|
901 | }, recoilValue.key, 'set Recoil value');
|
902 | }
|
903 |
|
904 | let subscriptionID = 0;
|
905 |
|
906 | function subscribeToRecoilValue(store, {
|
907 | key
|
908 | }, callback, componentDebugName = null) {
|
909 | const subID = subscriptionID++;
|
910 | const storeState = store.getState();
|
911 |
|
912 | if (!storeState.nodeToComponentSubscriptions.has(key)) {
|
913 | storeState.nodeToComponentSubscriptions.set(key, new Map());
|
914 | }
|
915 |
|
916 | Recoil_nullthrows(storeState.nodeToComponentSubscriptions.get(key)).set(subID, [componentDebugName !== null && componentDebugName !== void 0 ? componentDebugName : '<not captured>', callback]);
|
917 | return {
|
918 | release: () => {
|
919 | const storeState = store.getState();
|
920 | const subs = storeState.nodeToComponentSubscriptions.get(key);
|
921 |
|
922 | if (subs === undefined || !subs.has(subID)) {
|
923 | Recoil_recoverableViolation(`Subscription missing at release time for atom ${key}. This is a bug in Recoil.`);
|
924 | return;
|
925 | }
|
926 |
|
927 | subs.delete(subID);
|
928 |
|
929 | if (subs.size === 0) {
|
930 | storeState.nodeToComponentSubscriptions.delete(key);
|
931 | }
|
932 | }
|
933 | };
|
934 | }
|
935 |
|
936 | var Recoil_RecoilValueInterface = {
|
937 | RecoilValueReadOnly: RecoilValueReadOnly$1,
|
938 | AbstractRecoilValue: AbstractRecoilValue$1,
|
939 | RecoilState: RecoilState$1,
|
940 | getRecoilValueAsLoadable,
|
941 | setRecoilValue,
|
942 | setRecoilValueLoadable,
|
943 | markRecoilValueModified,
|
944 | setUnvalidatedRecoilValue,
|
945 | subscribeToRecoilValue,
|
946 | isRecoilValue: isRecoilValue$1,
|
947 | applyAtomValueWrites,
|
948 |
|
949 | batchStart,
|
950 | invalidateDownstreams_FOR_TESTING: invalidateDownstreams
|
951 | };
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 | const {
|
967 | unstable_batchedUpdates
|
968 | } = reactDom;
|
969 |
|
970 |
|
971 |
|
972 | var Recoil_ReactBatchedUpdates = {
|
973 | unstable_batchedUpdates
|
974 | };
|
975 |
|
976 |
|
977 |
|
978 |
|
979 |
|
980 |
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 | const {
|
987 | batchStart: batchStart$1
|
988 | } = Recoil_RecoilValueInterface;
|
989 |
|
990 | const {
|
991 | unstable_batchedUpdates: unstable_batchedUpdates$1
|
992 | } = Recoil_ReactBatchedUpdates;
|
993 |
|
994 | let batcher = unstable_batchedUpdates$1;
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 | const setBatcher = newBatcher => {
|
1003 | batcher = newBatcher;
|
1004 | };
|
1005 |
|
1006 |
|
1007 |
|
1008 |
|
1009 |
|
1010 | const getBatcher = () => batcher;
|
1011 |
|
1012 |
|
1013 |
|
1014 |
|
1015 |
|
1016 |
|
1017 | const batchUpdates = callback => {
|
1018 | batcher(() => {
|
1019 | let batchEnd = () => undefined;
|
1020 |
|
1021 | try {
|
1022 | batchEnd = batchStart$1();
|
1023 | callback();
|
1024 | } finally {
|
1025 | batchEnd();
|
1026 | }
|
1027 | });
|
1028 | };
|
1029 |
|
1030 | var Recoil_Batching = {
|
1031 | getBatcher,
|
1032 | setBatcher,
|
1033 | batchUpdates
|
1034 | };
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | function enqueueExecution(s, f) {
|
1048 | f();
|
1049 | }
|
1050 |
|
1051 | var Recoil_Queue = {
|
1052 | enqueueExecution
|
1053 | };
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 | function* concatIterables(iters) {
|
1078 | for (const iter of iters) {
|
1079 | for (const val of iter) {
|
1080 | yield val;
|
1081 | }
|
1082 | }
|
1083 | }
|
1084 |
|
1085 | var Recoil_concatIterables = concatIterables;
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 | function* filterIterable(iterable, predicate) {
|
1103 |
|
1104 | let index = 0;
|
1105 |
|
1106 | for (const value of iterable) {
|
1107 | if (predicate(value, index++)) {
|
1108 | yield value;
|
1109 | }
|
1110 | }
|
1111 | }
|
1112 |
|
1113 | var Recoil_filterIterable = filterIterable;
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 | function mapIterable(iterable, callback) {
|
1131 |
|
1132 | return function* () {
|
1133 | let index = 0;
|
1134 |
|
1135 | for (const value of iterable) {
|
1136 | yield callback(value, index++);
|
1137 | }
|
1138 | }();
|
1139 | }
|
1140 |
|
1141 | var Recoil_mapIterable = mapIterable;
|
1142 |
|
1143 | const {
|
1144 | graph: graph$1
|
1145 | } = Recoil_Graph;
|
1146 |
|
1147 |
|
1148 | let nextTreeStateVersion = 0;
|
1149 |
|
1150 | const getNextTreeStateVersion = () => nextTreeStateVersion++;
|
1151 |
|
1152 | function makeEmptyTreeState() {
|
1153 | const version = getNextTreeStateVersion();
|
1154 | return {
|
1155 | version,
|
1156 | stateID: version,
|
1157 | transactionMetadata: {},
|
1158 | dirtyAtoms: new Set(),
|
1159 | atomValues: new Map(),
|
1160 | nonvalidatedAtoms: new Map()
|
1161 | };
|
1162 | }
|
1163 |
|
1164 | function makeEmptyStoreState() {
|
1165 | const currentTree = makeEmptyTreeState();
|
1166 | return {
|
1167 | currentTree,
|
1168 | nextTree: null,
|
1169 | previousTree: null,
|
1170 | knownAtoms: new Set(),
|
1171 | knownSelectors: new Set(),
|
1172 | transactionSubscriptions: new Map(),
|
1173 | nodeTransactionSubscriptions: new Map(),
|
1174 | nodeToComponentSubscriptions: new Map(),
|
1175 | queuedComponentCallbacks_DEPRECATED: [],
|
1176 | suspendedComponentResolvers: new Set(),
|
1177 | graphsByVersion: new Map().set(currentTree.version, graph$1()),
|
1178 | versionsUsedByComponent: new Map()
|
1179 | };
|
1180 | }
|
1181 |
|
1182 | var Recoil_State = {
|
1183 | makeEmptyTreeState,
|
1184 | makeEmptyStoreState,
|
1185 | getNextTreeStateVersion
|
1186 | };
|
1187 |
|
1188 | const {
|
1189 | batchUpdates: batchUpdates$1
|
1190 | } = Recoil_Batching;
|
1191 |
|
1192 | const {
|
1193 | getDownstreamNodes: getDownstreamNodes$2,
|
1194 | peekNodeLoadable: peekNodeLoadable$1
|
1195 | } = Recoil_FunctionalCore;
|
1196 |
|
1197 | const {
|
1198 | graph: graph$2
|
1199 | } = Recoil_Graph;
|
1200 |
|
1201 | const {
|
1202 | DEFAULT_VALUE: DEFAULT_VALUE$1,
|
1203 | recoilValues: recoilValues$1
|
1204 | } = Recoil_Node;
|
1205 |
|
1206 | const {
|
1207 | getRecoilValueAsLoadable: getRecoilValueAsLoadable$1,
|
1208 | setRecoilValue: setRecoilValue$1
|
1209 | } = Recoil_RecoilValueInterface;
|
1210 |
|
1211 | const {
|
1212 | getNextTreeStateVersion: getNextTreeStateVersion$1,
|
1213 | makeEmptyStoreState: makeEmptyStoreState$1
|
1214 | } = Recoil_State;
|
1215 |
|
1216 |
|
1217 | function recoilValuesForKeys(keys) {
|
1218 | return Recoil_mapIterable(keys, key => Recoil_nullthrows(recoilValues$1.get(key)));
|
1219 | } // A "Snapshot" is "read-only" and captures a specific set of values of atoms.
|
1220 | // However, the data-flow-graph and selector values may evolve as selector
|
1221 | // evaluation functions are executed and async selectors resolve.
|
1222 |
|
1223 |
|
1224 | class Snapshot {
|
1225 | constructor(storeState) {
|
1226 | _defineProperty(this, "_store", void 0);
|
1227 |
|
1228 | _defineProperty(this, "getLoadable", recoilValue =>
|
1229 | getRecoilValueAsLoadable$1(this._store, recoilValue));
|
1230 |
|
1231 | _defineProperty(this, "getPromise", recoilValue =>
|
1232 | this.getLoadable(recoilValue).toPromise());
|
1233 |
|
1234 | _defineProperty(this, "getNodes_UNSTABLE", opt => {
|
1235 |
|
1236 | if ((opt === null || opt === void 0 ? void 0 : opt.isModified) === true) {
|
1237 | if ((opt === null || opt === void 0 ? void 0 : opt.isInitialized) === false) {
|
1238 | return [];
|
1239 | }
|
1240 |
|
1241 | const state = this._store.getState().currentTree;
|
1242 |
|
1243 | return recoilValuesForKeys(state.dirtyAtoms);
|
1244 | }
|
1245 |
|
1246 | const knownAtoms = this._store.getState().knownAtoms;
|
1247 |
|
1248 | const knownSelectors = this._store.getState().knownSelectors;
|
1249 |
|
1250 | return (opt === null || opt === void 0 ? void 0 : opt.isInitialized) == null ? recoilValues$1.values() : opt.isInitialized === true ? recoilValuesForKeys(Recoil_concatIterables([this._store.getState().knownAtoms, this._store.getState().knownSelectors])) : Recoil_filterIterable(recoilValues$1.values(), ({
|
1251 | key
|
1252 | }) => !knownAtoms.has(key) && !knownSelectors.has(key));
|
1253 | });
|
1254 |
|
1255 | _defineProperty(this, "getDeps_UNSTABLE", recoilValue => {
|
1256 | this.getLoadable(recoilValue);
|
1257 |
|
1258 | const deps = this._store.getGraph(this._store.getState().currentTree.version).nodeDeps.get(recoilValue.key);
|
1259 |
|
1260 | return recoilValuesForKeys(deps !== null && deps !== void 0 ? deps : []);
|
1261 | });
|
1262 |
|
1263 | _defineProperty(this, "getSubscribers_UNSTABLE", ({
|
1264 | key
|
1265 | }) => {
|
1266 | const state = this._store.getState().currentTree;
|
1267 |
|
1268 | const downstreamNodes = Recoil_filterIterable(getDownstreamNodes$2(this._store, state, new Set([key])), nodeKey => nodeKey !== key);
|
1269 | return {
|
1270 | nodes: recoilValuesForKeys(downstreamNodes)
|
1271 | };
|
1272 | });
|
1273 |
|
1274 | _defineProperty(this, "getInfo_UNSTABLE", recoilValue => {
|
1275 | var _graph$nodeDeps$get;
|
1276 |
|
1277 | const {
|
1278 | key
|
1279 | } = recoilValue;
|
1280 |
|
1281 | const state = this._store.getState().currentTree;
|
1282 |
|
1283 | const graph = this._store.getGraph(state.version);
|
1284 |
|
1285 | const type = this._store.getState().knownAtoms.has(key) ? 'atom' : this._store.getState().knownSelectors.has(key) ? 'selector' : undefined;
|
1286 | return {
|
1287 | loadable: peekNodeLoadable$1(this._store, state, key),
|
1288 | isActive: this._store.getState().knownAtoms.has(key) || this._store.getState().knownSelectors.has(key),
|
1289 | isSet: type === 'selector' ? false : state.atomValues.has(key),
|
1290 | isModified: state.dirtyAtoms.has(key),
|
1291 | type,
|
1292 |
|
1293 | deps: recoilValuesForKeys((_graph$nodeDeps$get = graph.nodeDeps.get(key)) !== null && _graph$nodeDeps$get !== void 0 ? _graph$nodeDeps$get : []),
|
1294 | subscribers: this.getSubscribers_UNSTABLE(recoilValue)
|
1295 | };
|
1296 | });
|
1297 |
|
1298 | _defineProperty(this, "map", mapper => {
|
1299 | const mutableSnapshot = new MutableSnapshot(this);
|
1300 | mapper(mutableSnapshot);
|
1301 |
|
1302 | return cloneSnapshot(mutableSnapshot.getStore_INTERNAL());
|
1303 | });
|
1304 |
|
1305 | _defineProperty(this, "asyncMap", async mapper => {
|
1306 | const mutableSnapshot = new MutableSnapshot(this);
|
1307 | await mapper(mutableSnapshot);
|
1308 | return cloneSnapshot(mutableSnapshot.getStore_INTERNAL());
|
1309 | });
|
1310 |
|
1311 | this._store = {
|
1312 | getState: () => storeState,
|
1313 | replaceState: replacer => {
|
1314 | storeState.currentTree = replacer(storeState.currentTree);
|
1315 | },
|
1316 | getGraph: version => {
|
1317 | const graphs = storeState.graphsByVersion;
|
1318 |
|
1319 | if (graphs.has(version)) {
|
1320 | return Recoil_nullthrows(graphs.get(version));
|
1321 | }
|
1322 |
|
1323 | const newGraph = graph$2();
|
1324 | graphs.set(version, newGraph);
|
1325 | return newGraph;
|
1326 | },
|
1327 | subscribeToTransactions: () => ({
|
1328 | release: () => {}
|
1329 | }),
|
1330 | addTransactionMetadata: () => {
|
1331 | throw new Error('Cannot subscribe to Snapshots');
|
1332 | }
|
1333 | };
|
1334 | }
|
1335 |
|
1336 | getStore_INTERNAL() {
|
1337 | return this._store;
|
1338 | }
|
1339 |
|
1340 | getID() {
|
1341 | return this.getID_INTERNAL();
|
1342 | }
|
1343 |
|
1344 | getID_INTERNAL() {
|
1345 | return this._store.getState().currentTree.stateID;
|
1346 | }
|
1347 |
|
1348 | }
|
1349 |
|
1350 | function cloneStoreState(store, treeState, bumpVersion = false) {
|
1351 | const storeState = store.getState();
|
1352 | const version = bumpVersion ? getNextTreeStateVersion$1() : treeState.version;
|
1353 | return {
|
1354 | currentTree: bumpVersion ? {
|
1355 |
|
1356 |
|
1357 | version,
|
1358 | stateID: version,
|
1359 | transactionMetadata: { ...treeState.transactionMetadata
|
1360 | },
|
1361 | dirtyAtoms: new Set(treeState.dirtyAtoms),
|
1362 | atomValues: new Map(treeState.atomValues),
|
1363 | nonvalidatedAtoms: new Map(treeState.nonvalidatedAtoms)
|
1364 | } : treeState,
|
1365 | nextTree: null,
|
1366 | previousTree: null,
|
1367 | knownAtoms: new Set(storeState.knownAtoms),
|
1368 |
|
1369 | knownSelectors: new Set(storeState.knownSelectors),
|
1370 |
|
1371 | transactionSubscriptions: new Map(),
|
1372 | nodeTransactionSubscriptions: new Map(),
|
1373 | nodeToComponentSubscriptions: new Map(),
|
1374 | queuedComponentCallbacks_DEPRECATED: [],
|
1375 | suspendedComponentResolvers: new Set(),
|
1376 | graphsByVersion: new Map().set(version, store.getGraph(treeState.version)),
|
1377 | versionsUsedByComponent: new Map()
|
1378 | };
|
1379 | }
|
1380 |
|
1381 |
|
1382 | function freshSnapshot(initializeState) {
|
1383 | const snapshot = new Snapshot(makeEmptyStoreState$1());
|
1384 | return initializeState != null ? snapshot.map(initializeState) : snapshot;
|
1385 | }
|
1386 |
|
1387 |
|
1388 | function cloneSnapshot(store, version = 'current') {
|
1389 | const storeState = store.getState();
|
1390 | const treeState = version === 'current' ? storeState.currentTree : Recoil_nullthrows(storeState.previousTree);
|
1391 | return new Snapshot(cloneStoreState(store, treeState));
|
1392 | }
|
1393 |
|
1394 | class MutableSnapshot extends Snapshot {
|
1395 | constructor(snapshot) {
|
1396 | super(cloneStoreState(snapshot.getStore_INTERNAL(), snapshot.getStore_INTERNAL().getState().currentTree, true));
|
1397 |
|
1398 | _defineProperty(this, "set", (recoilState, newValueOrUpdater) => {
|
1399 | const store = this.getStore_INTERNAL();
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 | batchUpdates$1(() => {
|
1405 | setRecoilValue$1(store, recoilState, newValueOrUpdater);
|
1406 | });
|
1407 | });
|
1408 |
|
1409 | _defineProperty(this, "reset", recoilState =>
|
1410 | batchUpdates$1(() => setRecoilValue$1(this.getStore_INTERNAL(), recoilState, DEFAULT_VALUE$1)));
|
1411 | }
|
1412 |
|
1413 |
|
1414 |
|
1415 | }
|
1416 |
|
1417 | var Recoil_Snapshot = {
|
1418 | Snapshot,
|
1419 | MutableSnapshot,
|
1420 | freshSnapshot,
|
1421 | cloneSnapshot
|
1422 | };
|
1423 |
|
1424 | var Recoil_Snapshot_1 = Recoil_Snapshot.Snapshot;
|
1425 | var Recoil_Snapshot_2 = Recoil_Snapshot.MutableSnapshot;
|
1426 | var Recoil_Snapshot_3 = Recoil_Snapshot.freshSnapshot;
|
1427 | var Recoil_Snapshot_4 = Recoil_Snapshot.cloneSnapshot;
|
1428 |
|
1429 | var Recoil_Snapshot$1 = Object.freeze({
|
1430 | __proto__: null,
|
1431 | Snapshot: Recoil_Snapshot_1,
|
1432 | MutableSnapshot: Recoil_Snapshot_2,
|
1433 | freshSnapshot: Recoil_Snapshot_3,
|
1434 | cloneSnapshot: Recoil_Snapshot_4
|
1435 | });
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 | function unionSets(...sets) {
|
1449 | const result = new Set();
|
1450 |
|
1451 | for (const set of sets) {
|
1452 | for (const value of set) {
|
1453 | result.add(value);
|
1454 | }
|
1455 | }
|
1456 |
|
1457 | return result;
|
1458 | }
|
1459 |
|
1460 | var Recoil_unionSets = unionSets;
|
1461 |
|
1462 | const {
|
1463 | useContext,
|
1464 | useEffect,
|
1465 | useMemo,
|
1466 | useRef,
|
1467 | useState
|
1468 | } = react;
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 | const {
|
1476 | cleanUpNode: cleanUpNode$1,
|
1477 | getDownstreamNodes: getDownstreamNodes$3,
|
1478 | setNodeValue: setNodeValue$2,
|
1479 | setUnvalidatedAtomValue_DEPRECATED: setUnvalidatedAtomValue_DEPRECATED$1
|
1480 | } = Recoil_FunctionalCore;
|
1481 |
|
1482 | const {
|
1483 | graph: graph$3,
|
1484 | saveDependencyMapToStore: saveDependencyMapToStore$2
|
1485 | } = Recoil_Graph;
|
1486 |
|
1487 | const {
|
1488 | cloneGraph: cloneGraph$1
|
1489 | } = Recoil_Graph;
|
1490 |
|
1491 | const {
|
1492 | applyAtomValueWrites: applyAtomValueWrites$1
|
1493 | } = Recoil_RecoilValueInterface;
|
1494 |
|
1495 | const {
|
1496 | freshSnapshot: freshSnapshot$1
|
1497 | } = Recoil_Snapshot$1;
|
1498 |
|
1499 | const {
|
1500 | getNextTreeStateVersion: getNextTreeStateVersion$2,
|
1501 | makeEmptyStoreState: makeEmptyStoreState$2
|
1502 | } = Recoil_State;
|
1503 |
|
1504 | const {
|
1505 | mapByDeletingMultipleFromMap: mapByDeletingMultipleFromMap$1
|
1506 | } = Recoil_CopyOnWrite;
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 | function notInAContext() {
|
1517 | throw new Error('This component must be used inside a <RecoilRoot> component.');
|
1518 | }
|
1519 |
|
1520 | const defaultStore = Object.freeze({
|
1521 | getState: notInAContext,
|
1522 | replaceState: notInAContext,
|
1523 | getGraph: notInAContext,
|
1524 | subscribeToTransactions: notInAContext,
|
1525 | addTransactionMetadata: notInAContext
|
1526 | });
|
1527 | let stateReplacerIsBeingExecuted = false;
|
1528 |
|
1529 | function startNextTreeIfNeeded(storeState) {
|
1530 | if (stateReplacerIsBeingExecuted) {
|
1531 | throw new Error('An atom update was triggered within the execution of a state updater function. State updater functions provided to Recoil must be pure functions.');
|
1532 | }
|
1533 |
|
1534 | if (storeState.nextTree === null) {
|
1535 | const version = storeState.currentTree.version;
|
1536 | const nextVersion = getNextTreeStateVersion$2();
|
1537 | storeState.nextTree = { ...storeState.currentTree,
|
1538 | version: nextVersion,
|
1539 | stateID: nextVersion,
|
1540 | dirtyAtoms: new Set(),
|
1541 | transactionMetadata: {}
|
1542 | };
|
1543 | storeState.graphsByVersion.set(nextVersion, cloneGraph$1(Recoil_nullthrows(storeState.graphsByVersion.get(version))));
|
1544 | }
|
1545 | }
|
1546 |
|
1547 | const AppContext = react.createContext({
|
1548 | current: defaultStore
|
1549 | });
|
1550 |
|
1551 | const useStoreRef = () => useContext(AppContext);
|
1552 |
|
1553 | const MutableSourceContext = react.createContext(null);
|
1554 |
|
1555 | const useRecoilMutableSource = () => useContext(MutableSourceContext);
|
1556 |
|
1557 | function sendEndOfBatchNotifications(store) {
|
1558 | const storeState = store.getState();
|
1559 | const treeState = storeState.currentTree;
|
1560 |
|
1561 | const dirtyAtoms = treeState.dirtyAtoms;
|
1562 |
|
1563 | if (dirtyAtoms.size) {
|
1564 |
|
1565 | for (const [key, subscriptions] of storeState.nodeTransactionSubscriptions) {
|
1566 | if (dirtyAtoms.has(key)) {
|
1567 | for (const [_, subscription] of subscriptions) {
|
1568 | subscription(store);
|
1569 | }
|
1570 | }
|
1571 | }
|
1572 |
|
1573 | for (const [_, subscription] of storeState.transactionSubscriptions) {
|
1574 | subscription(store);
|
1575 | }
|
1576 |
|
1577 |
|
1578 | const dependentNodes = getDownstreamNodes$3(store, treeState, dirtyAtoms);
|
1579 |
|
1580 | for (const key of dependentNodes) {
|
1581 | const comps = storeState.nodeToComponentSubscriptions.get(key);
|
1582 |
|
1583 | if (comps) {
|
1584 | for (const [_subID, [_debugName, callback]] of comps) {
|
1585 | callback(treeState);
|
1586 | }
|
1587 | }
|
1588 | }
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 | let nodeNames = '[available in dev build]';
|
1597 |
|
1598 | if (process.env.NODE_ENV !== "production") {
|
1599 | nodeNames = Array.from(dirtyAtoms).join(', ');
|
1600 | }
|
1601 |
|
1602 | storeState.suspendedComponentResolvers.forEach(cb => Recoil_Tracing.trace('value became available, waking components', nodeNames, cb));
|
1603 | }
|
1604 |
|
1605 |
|
1606 |
|
1607 | storeState.queuedComponentCallbacks_DEPRECATED.forEach(cb => cb(treeState));
|
1608 | storeState.queuedComponentCallbacks_DEPRECATED.splice(0, storeState.queuedComponentCallbacks_DEPRECATED.length);
|
1609 | }
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 | function Batcher(props) {
|
1619 | const storeRef = useStoreRef();
|
1620 | const [_, setState] = useState([]);
|
1621 | props.setNotifyBatcherOfChange(() => setState({}));
|
1622 | useEffect(() => {
|
1623 |
|
1624 |
|
1625 |
|
1626 | Recoil_Queue.enqueueExecution('Batcher', () => {
|
1627 | const storeState = storeRef.current.getState();
|
1628 | const {
|
1629 | nextTree
|
1630 | } = storeState;
|
1631 |
|
1632 |
|
1633 | if (nextTree === null) {
|
1634 | return;
|
1635 | }
|
1636 |
|
1637 |
|
1638 |
|
1639 | storeState.previousTree = storeState.currentTree;
|
1640 | storeState.currentTree = nextTree;
|
1641 | storeState.nextTree = null;
|
1642 | sendEndOfBatchNotifications(storeRef.current);
|
1643 | const discardedVersion = Recoil_nullthrows(storeState.previousTree).version;
|
1644 | storeState.graphsByVersion.delete(discardedVersion);
|
1645 | storeState.previousTree = null;
|
1646 | });
|
1647 | });
|
1648 | return null;
|
1649 | }
|
1650 |
|
1651 | if (process.env.NODE_ENV !== "production") {
|
1652 | if (typeof window !== 'undefined' && !window.$recoilDebugStates) {
|
1653 | window.$recoilDebugStates = [];
|
1654 | }
|
1655 | }
|
1656 |
|
1657 |
|
1658 |
|
1659 | function initialStoreState_DEPRECATED(store, initializeState) {
|
1660 | const initial = makeEmptyStoreState$2();
|
1661 | initializeState({
|
1662 |
|
1663 | set: (atom, value) => {
|
1664 | const state = initial.currentTree;
|
1665 | const [depMap, writes] = setNodeValue$2(store, state, atom.key, value);
|
1666 | const writtenNodes = new Set(writes.keys());
|
1667 | saveDependencyMapToStore$2(depMap, store, state.version);
|
1668 | const nonvalidatedAtoms = mapByDeletingMultipleFromMap$1(state.nonvalidatedAtoms, writtenNodes);
|
1669 | initial.currentTree = { ...state,
|
1670 | dirtyAtoms: Recoil_unionSets(state.dirtyAtoms, writtenNodes),
|
1671 | atomValues: applyAtomValueWrites$1(state.atomValues, writes),
|
1672 |
|
1673 | nonvalidatedAtoms
|
1674 | };
|
1675 | },
|
1676 | setUnvalidatedAtomValues: atomValues => {
|
1677 |
|
1678 | atomValues.forEach((v, k) => {
|
1679 | initial.currentTree = setUnvalidatedAtomValue_DEPRECATED$1(initial.currentTree, k, v);
|
1680 | });
|
1681 | }
|
1682 | });
|
1683 | return initial;
|
1684 | }
|
1685 |
|
1686 | function initialStoreState(initializeState) {
|
1687 | const snapshot = freshSnapshot$1().map(initializeState);
|
1688 | return snapshot.getStore_INTERNAL().getState();
|
1689 | }
|
1690 |
|
1691 | let nextID = 0;
|
1692 |
|
1693 | function RecoilRoot({
|
1694 | initializeState_DEPRECATED,
|
1695 | initializeState,
|
1696 | store_INTERNAL: storeProp,
|
1697 | // For use with React "context bridging"
|
1698 | children
|
1699 | }) {
|
1700 | var _createMutableSource;
|
1701 |
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 |
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 | let storeState;
|
1719 |
|
1720 | const getGraph = version => {
|
1721 | const graphs = storeState.current.graphsByVersion;
|
1722 |
|
1723 | if (graphs.has(version)) {
|
1724 | return Recoil_nullthrows(graphs.get(version));
|
1725 | }
|
1726 |
|
1727 | const newGraph = graph$3();
|
1728 | graphs.set(version, newGraph);
|
1729 | return newGraph;
|
1730 | };
|
1731 |
|
1732 | const subscribeToTransactions = (callback, key) => {
|
1733 | if (key == null) {
|
1734 |
|
1735 | const {
|
1736 | transactionSubscriptions
|
1737 | } = storeRef.current.getState();
|
1738 | const id = nextID++;
|
1739 | transactionSubscriptions.set(id, callback);
|
1740 | return {
|
1741 | release: () => {
|
1742 | transactionSubscriptions.delete(id);
|
1743 | }
|
1744 | };
|
1745 | } else {
|
1746 |
|
1747 | const {
|
1748 | nodeTransactionSubscriptions
|
1749 | } = storeRef.current.getState();
|
1750 |
|
1751 | if (!nodeTransactionSubscriptions.has(key)) {
|
1752 | nodeTransactionSubscriptions.set(key, new Map());
|
1753 | }
|
1754 |
|
1755 | const id = nextID++;
|
1756 | Recoil_nullthrows(nodeTransactionSubscriptions.get(key)).set(id, callback);
|
1757 | return {
|
1758 | release: () => {
|
1759 | const subs = nodeTransactionSubscriptions.get(key);
|
1760 |
|
1761 | if (subs) {
|
1762 | subs.delete(id);
|
1763 |
|
1764 | if (subs.size === 0) {
|
1765 | nodeTransactionSubscriptions.delete(key);
|
1766 | }
|
1767 | }
|
1768 | }
|
1769 | };
|
1770 | }
|
1771 | };
|
1772 |
|
1773 | const addTransactionMetadata = metadata => {
|
1774 | startNextTreeIfNeeded(storeRef.current.getState());
|
1775 |
|
1776 | for (const k of Object.keys(metadata)) {
|
1777 | Recoil_nullthrows(storeRef.current.getState().nextTree).transactionMetadata[k] = metadata[k];
|
1778 | }
|
1779 | };
|
1780 |
|
1781 | const replaceState = replacer => {
|
1782 | const storeState = storeRef.current.getState();
|
1783 | startNextTreeIfNeeded(storeState);
|
1784 |
|
1785 | const nextTree = Recoil_nullthrows(storeState.nextTree);
|
1786 | let replaced;
|
1787 |
|
1788 | try {
|
1789 | stateReplacerIsBeingExecuted = true;
|
1790 | replaced = replacer(nextTree);
|
1791 | } finally {
|
1792 | stateReplacerIsBeingExecuted = false;
|
1793 | }
|
1794 |
|
1795 | if (replaced === nextTree) {
|
1796 | return;
|
1797 | }
|
1798 |
|
1799 | if (process.env.NODE_ENV !== "production") {
|
1800 | if (typeof window !== 'undefined') {
|
1801 | window.$recoilDebugStates.push(replaced);
|
1802 | }
|
1803 | }
|
1804 |
|
1805 |
|
1806 | storeState.nextTree = replaced;
|
1807 | Recoil_nullthrows(notifyBatcherOfChange.current)();
|
1808 | };
|
1809 |
|
1810 | const notifyBatcherOfChange = useRef(null);
|
1811 |
|
1812 | function setNotifyBatcherOfChange(x) {
|
1813 | notifyBatcherOfChange.current = x;
|
1814 | }
|
1815 |
|
1816 |
|
1817 | const createMutableSource = (_createMutableSource = react.createMutableSource) !== null && _createMutableSource !== void 0 ? _createMutableSource :
|
1818 | react.unstable_createMutableSource;
|
1819 |
|
1820 | const store = storeProp !== null && storeProp !== void 0 ? storeProp : {
|
1821 | getState: () => storeState.current,
|
1822 | replaceState,
|
1823 | getGraph,
|
1824 | subscribeToTransactions,
|
1825 | addTransactionMetadata
|
1826 | };
|
1827 | const storeRef = useRef(store);
|
1828 | storeState = useRef(initializeState_DEPRECATED != null ? initialStoreState_DEPRECATED(store, initializeState_DEPRECATED) : initializeState != null ? initialStoreState(initializeState) : makeEmptyStoreState$2());
|
1829 | const mutableSource = useMemo(() => createMutableSource ? createMutableSource(storeState, () => storeState.current.currentTree.version) : null, [createMutableSource, storeState]);
|
1830 |
|
1831 | useEffect(() => () => {
|
1832 | for (const atomKey of storeRef.current.getState().knownAtoms) {
|
1833 | cleanUpNode$1(storeRef.current, atomKey);
|
1834 | }
|
1835 | }, []);
|
1836 | return react.createElement(AppContext.Provider, {
|
1837 | value: storeRef
|
1838 | }, react.createElement(MutableSourceContext.Provider, {
|
1839 | value: mutableSource
|
1840 | }, react.createElement(Batcher, {
|
1841 | setNotifyBatcherOfChange: setNotifyBatcherOfChange
|
1842 | }), children));
|
1843 | }
|
1844 |
|
1845 | var Recoil_RecoilRoot_react = {
|
1846 | useStoreRef,
|
1847 | useRecoilMutableSource,
|
1848 | RecoilRoot,
|
1849 | sendEndOfBatchNotifications_FOR_TESTING: sendEndOfBatchNotifications
|
1850 | };
|
1851 |
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 |
|
1865 |
|
1866 |
|
1867 | function filterMap(map, callback) {
|
1868 | const result = new Map();
|
1869 |
|
1870 | for (const [key, value] of map) {
|
1871 | if (callback(value, key)) {
|
1872 | result.set(key, value);
|
1873 | }
|
1874 | }
|
1875 |
|
1876 | return result;
|
1877 | }
|
1878 |
|
1879 | var Recoil_filterMap = filterMap;
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 | function filterSet(set, callback) {
|
1897 | const result = new Set();
|
1898 |
|
1899 | for (const value of set) {
|
1900 | if (callback(value)) {
|
1901 | result.add(value);
|
1902 | }
|
1903 | }
|
1904 |
|
1905 | return result;
|
1906 | }
|
1907 |
|
1908 | var Recoil_filterSet = filterSet;
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 | function invariant(condition, message) {
|
1922 | if (!condition) {
|
1923 | throw new Error(message);
|
1924 | }
|
1925 | }
|
1926 |
|
1927 | var invariant_1 = invariant;
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 | var Recoil_invariant = invariant_1;
|
1933 |
|
1934 |
|
1935 |
|
1936 |
|
1937 |
|
1938 |
|
1939 |
|
1940 |
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 | function mergeMaps(...maps) {
|
1946 | const result = new Map();
|
1947 |
|
1948 | for (let i = 0; i < maps.length; i++) {
|
1949 | const iterator = maps[i].keys();
|
1950 | let nextKey;
|
1951 |
|
1952 | while (!(nextKey = iterator.next()).done) {
|
1953 |
|
1954 | result.set(nextKey.value, maps[i].get(nextKey.value));
|
1955 | }
|
1956 | }
|
1957 | |
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 | return result;
|
1963 | }
|
1964 |
|
1965 | var Recoil_mergeMaps = mergeMaps;
|
1966 |
|
1967 | var _useMutableSource;
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 | const useMutableSource =
|
1973 | (_useMutableSource = react.useMutableSource) !== null && _useMutableSource !== void 0 ? _useMutableSource : react.unstable_useMutableSource;
|
1974 |
|
1975 | function mutableSourceExists() {
|
1976 | return useMutableSource && !(typeof window !== 'undefined' && window.$disableRecoilValueMutableSource_TEMP_HACK_DO_NOT_USE);
|
1977 | }
|
1978 |
|
1979 | var Recoil_mutableSource = {
|
1980 | mutableSourceExists,
|
1981 | useMutableSource
|
1982 | };
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 |
|
1989 |
|
1990 |
|
1991 |
|
1992 |
|
1993 |
|
1994 |
|
1995 |
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 |
|
2014 | const UNKNOWN_FUNCTION = '<unknown>';
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 |
|
2020 | function stackTraceParser(stackString) {
|
2021 | const lines = stackString.split('\n');
|
2022 | return lines.reduce((stack, line) => {
|
2023 | const parseResult = parseChrome(line) || parseWinjs(line) || parseGecko(line) || parseNode(line) || parseJSC(line);
|
2024 |
|
2025 | if (parseResult) {
|
2026 | stack.push(parseResult);
|
2027 | }
|
2028 |
|
2029 | return stack;
|
2030 | }, []);
|
2031 | }
|
2032 |
|
2033 | const chromeRe = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/|[a-z]:\\|\\\\).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
|
2034 | const chromeEvalRe = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
2035 |
|
2036 | function parseChrome(line) {
|
2037 | const parts = chromeRe.exec(line);
|
2038 |
|
2039 | if (!parts) {
|
2040 | return null;
|
2041 | }
|
2042 |
|
2043 | const isNative = parts[2] && parts[2].indexOf('native') === 0;
|
2044 |
|
2045 | const isEval = parts[2] && parts[2].indexOf('eval') === 0;
|
2046 |
|
2047 | const submatch = chromeEvalRe.exec(parts[2]);
|
2048 |
|
2049 | if (isEval && submatch != null) {
|
2050 |
|
2051 | parts[2] = submatch[1];
|
2052 |
|
2053 | parts[3] = submatch[2];
|
2054 |
|
2055 | parts[4] = submatch[3];
|
2056 | }
|
2057 |
|
2058 | return {
|
2059 | file: !isNative ? parts[2] : null,
|
2060 | methodName: parts[1] || UNKNOWN_FUNCTION,
|
2061 | arguments: isNative ? [parts[2]] : [],
|
2062 | lineNumber: parts[3] ? +parts[3] : null,
|
2063 | column: parts[4] ? +parts[4] : null
|
2064 | };
|
2065 | }
|
2066 |
|
2067 | const winjsRe = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
2068 |
|
2069 | function parseWinjs(line) {
|
2070 | const parts = winjsRe.exec(line);
|
2071 |
|
2072 | if (!parts) {
|
2073 | return null;
|
2074 | }
|
2075 |
|
2076 | return {
|
2077 | file: parts[2],
|
2078 | methodName: parts[1] || UNKNOWN_FUNCTION,
|
2079 | arguments: [],
|
2080 | lineNumber: +parts[3],
|
2081 | column: parts[4] ? +parts[4] : null
|
2082 | };
|
2083 | }
|
2084 |
|
2085 | const geckoRe = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
2086 | const geckoEvalRe = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
2087 |
|
2088 | function parseGecko(line) {
|
2089 | const parts = geckoRe.exec(line);
|
2090 |
|
2091 | if (!parts) {
|
2092 | return null;
|
2093 | }
|
2094 |
|
2095 | const isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
|
2096 | const submatch = geckoEvalRe.exec(parts[3]);
|
2097 |
|
2098 | if (isEval && submatch != null) {
|
2099 |
|
2100 | parts[3] = submatch[1];
|
2101 | parts[4] = submatch[2];
|
2102 | parts[5] = null;
|
2103 | }
|
2104 |
|
2105 | return {
|
2106 | file: parts[3],
|
2107 | methodName: parts[1] || UNKNOWN_FUNCTION,
|
2108 | arguments: parts[2] ? parts[2].split(',') : [],
|
2109 | lineNumber: parts[4] ? +parts[4] : null,
|
2110 | column: parts[5] ? +parts[5] : null
|
2111 | };
|
2112 | }
|
2113 |
|
2114 | const javaScriptCoreRe = /^\s*(?:([^@]*)(?:\((.*?)\))?@)?(\S.*?):(\d+)(?::(\d+))?\s*$/i;
|
2115 |
|
2116 | function parseJSC(line) {
|
2117 | const parts = javaScriptCoreRe.exec(line);
|
2118 |
|
2119 | if (!parts) {
|
2120 | return null;
|
2121 | }
|
2122 |
|
2123 | return {
|
2124 | file: parts[3],
|
2125 | methodName: parts[1] || UNKNOWN_FUNCTION,
|
2126 | arguments: [],
|
2127 | lineNumber: +parts[4],
|
2128 | column: parts[5] ? +parts[5] : null
|
2129 | };
|
2130 | }
|
2131 |
|
2132 | const nodeRe = /^\s*at (?:((?:\[object object\])?[^\\/]+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
2133 |
|
2134 | function parseNode(line) {
|
2135 | const parts = nodeRe.exec(line);
|
2136 |
|
2137 | if (!parts) {
|
2138 | return null;
|
2139 | }
|
2140 |
|
2141 | return {
|
2142 | file: parts[2],
|
2143 | methodName: parts[1] || UNKNOWN_FUNCTION,
|
2144 | arguments: [],
|
2145 | lineNumber: +parts[3],
|
2146 | column: parts[4] ? +parts[4] : null
|
2147 | };
|
2148 | }
|
2149 |
|
2150 | var Recoil_stackTraceParser = stackTraceParser;
|
2151 |
|
2152 | const {
|
2153 | useRef: useRef$1
|
2154 | } = react;
|
2155 |
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 | function useComponentName() {
|
2161 | const nameRef = useRef$1();
|
2162 |
|
2163 | if (process.env.NODE_ENV !== "production") {
|
2164 | if (Recoil_gkx_1('recoil_infer_component_names')) {
|
2165 | var _nameRef$current;
|
2166 |
|
2167 | if (nameRef.current === undefined) {
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 |
|
2176 | const frames = Recoil_stackTraceParser(new Error().stack);
|
2177 |
|
2178 | for (const {
|
2179 | methodName
|
2180 | } of frames) {
|
2181 |
|
2182 |
|
2183 | if (!methodName.match(/\buse[^\b]+$/)) {
|
2184 | return nameRef.current = methodName;
|
2185 | }
|
2186 | }
|
2187 |
|
2188 | nameRef.current = null;
|
2189 | }
|
2190 |
|
2191 | return (_nameRef$current = nameRef.current) !== null && _nameRef$current !== void 0 ? _nameRef$current : '<unable to determine component name>';
|
2192 | }
|
2193 | }
|
2194 |
|
2195 |
|
2196 | return "<component name not available>";
|
2197 | }
|
2198 |
|
2199 | var Recoil_useComponentName = useComponentName;
|
2200 |
|
2201 | const {
|
2202 | useCallback,
|
2203 | useEffect: useEffect$1,
|
2204 | useMemo: useMemo$1,
|
2205 | useRef: useRef$2,
|
2206 | useState: useState$1
|
2207 | } = react;
|
2208 |
|
2209 | const {
|
2210 | batchUpdates: batchUpdates$2
|
2211 | } = Recoil_Batching;
|
2212 |
|
2213 | const {
|
2214 | DEFAULT_VALUE: DEFAULT_VALUE$2,
|
2215 | getNode: getNode$2,
|
2216 | nodes: nodes$1
|
2217 | } = Recoil_Node;
|
2218 |
|
2219 | const {
|
2220 | useRecoilMutableSource: useRecoilMutableSource$1,
|
2221 | useStoreRef: useStoreRef$1
|
2222 | } = Recoil_RecoilRoot_react;
|
2223 |
|
2224 | const {
|
2225 | isRecoilValue: isRecoilValue$2
|
2226 | } = Recoil_RecoilValue$1;
|
2227 |
|
2228 | const {
|
2229 | AbstractRecoilValue: AbstractRecoilValue$2,
|
2230 | getRecoilValueAsLoadable: getRecoilValueAsLoadable$2,
|
2231 | setRecoilValue: setRecoilValue$2,
|
2232 | setRecoilValueLoadable: setRecoilValueLoadable$1,
|
2233 | setUnvalidatedRecoilValue: setUnvalidatedRecoilValue$1,
|
2234 | subscribeToRecoilValue: subscribeToRecoilValue$1
|
2235 | } = Recoil_RecoilValueInterface;
|
2236 |
|
2237 | const {
|
2238 | Snapshot: Snapshot$1,
|
2239 | cloneSnapshot: cloneSnapshot$1
|
2240 | } = Recoil_Snapshot$1;
|
2241 |
|
2242 | const {
|
2243 | setByAddingToSet: setByAddingToSet$2
|
2244 | } = Recoil_CopyOnWrite;
|
2245 |
|
2246 |
|
2247 |
|
2248 |
|
2249 |
|
2250 |
|
2251 |
|
2252 |
|
2253 |
|
2254 |
|
2255 |
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 | const {
|
2261 | mutableSourceExists: mutableSourceExists$1,
|
2262 | useMutableSource: useMutableSource$1
|
2263 | } = Recoil_mutableSource;
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 |
|
2269 |
|
2270 |
|
2271 |
|
2272 |
|
2273 | function handleLoadable(loadable, atom, storeRef) {
|
2274 |
|
2275 |
|
2276 |
|
2277 | if (loadable.state === 'hasValue') {
|
2278 | return loadable.contents;
|
2279 | } else if (loadable.state === 'loading') {
|
2280 | const promise = new Promise(resolve => {
|
2281 | storeRef.current.getState().suspendedComponentResolvers.add(resolve);
|
2282 | });
|
2283 | throw promise;
|
2284 | } else if (loadable.state === 'hasError') {
|
2285 | throw loadable.contents;
|
2286 | } else {
|
2287 | throw new Error(`Invalid value of loadable atom "${atom.key}"`);
|
2288 | }
|
2289 | }
|
2290 |
|
2291 | function validateRecoilValue(recoilValue, hookName) {
|
2292 | if (!isRecoilValue$2(recoilValue)) {
|
2293 | throw new Error(`Invalid argument to ${hookName}: expected an atom or selector but got ${String(recoilValue)}`);
|
2294 | }
|
2295 | }
|
2296 |
|
2297 | function useRecoilInterface_DEPRECATED() {
|
2298 | const storeRef = useStoreRef$1();
|
2299 | const [_, forceUpdate] = useState$1([]);
|
2300 | const recoilValuesUsed = useRef$2(new Set());
|
2301 | recoilValuesUsed.current = new Set();
|
2302 |
|
2303 | const previousSubscriptions = useRef$2(new Set());
|
2304 | const subscriptions = useRef$2(new Map());
|
2305 | const unsubscribeFrom = useCallback(key => {
|
2306 | const sub = subscriptions.current.get(key);
|
2307 |
|
2308 | if (sub) {
|
2309 | sub.release(storeRef.current);
|
2310 | subscriptions.current.delete(key);
|
2311 | }
|
2312 | }, [storeRef, subscriptions]);
|
2313 | const componentName = Recoil_useComponentName();
|
2314 | useEffect$1(() => {
|
2315 | const store = storeRef.current;
|
2316 |
|
2317 | function updateState(_state, key) {
|
2318 | if (!subscriptions.current.has(key)) {
|
2319 | return;
|
2320 | }
|
2321 |
|
2322 | forceUpdate([]);
|
2323 | }
|
2324 |
|
2325 | Recoil_differenceSets(recoilValuesUsed.current, previousSubscriptions.current).forEach(key => {
|
2326 | if (subscriptions.current.has(key)) {
|
2327 | Recoil_expectationViolation(`Double subscription to RecoilValue "${key}"`);
|
2328 | return;
|
2329 | }
|
2330 |
|
2331 | const sub = subscribeToRecoilValue$1(store, new AbstractRecoilValue$2(key), state => {
|
2332 | Recoil_Tracing.trace('RecoilValue subscription fired', key, () => {
|
2333 | updateState(state, key);
|
2334 | });
|
2335 | }, componentName);
|
2336 | subscriptions.current.set(key, sub);
|
2337 | Recoil_Tracing.trace('initial update on subscribing', key, () => {
|
2338 | |
2339 |
|
2340 |
|
2341 |
|
2342 |
|
2343 |
|
2344 |
|
2345 |
|
2346 |
|
2347 |
|
2348 |
|
2349 |
|
2350 |
|
2351 |
|
2352 |
|
2353 |
|
2354 |
|
2355 | const state = store.getState();
|
2356 |
|
2357 | if (state.nextTree) {
|
2358 | store.getState().queuedComponentCallbacks_DEPRECATED.push(Recoil_Tracing.wrap(() => {
|
2359 | updateState(store.getState(), key);
|
2360 | }));
|
2361 | } else {
|
2362 | updateState(store.getState(), key);
|
2363 | }
|
2364 | });
|
2365 | });
|
2366 | Recoil_differenceSets(previousSubscriptions.current, recoilValuesUsed.current).forEach(key => {
|
2367 | unsubscribeFrom(key);
|
2368 | });
|
2369 | previousSubscriptions.current = recoilValuesUsed.current;
|
2370 | });
|
2371 | useEffect$1(() => {
|
2372 | const subs = subscriptions.current;
|
2373 | return () => subs.forEach((_, key) => unsubscribeFrom(key));
|
2374 | }, [unsubscribeFrom]);
|
2375 | return useMemo$1(() => {
|
2376 | function useSetRecoilState(recoilState) {
|
2377 | if (process.env.NODE_ENV !== "production") {
|
2378 |
|
2379 | validateRecoilValue(recoilState, 'useSetRecoilState');
|
2380 | }
|
2381 |
|
2382 | return newValueOrUpdater => {
|
2383 | setRecoilValue$2(storeRef.current, recoilState, newValueOrUpdater);
|
2384 | };
|
2385 | }
|
2386 |
|
2387 | function useResetRecoilState(recoilState) {
|
2388 | if (process.env.NODE_ENV !== "production") {
|
2389 |
|
2390 | validateRecoilValue(recoilState, 'useResetRecoilState');
|
2391 | }
|
2392 |
|
2393 | return () => setRecoilValue$2(storeRef.current, recoilState, DEFAULT_VALUE$2);
|
2394 | }
|
2395 |
|
2396 | function useRecoilValueLoadable(recoilValue) {
|
2397 | if (process.env.NODE_ENV !== "production") {
|
2398 |
|
2399 | validateRecoilValue(recoilValue, 'useRecoilValueLoadable');
|
2400 | }
|
2401 |
|
2402 | if (!recoilValuesUsed.current.has(recoilValue.key)) {
|
2403 | recoilValuesUsed.current = setByAddingToSet$2(recoilValuesUsed.current, recoilValue.key);
|
2404 | }
|
2405 |
|
2406 |
|
2407 | return getRecoilValueAsLoadable$2(storeRef.current, recoilValue);
|
2408 | }
|
2409 |
|
2410 | function useRecoilValue(recoilValue) {
|
2411 | if (process.env.NODE_ENV !== "production") {
|
2412 |
|
2413 | validateRecoilValue(recoilValue, 'useRecoilValue');
|
2414 | }
|
2415 |
|
2416 | const loadable = useRecoilValueLoadable(recoilValue);
|
2417 |
|
2418 | return handleLoadable(loadable, recoilValue, storeRef);
|
2419 | }
|
2420 |
|
2421 | function useRecoilState(recoilState) {
|
2422 | if (process.env.NODE_ENV !== "production") {
|
2423 |
|
2424 | validateRecoilValue(recoilState, 'useRecoilState');
|
2425 | }
|
2426 |
|
2427 | return [useRecoilValue(recoilState), useSetRecoilState(recoilState)];
|
2428 | }
|
2429 |
|
2430 | function useRecoilStateLoadable(recoilState) {
|
2431 | if (process.env.NODE_ENV !== "production") {
|
2432 |
|
2433 | validateRecoilValue(recoilState, 'useRecoilStateLoadable');
|
2434 | }
|
2435 |
|
2436 | return [useRecoilValueLoadable(recoilState), useSetRecoilState(recoilState)];
|
2437 | }
|
2438 |
|
2439 | return {
|
2440 | getRecoilValue: useRecoilValue,
|
2441 | getRecoilValueLoadable: useRecoilValueLoadable,
|
2442 | getRecoilState: useRecoilState,
|
2443 | getRecoilStateLoadable: useRecoilStateLoadable,
|
2444 | getSetRecoilState: useSetRecoilState,
|
2445 | getResetRecoilState: useResetRecoilState
|
2446 | };
|
2447 | }, [recoilValuesUsed, storeRef]);
|
2448 | }
|
2449 |
|
2450 | const recoilComponentGetRecoilValueCount_FOR_TESTING = {
|
2451 | current: 0
|
2452 | };
|
2453 |
|
2454 | function useRecoilValueLoadable_MUTABLESOURCE(recoilValue) {
|
2455 | if (process.env.NODE_ENV !== "production") {
|
2456 |
|
2457 | validateRecoilValue(recoilValue, 'useRecoilValueLoadable');
|
2458 | }
|
2459 |
|
2460 | const storeRef = useStoreRef$1();
|
2461 | const getValue = useCallback(() => {
|
2462 | if (process.env.NODE_ENV !== "production") {
|
2463 | recoilComponentGetRecoilValueCount_FOR_TESTING.current++;
|
2464 | }
|
2465 |
|
2466 | return getRecoilValueAsLoadable$2(storeRef.current, recoilValue, storeRef.current.getState().currentTree);
|
2467 | }, [storeRef, recoilValue]);
|
2468 | const componentName = Recoil_useComponentName();
|
2469 | const subscribe = useCallback((_something, callback) => {
|
2470 | const store = storeRef.current;
|
2471 | const sub = subscribeToRecoilValue$1(store, recoilValue, () => {
|
2472 | Recoil_Tracing.trace('RecoilValue subscription fired', recoilValue.key, () => {
|
2473 | callback();
|
2474 | });
|
2475 | }, componentName);
|
2476 | return () => sub.release(store);
|
2477 | }, [recoilValue, storeRef, componentName]);
|
2478 | return useMutableSource$1(useRecoilMutableSource$1(), getValue, subscribe);
|
2479 | }
|
2480 |
|
2481 | function useRecoilValueLoadable_LEGACY(recoilValue) {
|
2482 | if (process.env.NODE_ENV !== "production") {
|
2483 |
|
2484 | validateRecoilValue(recoilValue, 'useRecoilValueLoadable');
|
2485 | }
|
2486 |
|
2487 | const storeRef = useStoreRef$1();
|
2488 | const [_, forceUpdate] = useState$1([]);
|
2489 | const componentName = Recoil_useComponentName();
|
2490 | useEffect$1(() => {
|
2491 | const store = storeRef.current;
|
2492 | const sub = subscribeToRecoilValue$1(store, recoilValue, _state => {
|
2493 | Recoil_Tracing.trace('RecoilValue subscription fired', recoilValue.key, () => {
|
2494 | forceUpdate([]);
|
2495 | });
|
2496 | }, componentName);
|
2497 | Recoil_Tracing.trace('initial update on subscribing', recoilValue.key, () => {
|
2498 | |
2499 |
|
2500 |
|
2501 |
|
2502 |
|
2503 |
|
2504 |
|
2505 |
|
2506 |
|
2507 |
|
2508 |
|
2509 |
|
2510 |
|
2511 |
|
2512 |
|
2513 |
|
2514 | const state = store.getState();
|
2515 |
|
2516 | if (state.nextTree) {
|
2517 | store.getState().queuedComponentCallbacks_DEPRECATED.push(Recoil_Tracing.wrap(() => {
|
2518 | forceUpdate([]);
|
2519 | }));
|
2520 | } else {
|
2521 | forceUpdate([]);
|
2522 | }
|
2523 | });
|
2524 | return () => sub.release(store);
|
2525 | }, [recoilValue, storeRef]);
|
2526 | return getRecoilValueAsLoadable$2(storeRef.current, recoilValue);
|
2527 | }
|
2528 |
|
2529 |
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 | function useRecoilValueLoadable(recoilValue) {
|
2535 | if (mutableSourceExists$1()) {
|
2536 |
|
2537 | return useRecoilValueLoadable_MUTABLESOURCE(recoilValue);
|
2538 | } else {
|
2539 |
|
2540 | return useRecoilValueLoadable_LEGACY(recoilValue);
|
2541 | }
|
2542 | }
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | function useRecoilValue(recoilValue) {
|
2552 | if (process.env.NODE_ENV !== "production") {
|
2553 |
|
2554 | validateRecoilValue(recoilValue, 'useRecoilValue');
|
2555 | }
|
2556 |
|
2557 | const storeRef = useStoreRef$1();
|
2558 | const loadable = useRecoilValueLoadable(recoilValue);
|
2559 |
|
2560 | return handleLoadable(loadable, recoilValue, storeRef);
|
2561 | }
|
2562 |
|
2563 |
|
2564 |
|
2565 |
|
2566 |
|
2567 |
|
2568 | function useSetRecoilState(recoilState) {
|
2569 | if (process.env.NODE_ENV !== "production") {
|
2570 |
|
2571 | validateRecoilValue(recoilState, 'useSetRecoilState');
|
2572 | }
|
2573 |
|
2574 | const storeRef = useStoreRef$1();
|
2575 | return useCallback(newValueOrUpdater => {
|
2576 | setRecoilValue$2(storeRef.current, recoilState, newValueOrUpdater);
|
2577 | }, [storeRef, recoilState]);
|
2578 | }
|
2579 |
|
2580 |
|
2581 |
|
2582 |
|
2583 |
|
2584 | function useResetRecoilState(recoilState) {
|
2585 | if (process.env.NODE_ENV !== "production") {
|
2586 |
|
2587 | validateRecoilValue(recoilState, 'useResetRecoilState');
|
2588 | }
|
2589 |
|
2590 | const storeRef = useStoreRef$1();
|
2591 | return useCallback(() => {
|
2592 | setRecoilValue$2(storeRef.current, recoilState, DEFAULT_VALUE$2);
|
2593 | }, [storeRef, recoilState]);
|
2594 | }
|
2595 |
|
2596 |
|
2597 |
|
2598 |
|
2599 |
|
2600 |
|
2601 |
|
2602 |
|
2603 |
|
2604 | function useRecoilState(recoilState) {
|
2605 | if (process.env.NODE_ENV !== "production") {
|
2606 |
|
2607 | validateRecoilValue(recoilState, 'useRecoilState');
|
2608 | }
|
2609 |
|
2610 | return [useRecoilValue(recoilState), useSetRecoilState(recoilState)];
|
2611 | }
|
2612 |
|
2613 |
|
2614 |
|
2615 |
|
2616 |
|
2617 |
|
2618 |
|
2619 | function useRecoilStateLoadable(recoilState) {
|
2620 | if (process.env.NODE_ENV !== "production") {
|
2621 |
|
2622 | validateRecoilValue(recoilState, 'useRecoilStateLoadable');
|
2623 | }
|
2624 |
|
2625 | return [useRecoilValueLoadable(recoilState), useSetRecoilState(recoilState)];
|
2626 | }
|
2627 |
|
2628 | function useTransactionSubscription(callback) {
|
2629 | const storeRef = useStoreRef$1();
|
2630 | useEffect$1(() => {
|
2631 | const sub = storeRef.current.subscribeToTransactions(callback);
|
2632 | return sub.release;
|
2633 | }, [callback, storeRef]);
|
2634 | }
|
2635 |
|
2636 | function externallyVisibleAtomValuesInState(state) {
|
2637 | const atomValues = state.atomValues;
|
2638 | const persistedAtomContentsValues = Recoil_mapMap(Recoil_filterMap(atomValues, (v, k) => {
|
2639 | const node = getNode$2(k);
|
2640 | const persistence = node.persistence_UNSTABLE;
|
2641 | return persistence != null && persistence.type !== 'none' && v.state === 'hasValue';
|
2642 | }), v => v.contents);
|
2643 |
|
2644 |
|
2645 | return Recoil_mergeMaps(state.nonvalidatedAtoms, persistedAtomContentsValues);
|
2646 | }
|
2647 |
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 |
|
2668 |
|
2669 |
|
2670 |
|
2671 |
|
2672 | function useTransactionObservation_DEPRECATED(callback) {
|
2673 | useTransactionSubscription(useCallback(store => {
|
2674 | let previousTree = store.getState().previousTree;
|
2675 | const currentTree = store.getState().currentTree;
|
2676 |
|
2677 | if (!previousTree) {
|
2678 | Recoil_recoverableViolation('Transaction subscribers notified without a previous tree being present -- this is a bug in Recoil');
|
2679 | previousTree = store.getState().currentTree;
|
2680 | }
|
2681 |
|
2682 | const atomValues = externallyVisibleAtomValuesInState(currentTree);
|
2683 | const previousAtomValues = externallyVisibleAtomValuesInState(previousTree);
|
2684 | const atomInfo = Recoil_mapMap(nodes$1, node => {
|
2685 | var _node$persistence_UNS, _node$persistence_UNS2, _node$persistence_UNS3, _node$persistence_UNS4;
|
2686 |
|
2687 | return {
|
2688 | persistence_UNSTABLE: {
|
2689 | type: (_node$persistence_UNS = (_node$persistence_UNS2 = node.persistence_UNSTABLE) === null || _node$persistence_UNS2 === void 0 ? void 0 : _node$persistence_UNS2.type) !== null && _node$persistence_UNS !== void 0 ? _node$persistence_UNS : 'none',
|
2690 | backButton: (_node$persistence_UNS3 = (_node$persistence_UNS4 = node.persistence_UNSTABLE) === null || _node$persistence_UNS4 === void 0 ? void 0 : _node$persistence_UNS4.backButton) !== null && _node$persistence_UNS3 !== void 0 ? _node$persistence_UNS3 : false
|
2691 | }
|
2692 | };
|
2693 | });
|
2694 |
|
2695 |
|
2696 | const modifiedAtoms = Recoil_filterSet(currentTree.dirtyAtoms, k => atomValues.has(k) || previousAtomValues.has(k));
|
2697 | callback({
|
2698 | atomValues,
|
2699 | previousAtomValues,
|
2700 | atomInfo,
|
2701 | modifiedAtoms,
|
2702 | transactionMetadata: { ...currentTree.transactionMetadata
|
2703 | }
|
2704 | });
|
2705 | }, [callback]));
|
2706 | }
|
2707 |
|
2708 | function useRecoilTransactionObserver(callback) {
|
2709 | useTransactionSubscription(useCallback(store => {
|
2710 | callback({
|
2711 | snapshot: cloneSnapshot$1(store, 'current'),
|
2712 | previousSnapshot: cloneSnapshot$1(store, 'previous')
|
2713 | });
|
2714 | }, [callback]));
|
2715 | }
|
2716 |
|
2717 |
|
2718 | function useRecoilSnapshot() {
|
2719 | const storeRef = useStoreRef$1();
|
2720 | const [snapshot, setSnapshot] = useState$1(() => cloneSnapshot$1(storeRef.current));
|
2721 | useTransactionSubscription(useCallback(store => setSnapshot(cloneSnapshot$1(store)), []));
|
2722 | return snapshot;
|
2723 | }
|
2724 |
|
2725 | function useGotoRecoilSnapshot() {
|
2726 | const storeRef = useStoreRef$1();
|
2727 | return useCallback(snapshot => {
|
2728 | var _storeState$nextTree;
|
2729 |
|
2730 | const storeState = storeRef.current.getState();
|
2731 | const prev = (_storeState$nextTree = storeState.nextTree) !== null && _storeState$nextTree !== void 0 ? _storeState$nextTree : storeState.currentTree;
|
2732 | const next = snapshot.getStore_INTERNAL().getState().currentTree;
|
2733 | batchUpdates$2(() => {
|
2734 | const keysToUpdate = new Set();
|
2735 |
|
2736 | for (const keys of [prev.atomValues.keys(), next.atomValues.keys()]) {
|
2737 | for (const key of keys) {
|
2738 | var _prev$atomValues$get, _next$atomValues$get;
|
2739 |
|
2740 | if (((_prev$atomValues$get = prev.atomValues.get(key)) === null || _prev$atomValues$get === void 0 ? void 0 : _prev$atomValues$get.contents) !== ((_next$atomValues$get = next.atomValues.get(key)) === null || _next$atomValues$get === void 0 ? void 0 : _next$atomValues$get.contents) && getNode$2(key).shouldRestoreFromSnapshots) {
|
2741 | keysToUpdate.add(key);
|
2742 | }
|
2743 | }
|
2744 | }
|
2745 |
|
2746 | keysToUpdate.forEach(key => {
|
2747 | setRecoilValueLoadable$1(storeRef.current, new AbstractRecoilValue$2(key), next.atomValues.has(key) ? Recoil_nullthrows(next.atomValues.get(key)) : DEFAULT_VALUE$2);
|
2748 | });
|
2749 | storeRef.current.replaceState(state => {
|
2750 | return { ...state,
|
2751 | stateID: snapshot.getID_INTERNAL()
|
2752 | };
|
2753 | });
|
2754 | });
|
2755 | }, [storeRef]);
|
2756 | }
|
2757 |
|
2758 | function useSetUnvalidatedAtomValues() {
|
2759 | const storeRef = useStoreRef$1();
|
2760 | return (values, transactionMetadata = {}) => {
|
2761 | batchUpdates$2(() => {
|
2762 | storeRef.current.addTransactionMetadata(transactionMetadata);
|
2763 | values.forEach((value, key) => setUnvalidatedRecoilValue$1(storeRef.current, new AbstractRecoilValue$2(key), value));
|
2764 | });
|
2765 | };
|
2766 | }
|
2767 |
|
2768 | class Sentinel {}
|
2769 |
|
2770 | const SENTINEL = new Sentinel();
|
2771 |
|
2772 | function useRecoilCallback(fn, deps) {
|
2773 | const storeRef = useStoreRef$1();
|
2774 | const gotoSnapshot = useGotoRecoilSnapshot();
|
2775 | return useCallback((...args) => {
|
2776 |
|
2777 | const snapshot = cloneSnapshot$1(storeRef.current);
|
2778 |
|
2779 | function set(recoilState, newValueOrUpdater) {
|
2780 | setRecoilValue$2(storeRef.current, recoilState, newValueOrUpdater);
|
2781 | }
|
2782 |
|
2783 | function reset(recoilState) {
|
2784 | setRecoilValue$2(storeRef.current, recoilState, DEFAULT_VALUE$2);
|
2785 | }
|
2786 |
|
2787 | let ret = SENTINEL;
|
2788 | batchUpdates$2(() => {
|
2789 |
|
2790 | ret = fn({
|
2791 | set,
|
2792 | reset,
|
2793 | snapshot,
|
2794 | gotoSnapshot
|
2795 | })(...args);
|
2796 | });
|
2797 | !!(ret instanceof Sentinel) ? process.env.NODE_ENV !== "production" ? Recoil_invariant(false, 'batchUpdates should return immediately') : Recoil_invariant(false) : void 0;
|
2798 | return ret;
|
2799 | }, deps != null ? [...deps, storeRef] : undefined // eslint-disable-line fb-www/react-hooks-deps
|
2800 | );
|
2801 | }
|
2802 |
|
2803 | var Recoil_Hooks = {
|
2804 | recoilComponentGetRecoilValueCount_FOR_TESTING,
|
2805 | useGotoRecoilSnapshot,
|
2806 | useRecoilCallback,
|
2807 | useRecoilInterface: useRecoilInterface_DEPRECATED,
|
2808 | useRecoilSnapshot,
|
2809 | useRecoilState,
|
2810 | useRecoilStateLoadable,
|
2811 | useRecoilTransactionObserver,
|
2812 | useRecoilValue,
|
2813 | useRecoilValueLoadable,
|
2814 | useResetRecoilState,
|
2815 | useSetRecoilState,
|
2816 | useSetUnvalidatedAtomValues,
|
2817 | useTransactionObservation_DEPRECATED,
|
2818 | useTransactionSubscription_DEPRECATED: useTransactionSubscription
|
2819 | };
|
2820 |
|
2821 | const {
|
2822 | useMemo: useMemo$2
|
2823 | } = react;
|
2824 |
|
2825 | const {
|
2826 | RecoilRoot: RecoilRoot$1,
|
2827 | useStoreRef: useStoreRef$2
|
2828 | } = Recoil_RecoilRoot_react;
|
2829 |
|
2830 | function useRecoilBridgeAcrossReactRoots() {
|
2831 | const store = useStoreRef$2().current;
|
2832 | return useMemo$2(() => {
|
2833 | function RecoilBridge({
|
2834 | children
|
2835 | }) {
|
2836 | return react.createElement(RecoilRoot$1, {
|
2837 | store_INTERNAL: store
|
2838 | }, children);
|
2839 | }
|
2840 |
|
2841 | return RecoilBridge;
|
2842 | }, [store]);
|
2843 | }
|
2844 |
|
2845 | var Recoil_useRecoilBridgeAcrossReactRoots = useRecoilBridgeAcrossReactRoots;
|
2846 |
|
2847 |
|
2848 |
|
2849 |
|
2850 |
|
2851 |
|
2852 |
|
2853 |
|
2854 |
|
2855 |
|
2856 |
|
2857 |
|
2858 |
|
2859 |
|
2860 |
|
2861 |
|
2862 | function isPromise(p) {
|
2863 | return !!p && typeof p.then === 'function';
|
2864 | }
|
2865 |
|
2866 | var Recoil_isPromise = isPromise;
|
2867 |
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 | const loadableAccessors = {
|
2873 | |
2874 |
|
2875 |
|
2876 |
|
2877 | getValue() {
|
2878 | if (this.state === 'loading' && Recoil_gkx_1('recoil_async_selector_refactor')) {
|
2879 | throw this.contents.then(({
|
2880 | __value
|
2881 | }) => __value);
|
2882 | }
|
2883 |
|
2884 | if (this.state !== 'hasValue') {
|
2885 | throw this.contents;
|
2886 | }
|
2887 |
|
2888 | return this.contents;
|
2889 | },
|
2890 |
|
2891 | toPromise() {
|
2892 | return this.state === 'hasValue' ? Promise.resolve(this.contents) : this.state === 'hasError' ? Promise.reject(this.contents) : Recoil_gkx_1('recoil_async_selector_refactor') ? this.contents.then(({
|
2893 | __value
|
2894 | }) => __value) : this.contents;
|
2895 | },
|
2896 |
|
2897 | valueMaybe() {
|
2898 | return this.state === 'hasValue' ? this.contents : undefined;
|
2899 | },
|
2900 |
|
2901 | valueOrThrow() {
|
2902 | if (this.state !== 'hasValue') {
|
2903 | throw new Error(`Loadable expected value, but in "${this.state}" state`);
|
2904 | }
|
2905 |
|
2906 | return this.contents;
|
2907 | },
|
2908 |
|
2909 | errorMaybe() {
|
2910 | return this.state === 'hasError' ? this.contents : undefined;
|
2911 | },
|
2912 |
|
2913 | errorOrThrow() {
|
2914 | if (this.state !== 'hasError') {
|
2915 | throw new Error(`Loadable expected error, but in "${this.state}" state`);
|
2916 | }
|
2917 |
|
2918 | return this.contents;
|
2919 | },
|
2920 |
|
2921 | promiseMaybe() {
|
2922 | return this.state === 'loading' ? Recoil_gkx_1('recoil_async_selector_refactor') ? this.contents.then(({
|
2923 | __value
|
2924 | }) => __value) : this.contents : undefined;
|
2925 | },
|
2926 |
|
2927 | promiseOrThrow() {
|
2928 | if (this.state !== 'loading') {
|
2929 | throw new Error(`Loadable expected promise, but in "${this.state}" state`);
|
2930 | }
|
2931 |
|
2932 | return Recoil_gkx_1('recoil_async_selector_refactor') ? this.contents.then(({
|
2933 | __value
|
2934 | }) => __value) : this.contents;
|
2935 | },
|
2936 |
|
2937 |
|
2938 |
|
2939 |
|
2940 | map(map) {
|
2941 | if (this.state === 'hasError') {
|
2942 | return this;
|
2943 | }
|
2944 |
|
2945 | if (this.state === 'hasValue') {
|
2946 | try {
|
2947 | const next = map(this.contents);
|
2948 |
|
2949 | return Recoil_isPromise(next) ? loadableWithPromise(next) : loadableWithValue(next);
|
2950 | } catch (e) {
|
2951 | return Recoil_isPromise(e) ?
|
2952 |
|
2953 | loadableWithPromise(e.next(() => map(this.contents))) : loadableWithError(e);
|
2954 | }
|
2955 | }
|
2956 |
|
2957 | if (this.state === 'loading') {
|
2958 | return loadableWithPromise(this.contents
|
2959 | .then(map).catch(e => {
|
2960 | if (Recoil_isPromise(e)) {
|
2961 |
|
2962 | return e.then(() => map(this.contents));
|
2963 | }
|
2964 |
|
2965 | throw e;
|
2966 | }));
|
2967 | }
|
2968 |
|
2969 | throw new Error('Invalid Loadable state');
|
2970 | }
|
2971 |
|
2972 | };
|
2973 |
|
2974 | function loadableWithValue(value) {
|
2975 |
|
2976 | return Object.freeze({
|
2977 | state: 'hasValue',
|
2978 | contents: value,
|
2979 | ...loadableAccessors
|
2980 | });
|
2981 | }
|
2982 |
|
2983 | function loadableWithError(error) {
|
2984 | return Object.freeze({
|
2985 | state: 'hasError',
|
2986 | contents: error,
|
2987 | ...loadableAccessors
|
2988 | });
|
2989 | }
|
2990 |
|
2991 | function loadableWithPromise(promise) {
|
2992 | return Object.freeze({
|
2993 | state: 'loading',
|
2994 | contents: promise,
|
2995 | ...loadableAccessors
|
2996 | });
|
2997 | }
|
2998 |
|
2999 | function loadableLoading() {
|
3000 | return loadableWithPromise(new Promise(() => {}));
|
3001 | }
|
3002 |
|
3003 | function loadableAll(inputs) {
|
3004 | return inputs.every(i => i.state === 'hasValue') ? loadableWithValue(inputs.map(i => i.contents)) : inputs.some(i => i.state === 'hasError') ? loadableWithError(
|
3005 | Recoil_nullthrows(inputs.find(i => i.state === 'hasError'), 'Invalid loadable passed to loadableAll').contents) : loadableWithPromise(Recoil_gkx_1('recoil_async_selector_refactor') ? Promise.all(inputs.map(i => i.contents)).then(value => ({
|
3006 | __value: value
|
3007 | })) : Promise.all(inputs.map(i => i.contents)));
|
3008 | }
|
3009 |
|
3010 | var Recoil_Loadable = {
|
3011 | loadableWithValue,
|
3012 | loadableWithError,
|
3013 | loadableWithPromise,
|
3014 | loadableLoading,
|
3015 | loadableAll
|
3016 | };
|
3017 |
|
3018 |
|
3019 |
|
3020 |
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 |
|
3026 |
|
3027 |
|
3028 |
|
3029 | const ARRAY_BUFFER_VIEW_TYPES = [Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array, DataView];
|
3030 |
|
3031 | function isArrayBufferView(value) {
|
3032 | for (const type of ARRAY_BUFFER_VIEW_TYPES) {
|
3033 | if (value instanceof type) {
|
3034 | return true;
|
3035 | }
|
3036 | }
|
3037 |
|
3038 | return false;
|
3039 | }
|
3040 |
|
3041 | var Recoil_isArrayBufferView = isArrayBufferView;
|
3042 |
|
3043 |
|
3044 |
|
3045 |
|
3046 |
|
3047 |
|
3048 |
|
3049 |
|
3050 |
|
3051 |
|
3052 |
|
3053 |
|
3054 | function isNode(object) {
|
3055 | var _ownerDocument, _doc$defaultView;
|
3056 |
|
3057 | if (typeof window === 'undefined') {
|
3058 | return false;
|
3059 | }
|
3060 |
|
3061 | const doc = object != null ? (_ownerDocument = object.ownerDocument) !== null && _ownerDocument !== void 0 ? _ownerDocument : object : document;
|
3062 | const defaultView = (_doc$defaultView = doc.defaultView) !== null && _doc$defaultView !== void 0 ? _doc$defaultView : window;
|
3063 | return !!(object != null && (typeof defaultView.Node === 'function' ? object instanceof defaultView.Node : typeof object === 'object' && typeof object.nodeType === 'number' && typeof object.nodeName === 'string'));
|
3064 | }
|
3065 |
|
3066 | var Recoil_isNode = isNode;
|
3067 |
|
3068 | const isSSR = typeof window === 'undefined';
|
3069 | const isReactNative = typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
|
3070 |
|
3071 | function shouldNotBeFrozen(value) {
|
3072 |
|
3073 | if (value === null || typeof value !== 'object') {
|
3074 | return true;
|
3075 | }
|
3076 |
|
3077 |
|
3078 | switch (typeof value.$$typeof) {
|
3079 | case 'symbol':
|
3080 | return true;
|
3081 |
|
3082 | case 'number':
|
3083 | return true;
|
3084 | }
|
3085 |
|
3086 |
|
3087 | if (value['@@__IMMUTABLE_ITERABLE__@@'] != null || value['@@__IMMUTABLE_KEYED__@@'] != null || value['@@__IMMUTABLE_INDEXED__@@'] != null || value['@@__IMMUTABLE_ORDERED__@@'] != null || value['@@__IMMUTABLE_RECORD__@@'] != null) {
|
3088 | return true;
|
3089 | }
|
3090 |
|
3091 |
|
3092 | if (Recoil_isNode(value)) {
|
3093 | return true;
|
3094 | }
|
3095 |
|
3096 | if (Recoil_isPromise(value)) {
|
3097 | return true;
|
3098 | }
|
3099 |
|
3100 | if (Recoil_isArrayBufferView(value)) {
|
3101 | return true;
|
3102 | }
|
3103 |
|
3104 |
|
3105 | if (!isSSR && !isReactNative && (value === window || value instanceof Window)) {
|
3106 | return true;
|
3107 | }
|
3108 |
|
3109 | return false;
|
3110 | }
|
3111 |
|
3112 |
|
3113 |
|
3114 |
|
3115 | function deepFreezeValue(value) {
|
3116 | if (typeof value !== 'object' || shouldNotBeFrozen(value)) {
|
3117 | return;
|
3118 | }
|
3119 |
|
3120 | Object.freeze(value);
|
3121 |
|
3122 | for (const key in value) {
|
3123 | if (Object.prototype.hasOwnProperty.call(value, key)) {
|
3124 | const prop = value[key];
|
3125 |
|
3126 | if (typeof prop === 'object' && prop != null && !Object.isFrozen(prop)) {
|
3127 | deepFreezeValue(prop);
|
3128 | }
|
3129 | }
|
3130 | }
|
3131 |
|
3132 | Object.seal(value);
|
3133 | }
|
3134 |
|
3135 | var Recoil_deepFreezeValue = deepFreezeValue;
|
3136 |
|
3137 |
|
3138 |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 |
|
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 | function cacheMostRecent() {
|
3151 | let mostRecentKey;
|
3152 | let mostRecentValue;
|
3153 | const cache = {
|
3154 | get: key => key === mostRecentKey ? mostRecentValue : undefined,
|
3155 | set: (key, value) => {
|
3156 | mostRecentKey = key;
|
3157 | mostRecentValue = value;
|
3158 | return cache;
|
3159 | }
|
3160 | };
|
3161 | return cache;
|
3162 | }
|
3163 |
|
3164 | var Recoil_cacheMostRecent = cacheMostRecent;
|
3165 |
|
3166 |
|
3167 |
|
3168 |
|
3169 |
|
3170 |
|
3171 |
|
3172 |
|
3173 |
|
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 |
|
3182 | const LEAF = Symbol('ArrayKeyedMap');
|
3183 | const emptyMap = new Map();
|
3184 |
|
3185 | class ArrayKeyedMap {
|
3186 |
|
3187 | constructor(existing) {
|
3188 | this._base = new Map();
|
3189 |
|
3190 | if (existing instanceof ArrayKeyedMap) {
|
3191 | for (const [k, v] of existing.entries()) {
|
3192 | this.set(k, v);
|
3193 | }
|
3194 | } else if (existing) {
|
3195 | for (const [k, v] of existing) {
|
3196 | this.set(k, v);
|
3197 | }
|
3198 | }
|
3199 |
|
3200 | return this;
|
3201 | }
|
3202 |
|
3203 | get(key) {
|
3204 | const ks = Array.isArray(key) ? key : [key];
|
3205 | let map = this._base;
|
3206 | ks.forEach(k => {
|
3207 | var _map$get;
|
3208 |
|
3209 | map = (_map$get = map.get(k)) !== null && _map$get !== void 0 ? _map$get : emptyMap;
|
3210 | });
|
3211 | return map === undefined ? undefined : map.get(LEAF);
|
3212 | }
|
3213 |
|
3214 | set(key, value) {
|
3215 | const ks = Array.isArray(key) ? key : [key];
|
3216 | let map = this._base;
|
3217 | let next = map;
|
3218 | ks.forEach(k => {
|
3219 | next = map.get(k);
|
3220 |
|
3221 | if (!next) {
|
3222 | next = new Map();
|
3223 | map.set(k, next);
|
3224 | }
|
3225 |
|
3226 | map = next;
|
3227 | });
|
3228 | next.set(LEAF, value);
|
3229 | return this;
|
3230 | }
|
3231 |
|
3232 | delete(key) {
|
3233 | const ks = Array.isArray(key) ? key : [key];
|
3234 | let map = this._base;
|
3235 | let next = map;
|
3236 | ks.forEach(k => {
|
3237 | next = map.get(k);
|
3238 |
|
3239 | if (!next) {
|
3240 | next = new Map();
|
3241 | map.set(k, next);
|
3242 | }
|
3243 |
|
3244 | map = next;
|
3245 | });
|
3246 | next.delete(LEAF);
|
3247 |
|
3248 | return this;
|
3249 | }
|
3250 |
|
3251 | entries() {
|
3252 | const answer = [];
|
3253 |
|
3254 | function recurse(level, prefix) {
|
3255 | level.forEach((v, k) => {
|
3256 | if (k === LEAF) {
|
3257 | answer.push([prefix, v]);
|
3258 | } else {
|
3259 | recurse(v, prefix.concat(k));
|
3260 | }
|
3261 | });
|
3262 | }
|
3263 |
|
3264 | recurse(this._base, []);
|
3265 | return answer.values();
|
3266 | }
|
3267 |
|
3268 | toBuiltInMap() {
|
3269 | return new Map(this.entries());
|
3270 | }
|
3271 |
|
3272 | }
|
3273 |
|
3274 | var Recoil_ArrayKeyedMap = ArrayKeyedMap;
|
3275 |
|
3276 | function cacheWithReferenceEquality() {
|
3277 | return new Recoil_ArrayKeyedMap();
|
3278 | }
|
3279 |
|
3280 | var Recoil_cacheWithReferenceEquality = cacheWithReferenceEquality;
|
3281 |
|
3282 | const TIME_WARNING_THRESHOLD_MS = 15;
|
3283 |
|
3284 | function stringify(x, opt, key) {
|
3285 |
|
3286 |
|
3287 | if (typeof x === 'string' && !x.includes('"') && !x.includes('\\')) {
|
3288 | return `"${x}"`;
|
3289 | }
|
3290 |
|
3291 |
|
3292 | switch (typeof x) {
|
3293 | case 'undefined':
|
3294 | return '';
|
3295 |
|
3296 |
|
3297 | case 'boolean':
|
3298 | return x ? 'true' : 'false';
|
3299 |
|
3300 | case 'number':
|
3301 | case 'symbol':
|
3302 |
|
3303 | return String(x);
|
3304 |
|
3305 | case 'string':
|
3306 |
|
3307 | return JSON.stringify(x);
|
3308 |
|
3309 | case 'function':
|
3310 | if ((opt === null || opt === void 0 ? void 0 : opt.allowFunctions) !== true) {
|
3311 | throw new Error('Attempt to serialize function in a Recoil cache key');
|
3312 | }
|
3313 |
|
3314 | return `__FUNCTION(${x.name})__`;
|
3315 | }
|
3316 |
|
3317 | if (x === null) {
|
3318 | return 'null';
|
3319 | }
|
3320 |
|
3321 |
|
3322 | if (typeof x !== 'object') {
|
3323 | var _JSON$stringify;
|
3324 |
|
3325 | return (_JSON$stringify = JSON.stringify(x)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : '';
|
3326 | }
|
3327 |
|
3328 |
|
3329 | if (Recoil_isPromise(x)) {
|
3330 | return '__PROMISE__';
|
3331 | }
|
3332 |
|
3333 |
|
3334 | if (Array.isArray(x)) {
|
3335 | return `[${x.map((v, i) => stringify(v, opt, i.toString()))}]`;
|
3336 | }
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 |
|
3342 | if (typeof x.toJSON === 'function') {
|
3343 |
|
3344 | return stringify(x.toJSON(key), opt, key);
|
3345 | }
|
3346 |
|
3347 |
|
3348 |
|
3349 | if (x instanceof Map) {
|
3350 | const obj = {};
|
3351 |
|
3352 | for (const [k, v] of x) {
|
3353 |
|
3354 | obj[typeof k === 'string' ? k : stringify(k, opt)] = v;
|
3355 | }
|
3356 |
|
3357 | return stringify(obj, opt, key);
|
3358 | }
|
3359 |
|
3360 |
|
3361 |
|
3362 | if (x instanceof Set) {
|
3363 | return stringify(Array.from(x).sort((a, b) => stringify(a, opt).localeCompare(stringify(b, opt))), opt, key);
|
3364 | }
|
3365 |
|
3366 |
|
3367 | if (x[Symbol.iterator] != null && typeof x[Symbol.iterator] === 'function') {
|
3368 |
|
3369 | return stringify(Array.from(x), opt, key);
|
3370 | }
|
3371 |
|
3372 |
|
3373 | return `{${Object.keys(x).filter(key => x[key] !== undefined).sort() // stringify the key to add quotes and escape any nested slashes or quotes.
|
3374 | .map(key => `${stringify(key, opt)}:${stringify(x[key], opt, key)}`).join(',')}}`;
|
3375 | }
|
3376 |
|
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 |
|
3385 |
|
3386 |
|
3387 | function stableStringify(x, opt = {
|
3388 | allowFunctions: false
|
3389 | }) {
|
3390 | if (process.env.NODE_ENV !== "production") {
|
3391 | if (typeof window !== 'undefined') {
|
3392 | const startTime = window.performance ? window.performance.now() : 0;
|
3393 | const str = stringify(x, opt);
|
3394 | const endTime = window.performance ? window.performance.now() : 0;
|
3395 |
|
3396 | if (endTime - startTime > TIME_WARNING_THRESHOLD_MS) {
|
3397 |
|
3398 | console.groupCollapsed(`Recoil: Spent ${endTime - startTime}ms computing a cache key`);
|
3399 | console.warn(x, str);
|
3400 | console.groupEnd();
|
3401 |
|
3402 | }
|
3403 |
|
3404 | return str;
|
3405 | }
|
3406 | }
|
3407 |
|
3408 | return stringify(x, opt);
|
3409 | }
|
3410 |
|
3411 | var Recoil_stableStringify = stableStringify;
|
3412 |
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 |
|
3423 |
|
3424 |
|
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 | function cacheWithValueEquality() {
|
3430 | const map = new Map();
|
3431 | const cache = {
|
3432 | get: key => map.get(Recoil_stableStringify(key)),
|
3433 | set: (key, value) => {
|
3434 | map.set(Recoil_stableStringify(key), value);
|
3435 | return cache;
|
3436 | },
|
3437 | map
|
3438 |
|
3439 | };
|
3440 | return cache;
|
3441 | }
|
3442 |
|
3443 | var Recoil_cacheWithValueEquality = cacheWithValueEquality;
|
3444 |
|
3445 |
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 | function nodeCacheMostRecent() {
|
3454 | let mostRecent;
|
3455 | return {
|
3456 | get: (getNodeValue, handlers) => {
|
3457 | if (mostRecent === undefined) {
|
3458 | return undefined;
|
3459 | }
|
3460 |
|
3461 | for (const [nodeKey, nodeValue] of mostRecent.route) {
|
3462 | var _handlers$onCacheHit;
|
3463 |
|
3464 | if (getNodeValue(nodeKey) !== nodeValue) {
|
3465 | return undefined;
|
3466 | }
|
3467 |
|
3468 | handlers === null || handlers === void 0 ? void 0 : (_handlers$onCacheHit = handlers.onCacheHit) === null || _handlers$onCacheHit === void 0 ? void 0 : _handlers$onCacheHit.call(handlers, nodeKey);
|
3469 | }
|
3470 |
|
3471 | return mostRecent.value;
|
3472 | },
|
3473 | set: (route, value) => {
|
3474 | mostRecent = {
|
3475 | route,
|
3476 | value
|
3477 | };
|
3478 | },
|
3479 | getRoot: () => mostRecent
|
3480 | };
|
3481 | }
|
3482 |
|
3483 | var Recoil_nodeCacheMostRecent = nodeCacheMostRecent;
|
3484 |
|
3485 | function setInTreeCache(root, route, result) {
|
3486 | if (root == null) {
|
3487 | if (route.length === 0) {
|
3488 | return {
|
3489 | type: 'result',
|
3490 | result
|
3491 | };
|
3492 | } else {
|
3493 | const [path, ...rest] = route;
|
3494 | const [nodeKey, value] = path;
|
3495 | const ret = {
|
3496 | type: 'branch',
|
3497 | nodeKey,
|
3498 | branches: new Map([[value, setInTreeCache(null, rest, result)]])
|
3499 | };
|
3500 | return ret;
|
3501 | }
|
3502 | } else {
|
3503 | if (route.length === 0) {
|
3504 | !(root.type === 'result') ? process.env.NODE_ENV !== "production" ? Recoil_invariant(false, 'Existing cache must have a result type node at the end of the route') : Recoil_invariant(false) : void 0;
|
3505 |
|
3506 | if (root.result && root.result.state === 'loading') {
|
3507 | const ret = {
|
3508 | type: 'result',
|
3509 | result
|
3510 | };
|
3511 | return ret;
|
3512 | } else {
|
3513 | !(root.result === result) ? process.env.NODE_ENV !== "production" ? Recoil_invariant(false, 'Existing cache must have the same result at the end of the route') : Recoil_invariant(false) : void 0;
|
3514 | const ret = root;
|
3515 | return ret;
|
3516 | }
|
3517 | } else {
|
3518 | const [path, ...rest] = route;
|
3519 | const [nodeKey, value] = path;
|
3520 | !(root.type === 'branch') ? process.env.NODE_ENV !== "production" ? Recoil_invariant(false, 'Existing cache must have a branch midway through the route') : Recoil_invariant(false) : void 0;
|
3521 | !(root.nodeKey === nodeKey) ? process.env.NODE_ENV !== "production" ? Recoil_invariant(false, 'Existing cache must have a branch for the same nodeKey midway through the route') : Recoil_invariant(false) : void 0;
|
3522 | root.branches.set(value, setInTreeCache(root.branches.get(value), rest, result));
|
3523 | return root;
|
3524 | }
|
3525 | }
|
3526 | }
|
3527 |
|
3528 | function getFromTreeCache(root, getNodeValue, handlers) {
|
3529 | var _handlers$onCacheHit;
|
3530 |
|
3531 | if (root == null) {
|
3532 | return undefined;
|
3533 | }
|
3534 |
|
3535 | if (root.type === 'result') {
|
3536 | return root.result;
|
3537 | }
|
3538 |
|
3539 | handlers === null || handlers === void 0 ? void 0 : (_handlers$onCacheHit = handlers.onCacheHit) === null || _handlers$onCacheHit === void 0 ? void 0 : _handlers$onCacheHit.call(handlers, root.nodeKey);
|
3540 | const nodeValue = getNodeValue(root.nodeKey);
|
3541 | return getFromTreeCache(root.branches.get(nodeValue), getNodeValue, handlers);
|
3542 | }
|
3543 |
|
3544 | var Recoil_TreeNodeCache = {
|
3545 | setInTreeCache,
|
3546 | getFromTreeCache
|
3547 | };
|
3548 |
|
3549 | const {
|
3550 | getFromTreeCache: getFromTreeCache$1,
|
3551 | setInTreeCache: setInTreeCache$1
|
3552 | } = Recoil_TreeNodeCache;
|
3553 |
|
3554 | function treeCacheReferenceEquality() {
|
3555 | let treeRoot;
|
3556 | return {
|
3557 | get: (getNodeValue, handlers) => getFromTreeCache$1(treeRoot, getNodeValue, handlers),
|
3558 | set: (route, result) => {
|
3559 | treeRoot = setInTreeCache$1(treeRoot, route, result);
|
3560 | },
|
3561 | getRoot: () => treeRoot
|
3562 | };
|
3563 | }
|
3564 |
|
3565 | var Recoil_treeCacheReferenceEquality = treeCacheReferenceEquality;
|
3566 |
|
3567 | const {
|
3568 | getFromTreeCache: getFromTreeCache$2,
|
3569 | setInTreeCache: setInTreeCache$2
|
3570 | } = Recoil_TreeNodeCache;
|
3571 |
|
3572 | function treeCacheValueEquality() {
|
3573 | let treeRoot;
|
3574 | return {
|
3575 | get: (getNodeValue, handlers) => getFromTreeCache$2(treeRoot, nodeKey => Recoil_stableStringify(getNodeValue(nodeKey)), handlers),
|
3576 | set: (route, result) => {
|
3577 | treeRoot = setInTreeCache$2(treeRoot, route.map(([nodeKey, nodeValue]) => [nodeKey, Recoil_stableStringify(nodeValue)]), result);
|
3578 | },
|
3579 | getRoot: () => treeRoot
|
3580 | };
|
3581 | }
|
3582 |
|
3583 | var Recoil_treeCacheValueEquality = treeCacheValueEquality;
|
3584 |
|
3585 |
|
3586 |
|
3587 |
|
3588 |
|
3589 |
|
3590 |
|
3591 |
|
3592 |
|
3593 |
|
3594 |
|
3595 |
|
3596 |
|
3597 | function startPerfBlock(_id) {
|
3598 | return () => null;
|
3599 | }
|
3600 |
|
3601 | var Recoil_PerformanceTimings = {
|
3602 | startPerfBlock
|
3603 | };
|
3604 |
|
3605 | const {
|
3606 | loadableWithError: loadableWithError$1,
|
3607 | loadableWithPromise: loadableWithPromise$1,
|
3608 | loadableWithValue: loadableWithValue$1
|
3609 | } = Recoil_Loadable;
|
3610 |
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 |
|
3616 |
|
3617 |
|
3618 |
|
3619 |
|
3620 |
|
3621 |
|
3622 |
|
3623 | const {
|
3624 | getNodeLoadable: getNodeLoadable$2,
|
3625 | peekNodeLoadable: peekNodeLoadable$2,
|
3626 | setNodeValue: setNodeValue$3
|
3627 | } = Recoil_FunctionalCore;
|
3628 |
|
3629 | const {
|
3630 | saveDependencyMapToStore: saveDependencyMapToStore$3
|
3631 | } = Recoil_Graph;
|
3632 |
|
3633 | const {
|
3634 | DEFAULT_VALUE: DEFAULT_VALUE$3,
|
3635 | RecoilValueNotReady: RecoilValueNotReady$2,
|
3636 | registerNode: registerNode$1
|
3637 | } = Recoil_Node;
|
3638 |
|
3639 | const {
|
3640 | isRecoilValue: isRecoilValue$3
|
3641 | } = Recoil_RecoilValue$1;
|
3642 |
|
3643 | const {
|
3644 | AbstractRecoilValue: AbstractRecoilValue$3
|
3645 | } = Recoil_RecoilValue$1;
|
3646 |
|
3647 | const {
|
3648 | setRecoilValueLoadable: setRecoilValueLoadable$2
|
3649 | } = Recoil_RecoilValueInterface;
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 |
|
3656 |
|
3657 | const {
|
3658 | startPerfBlock: startPerfBlock$1
|
3659 | } = Recoil_PerformanceTimings;
|
3660 |
|
3661 |
|
3662 | const emptySet$1 = Object.freeze(new Set());
|
3663 | const dependencyStack = [];
|
3664 |
|
3665 | const waitingStores = new Map();
|
3666 |
|
3667 |
|
3668 | const getNewExecutionId = (() => {
|
3669 | let executionId = 0;
|
3670 | return () => executionId++;
|
3671 | })();
|
3672 |
|
3673 | function getInitialExecutionInfo() {
|
3674 | return {
|
3675 | depValuesDiscoveredSoFarDuringAsyncWork: null,
|
3676 | latestLoadable: null,
|
3677 | latestExecutionId: null,
|
3678 | stateVersion: null
|
3679 | };
|
3680 | }
|
3681 |
|
3682 | function selector(options) {
|
3683 | const {
|
3684 | key,
|
3685 | get,
|
3686 | cacheImplementation_UNSTABLE: cacheImplementation
|
3687 | } = options;
|
3688 | const set = options.set != null ? options.set : undefined; // flow
|
3689 |
|
3690 | /**
|
3691 | * HACK: doing this as a way to map given cache to corresponding tree cache
|
3692 | */
|
3693 |
|
3694 | const cache = cacheImplementation === Recoil_cacheWithReferenceEquality ? Recoil_treeCacheReferenceEquality() : cacheImplementation === Recoil_cacheWithValueEquality ? Recoil_treeCacheValueEquality() : cacheImplementation === Recoil_cacheMostRecent ? Recoil_nodeCacheMostRecent() : Recoil_treeCacheReferenceEquality();
|
3695 | const executionInfo = getInitialExecutionInfo();
|
3696 |
|
3697 | function initSelector(store) {
|
3698 | store.getState().knownSelectors.add(key);
|
3699 | }
|
3700 |
|
3701 | function notifyStoreWhenAsyncSettles(store, loadable, executionId) {
|
3702 | if (loadable.state === 'loading') {
|
3703 | let stores = waitingStores.get(executionId);
|
3704 |
|
3705 | if (stores == null) {
|
3706 | waitingStores.set(executionId, stores = new Set());
|
3707 | }
|
3708 |
|
3709 | stores.add(store);
|
3710 | }
|
3711 | }
|
3712 | |
3713 |
|
3714 |
|
3715 |
|
3716 |
|
3717 |
|
3718 | function notifyStoresOfSettledAsync(newLoadable, executionId) {
|
3719 | const stores = waitingStores.get(executionId);
|
3720 |
|
3721 | if (stores !== undefined) {
|
3722 | for (const store of stores) {
|
3723 | setRecoilValueLoadable$2(store, new AbstractRecoilValue$3(key), newLoadable);
|
3724 | }
|
3725 |
|
3726 | waitingStores.delete(executionId);
|
3727 | }
|
3728 | }
|
3729 |
|
3730 | function getCachedNodeLoadable(store, state, key) {
|
3731 | if (state.atomValues.has(key)) {
|
3732 | return [new Map(), Recoil_nullthrows(state.atomValues.get(key))];
|
3733 | }
|
3734 |
|
3735 | const [, loadable] = getNodeLoadable$2(store, state, key);
|
3736 | const isKeyPointingToSelector = store.getState().knownSelectors.has(key);
|
3737 |
|
3738 | if (loadable.state !== 'loading' && isKeyPointingToSelector) {
|
3739 | state.atomValues.set(key, loadable);
|
3740 | }
|
3741 |
|
3742 | return [new Map(), loadable];
|
3743 | }
|
3744 | |
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 |
|
3753 |
|
3754 |
|
3755 |
|
3756 |
|
3757 |
|
3758 |
|
3759 |
|
3760 |
|
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 |
|
3767 |
|
3768 |
|
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 | function wrapPendingPromise(store, promise, state, depValues, executionId) {
|
3776 | return promise.then(value => {
|
3777 | const loadable = loadableWithValue$1(value);
|
3778 | maybeFreezeValue(value);
|
3779 | setCache(state, depValuesToDepRoute(depValues), loadable);
|
3780 | setLoadableInStoreToNotifyDeps(loadable, executionId);
|
3781 | return {
|
3782 | __value: value,
|
3783 | __key: key
|
3784 | };
|
3785 | }).catch(errorOrPromise => {
|
3786 | if (isLatestExecution(executionId)) {
|
3787 | updateExecutionInfoDepValues(depValues, executionId);
|
3788 | }
|
3789 |
|
3790 | if (Recoil_isPromise(errorOrPromise)) {
|
3791 | return wrapPendingDependencyPromise(store, errorOrPromise, state, depValues, executionId);
|
3792 | }
|
3793 |
|
3794 | const loadable = loadableWithError$1(errorOrPromise);
|
3795 | maybeFreezeValue(errorOrPromise);
|
3796 | setCache(state, depValuesToDepRoute(depValues), loadable);
|
3797 | setLoadableInStoreToNotifyDeps(loadable, executionId);
|
3798 | throw errorOrPromise;
|
3799 | });
|
3800 | }
|
3801 | |
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 |
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 |
|
3814 |
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 |
|
3821 |
|
3822 |
|
3823 |
|
3824 |
|
3825 |
|
3826 |
|
3827 |
|
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 | function wrapPendingDependencyPromise(store, promise, state, existingDeps, executionId) {
|
3834 | return promise.then(resolvedDep => {
|
3835 | const {
|
3836 | __key: resolvedDepKey,
|
3837 | __value: depValue
|
3838 | } = resolvedDep;
|
3839 |
|
3840 | if (resolvedDepKey != null) {
|
3841 | |
3842 |
|
3843 |
|
3844 |
|
3845 |
|
3846 |
|
3847 |
|
3848 | state.atomValues.set(resolvedDepKey, loadableWithValue$1(depValue));
|
3849 | }
|
3850 |
|
3851 | const [loadable, depValues] = evaluateSelectorGetter(store, state, executionId);
|
3852 |
|
3853 | if (isLatestExecution(executionId)) {
|
3854 | updateExecutionInfoDepValues(depValues, executionId);
|
3855 | }
|
3856 |
|
3857 | maybeFreezeLoadableContents(loadable);
|
3858 |
|
3859 | if (loadable.state !== 'loading') {
|
3860 | setCache(state, depValuesToDepRoute(depValues), loadable);
|
3861 | setLoadableInStoreToNotifyDeps(loadable, executionId);
|
3862 | }
|
3863 |
|
3864 | if (loadable.state === 'hasError') {
|
3865 | throw loadable.contents;
|
3866 | }
|
3867 |
|
3868 | if (loadable.state === 'hasValue') {
|
3869 | return {
|
3870 | __value: loadable.contents,
|
3871 | __key: key
|
3872 | };
|
3873 | }
|
3874 | |
3875 |
|
3876 |
|
3877 |
|
3878 |
|
3879 |
|
3880 |
|
3881 | return loadable.contents;
|
3882 | }).catch(error => {
|
3883 | const loadable = loadableWithError$1(error);
|
3884 | maybeFreezeValue(error);
|
3885 | setCache(state, depValuesToDepRoute(existingDeps), loadableWithError$1(error));
|
3886 | setLoadableInStoreToNotifyDeps(loadable, executionId);
|
3887 | throw error;
|
3888 | });
|
3889 | }
|
3890 |
|
3891 | function setLoadableInStoreToNotifyDeps(loadable, executionId) {
|
3892 | if (isLatestExecution(executionId)) {
|
3893 | setExecutionInfo(loadable);
|
3894 | notifyStoresOfSettledAsync(loadable, executionId);
|
3895 | }
|
3896 | }
|
3897 |
|
3898 | function setDepsInStore(store, state, deps, executionId) {
|
3899 | var _store$getState, _store$getState$curre, _store$getState2, _store$getState2$next;
|
3900 |
|
3901 | if (isLatestExecution(executionId) || state.version === ((_store$getState = store.getState()) === null || _store$getState === void 0 ? void 0 : (_store$getState$curre = _store$getState.currentTree) === null || _store$getState$curre === void 0 ? void 0 : _store$getState$curre.version) || state.version === ((_store$getState2 = store.getState()) === null || _store$getState2 === void 0 ? void 0 : (_store$getState2$next = _store$getState2.nextTree) === null || _store$getState2$next === void 0 ? void 0 : _store$getState2$next.version)) {
|
3902 | var _store$getState$nextT, _store$getState3, _store$getState3$next;
|
3903 |
|
3904 | saveDependencyMapToStore$3(new Map([[key, deps]]), store, (_store$getState$nextT = (_store$getState3 = store.getState()) === null || _store$getState3 === void 0 ? void 0 : (_store$getState3$next = _store$getState3.nextTree) === null || _store$getState3$next === void 0 ? void 0 : _store$getState3$next.version) !== null && _store$getState$nextT !== void 0 ? _store$getState$nextT : store.getState().currentTree.version);
|
3905 | }
|
3906 | }
|
3907 |
|
3908 | function setNewDepInStore(store, state, deps, newDepKey, executionId) {
|
3909 | deps.add(newDepKey);
|
3910 | setDepsInStore(store, state, deps, executionId);
|
3911 | }
|
3912 |
|
3913 | function evaluateSelectorGetter(store, state, executionId) {
|
3914 | const endPerfBlock = startPerfBlock$1(key);
|
3915 |
|
3916 | let result;
|
3917 | let loadable;
|
3918 | const depValues = new Map();
|
3919 | |
3920 |
|
3921 |
|
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 | const deps = new Set();
|
3931 | setDepsInStore(store, state, deps, executionId);
|
3932 |
|
3933 | function getRecoilValue(recoilValue) {
|
3934 | const {
|
3935 | key: depKey
|
3936 | } = recoilValue;
|
3937 | setNewDepInStore(store, state, deps, depKey, executionId);
|
3938 | const [, depLoadable] = getCachedNodeLoadable(store, state, depKey);
|
3939 | depValues.set(depKey, depLoadable);
|
3940 |
|
3941 | if (depLoadable.state === 'hasValue') {
|
3942 | return depLoadable.contents;
|
3943 | }
|
3944 |
|
3945 | throw depLoadable.contents;
|
3946 | }
|
3947 |
|
3948 | try {
|
3949 | result = get({
|
3950 | get: getRecoilValue
|
3951 | });
|
3952 | result = isRecoilValue$3(result) ? getRecoilValue(result) : result;
|
3953 |
|
3954 | if (Recoil_isPromise(result)) {
|
3955 | result = wrapPendingPromise(store, result, state, depValues, executionId).finally(endPerfBlock);
|
3956 | } else {
|
3957 | endPerfBlock();
|
3958 | }
|
3959 | } catch (errorOrDepPromise) {
|
3960 | result = errorOrDepPromise;
|
3961 |
|
3962 | if (Recoil_isPromise(result)) {
|
3963 | result = wrapPendingDependencyPromise(store, result, state, depValues, executionId).finally(endPerfBlock);
|
3964 | } else {
|
3965 | endPerfBlock();
|
3966 | }
|
3967 | }
|
3968 |
|
3969 | if (result instanceof Error) {
|
3970 | loadable = loadableWithError$1(result);
|
3971 | } else if (Recoil_isPromise(result)) {
|
3972 | loadable = loadableWithPromise$1(result);
|
3973 | } else {
|
3974 | loadable = loadableWithValue$1(result);
|
3975 | }
|
3976 |
|
3977 | maybeFreezeLoadableContents(loadable);
|
3978 | return [loadable, depValues];
|
3979 | }
|
3980 |
|
3981 | function getValFromCacheAndUpdatedDownstreamDeps(store, state) {
|
3982 | var _store$getGraph$nodeD;
|
3983 |
|
3984 | if (state.atomValues.has(key)) {
|
3985 | return state.atomValues.get(key);
|
3986 | }
|
3987 |
|
3988 | const deps = new Set((_store$getGraph$nodeD = store.getGraph(state.version).nodeDeps.get(key)) !== null && _store$getGraph$nodeD !== void 0 ? _store$getGraph$nodeD : emptySet$1);
|
3989 | setDepsInStore(store, state, deps, executionInfo.latestExecutionId);
|
3990 | const cachedVal = cache.get(nodeKey => {
|
3991 | const [, loadable] = getCachedNodeLoadable(store, state, nodeKey);
|
3992 | return loadable.contents;
|
3993 | }, {
|
3994 | onCacheHit: nodeKey => {
|
3995 | if (nodeKey !== key) {
|
3996 | setNewDepInStore(store, state, deps, nodeKey, executionInfo.latestExecutionId);
|
3997 | }
|
3998 | }
|
3999 | });
|
4000 | return cachedVal;
|
4001 | }
|
4002 | |
4003 |
|
4004 |
|
4005 |
|
4006 |
|
4007 |
|
4008 |
|
4009 |
|
4010 |
|
4011 |
|
4012 |
|
4013 |
|
4014 |
|
4015 | function depValuesToDepRoute(depValues) {
|
4016 | return Array.from(depValues.entries()).map(([key, valLoadable]) => [key, valLoadable.contents]);
|
4017 | }
|
4018 |
|
4019 | function getValFromRunningNewExecutionAndUpdatedDeps(store, state) {
|
4020 | const newExecutionId = getNewExecutionId();
|
4021 | const [loadable, newDepValues] = evaluateSelectorGetter(store, state, newExecutionId);
|
4022 | setExecutionInfo(loadable, newDepValues, newExecutionId, state);
|
4023 | maybeSetCacheWithLoadable(state, depValuesToDepRoute(newDepValues), loadable);
|
4024 | notifyStoreWhenAsyncSettles(store, loadable, newExecutionId);
|
4025 | return loadable;
|
4026 | }
|
4027 | |
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 |
|
4034 |
|
4035 |
|
4036 |
|
4037 |
|
4038 |
|
4039 |
|
4040 |
|
4041 |
|
4042 |
|
4043 |
|
4044 |
|
4045 |
|
4046 |
|
4047 |
|
4048 | function getSelectorValAndUpdatedDeps(store, state) {
|
4049 | const cachedVal = getValFromCacheAndUpdatedDownstreamDeps(store, state);
|
4050 |
|
4051 | if (cachedVal != null) {
|
4052 | setExecutionInfo(cachedVal);
|
4053 | return cachedVal;
|
4054 | }
|
4055 |
|
4056 |
|
4057 | if (asyncWorkIsInProgressAndDepsDiscoveredHaveNotChanged(store, state)) {
|
4058 | notifyStoreWhenAsyncSettles(store, Recoil_nullthrows(executionInfo.latestLoadable), Recoil_nullthrows(executionInfo.latestExecutionId));
|
4059 |
|
4060 | return Recoil_nullthrows(executionInfo.latestLoadable);
|
4061 | }
|
4062 |
|
4063 | return getValFromRunningNewExecutionAndUpdatedDeps(store, state);
|
4064 | }
|
4065 |
|
4066 | function asyncWorkIsInProgressAndDepsDiscoveredHaveNotChanged(store, state) {
|
4067 | return executionInfo.latestLoadable != null && executionInfo.latestExecutionId != null && !haveAsyncDepsChanged(store, state);
|
4068 | }
|
4069 |
|
4070 | const mapOfCheckedVersions = new Map();
|
4071 |
|
4072 | function haveAsyncDepsChanged(store, state) {
|
4073 | var _executionInfo$depVal, _mapOfCheckedVersions;
|
4074 |
|
4075 | const oldDepValues = (_executionInfo$depVal = executionInfo.depValuesDiscoveredSoFarDuringAsyncWork) !== null && _executionInfo$depVal !== void 0 ? _executionInfo$depVal : new Map();
|
4076 | const cachedDepValuesCheckedForThisVersion = Array(((_mapOfCheckedVersions = mapOfCheckedVersions.get(state.version)) !== null && _mapOfCheckedVersions !== void 0 ? _mapOfCheckedVersions : new Map()).entries());
|
4077 | const isCachedVersionSame = mapOfCheckedVersions.has(state.version) && cachedDepValuesCheckedForThisVersion.length === oldDepValues.size && cachedDepValuesCheckedForThisVersion.every(([nodeKey, nodeVal]) => {
|
4078 | return oldDepValues.get(nodeKey) === nodeVal;
|
4079 | });
|
4080 |
|
4081 | if (oldDepValues == null || state.version === executionInfo.stateVersion || isCachedVersionSame) {
|
4082 | return false;
|
4083 | }
|
4084 |
|
4085 | mapOfCheckedVersions.set(state.version, new Map(oldDepValues));
|
4086 | return Array.from(oldDepValues).some(([nodeKey, oldVal]) => {
|
4087 | const [, loadable] = getCachedNodeLoadable(store, state, nodeKey);
|
4088 | return loadable.contents !== oldVal.contents &&
|
4089 | |
4090 |
|
4091 |
|
4092 |
|
4093 |
|
4094 |
|
4095 |
|
4096 |
|
4097 |
|
4098 |
|
4099 |
|
4100 |
|
4101 |
|
4102 | !(oldVal.state === 'loading' && loadable.state !== 'loading');
|
4103 | });
|
4104 | }
|
4105 | |
4106 |
|
4107 |
|
4108 |
|
4109 |
|
4110 |
|
4111 |
|
4112 |
|
4113 |
|
4114 | function setExecutionInfo(loadable, depValues, newExecutionId, state) {
|
4115 | if (loadable.state === 'loading') {
|
4116 | executionInfo.depValuesDiscoveredSoFarDuringAsyncWork = depValues;
|
4117 | executionInfo.latestExecutionId = newExecutionId;
|
4118 | executionInfo.latestLoadable = loadable;
|
4119 | executionInfo.stateVersion = state === null || state === void 0 ? void 0 : state.version;
|
4120 | } else {
|
4121 | executionInfo.depValuesDiscoveredSoFarDuringAsyncWork = null;
|
4122 | executionInfo.latestExecutionId = null;
|
4123 | executionInfo.latestLoadable = null;
|
4124 | executionInfo.stateVersion = null;
|
4125 | }
|
4126 | }
|
4127 | |
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 |
|
4137 |
|
4138 |
|
4139 |
|
4140 | function maybeSetCacheWithLoadable(state, depRoute, loadable) {
|
4141 | if (loadable.state !== 'loading') {
|
4142 | setCache(state, depRoute, loadable);
|
4143 | }
|
4144 | }
|
4145 |
|
4146 | function updateExecutionInfoDepValues(depValues, executionId) {
|
4147 | if (isLatestExecution(executionId)) {
|
4148 | executionInfo.depValuesDiscoveredSoFarDuringAsyncWork = depValues;
|
4149 | }
|
4150 | }
|
4151 |
|
4152 | function isLatestExecution(executionId) {
|
4153 | return executionId === executionInfo.latestExecutionId;
|
4154 | }
|
4155 |
|
4156 | function maybeFreezeLoadableContents(loadable) {
|
4157 | if (loadable.state !== 'loading') {
|
4158 | maybeFreezeValue(loadable.contents);
|
4159 | }
|
4160 | }
|
4161 |
|
4162 | function maybeFreezeValue(val) {
|
4163 | if (process.env.NODE_ENV !== "production") {
|
4164 | if (Boolean(options.dangerouslyAllowMutability) === false) {
|
4165 | Recoil_deepFreezeValue(val);
|
4166 | }
|
4167 | }
|
4168 | }
|
4169 |
|
4170 | function setCache(state, cacheRoute, loadable) {
|
4171 | state.atomValues.set(key, loadable);
|
4172 | cache.set(cacheRoute, loadable);
|
4173 | }
|
4174 |
|
4175 | function detectCircularDependencies(fn) {
|
4176 | if (dependencyStack.includes(key)) {
|
4177 | const message = `Recoil selector has circular dependencies: ${dependencyStack.slice(dependencyStack.indexOf(key)).join(' \u2192 ')}`;
|
4178 |
|
4179 | return loadableWithError$1(new Error(message));
|
4180 | }
|
4181 |
|
4182 | dependencyStack.push(key);
|
4183 |
|
4184 | try {
|
4185 | return fn();
|
4186 | } finally {
|
4187 | dependencyStack.pop();
|
4188 | }
|
4189 | }
|
4190 |
|
4191 | function myPeek(store, state) {
|
4192 | const cacheVal = cache.get(nodeKey => {
|
4193 | const peek = peekNodeLoadable$2(store, state, nodeKey);
|
4194 | return peek === null || peek === void 0 ? void 0 : peek.contents;
|
4195 | });
|
4196 | return cacheVal;
|
4197 | }
|
4198 |
|
4199 | function myGet(store, state) {
|
4200 | initSelector(store);
|
4201 | return [new Map(), detectCircularDependencies(() => getSelectorValAndUpdatedDeps(store, state))];
|
4202 | }
|
4203 |
|
4204 | function invalidate(state) {
|
4205 | state.atomValues.delete(key);
|
4206 | }
|
4207 |
|
4208 | if (set != null) {
|
4209 | function mySet(store, state, newValue) {
|
4210 | initSelector(store);
|
4211 | const dependencyMap = new Map();
|
4212 | const writes = new Map();
|
4213 |
|
4214 | function getRecoilValue({
|
4215 | key
|
4216 | }) {
|
4217 | const [, loadable] = getCachedNodeLoadable(store, state, key);
|
4218 |
|
4219 | if (loadable.state === 'hasValue') {
|
4220 | return loadable.contents;
|
4221 | } else if (loadable.state === 'loading') {
|
4222 | throw new RecoilValueNotReady$2(key);
|
4223 | } else {
|
4224 | throw loadable.contents;
|
4225 | }
|
4226 | }
|
4227 |
|
4228 | function setRecoilState(recoilState, valueOrUpdater) {
|
4229 | const newValue = typeof valueOrUpdater === 'function' ?
|
4230 |
|
4231 | valueOrUpdater(getRecoilValue(recoilState)) : valueOrUpdater;
|
4232 | const [, upstreamWrites] = setNodeValue$3(store, state, recoilState.key, newValue);
|
4233 | upstreamWrites.forEach((v, k) => writes.set(k, v));
|
4234 | }
|
4235 |
|
4236 | function resetRecoilState(recoilState) {
|
4237 | setRecoilState(recoilState, DEFAULT_VALUE$3);
|
4238 | }
|
4239 |
|
4240 | set({
|
4241 | set: setRecoilState,
|
4242 | get: getRecoilValue,
|
4243 | reset: resetRecoilState
|
4244 | }, newValue);
|
4245 | return [dependencyMap, writes];
|
4246 | }
|
4247 |
|
4248 | return registerNode$1({
|
4249 | key,
|
4250 | peek: myPeek,
|
4251 | get: myGet,
|
4252 | set: mySet,
|
4253 | cleanUp: () => {},
|
4254 | invalidate,
|
4255 | dangerouslyAllowMutability: options.dangerouslyAllowMutability,
|
4256 | shouldRestoreFromSnapshots: false
|
4257 | });
|
4258 | } else {
|
4259 | return registerNode$1({
|
4260 | key,
|
4261 | peek: myPeek,
|
4262 | get: myGet,
|
4263 | cleanUp: () => {},
|
4264 | invalidate,
|
4265 | dangerouslyAllowMutability: options.dangerouslyAllowMutability,
|
4266 | shouldRestoreFromSnapshots: false
|
4267 | });
|
4268 | }
|
4269 | }
|
4270 |
|
4271 |
|
4272 |
|
4273 | var Recoil_selector_NEW = selector;
|
4274 |
|
4275 | const {
|
4276 | loadableWithError: loadableWithError$2,
|
4277 | loadableWithPromise: loadableWithPromise$2,
|
4278 | loadableWithValue: loadableWithValue$2
|
4279 | } = Recoil_Loadable;
|
4280 |
|
4281 |
|
4282 |
|
4283 | const {
|
4284 | getNodeLoadable: getNodeLoadable$3,
|
4285 | peekNodeLoadable: peekNodeLoadable$3,
|
4286 | setNodeValue: setNodeValue$4
|
4287 | } = Recoil_FunctionalCore;
|
4288 |
|
4289 | const {
|
4290 | addToDependencyMap: addToDependencyMap$1,
|
4291 | mergeDepsIntoDependencyMap: mergeDepsIntoDependencyMap$1,
|
4292 | saveDependencyMapToStore: saveDependencyMapToStore$4
|
4293 | } = Recoil_Graph;
|
4294 |
|
4295 | const {
|
4296 | DEFAULT_VALUE: DEFAULT_VALUE$4,
|
4297 | RecoilValueNotReady: RecoilValueNotReady$3,
|
4298 | registerNode: registerNode$2
|
4299 | } = Recoil_Node;
|
4300 |
|
4301 | const {
|
4302 | AbstractRecoilValue: AbstractRecoilValue$4
|
4303 | } = Recoil_RecoilValue$1;
|
4304 |
|
4305 | const {
|
4306 | getRecoilValueAsLoadable: getRecoilValueAsLoadable$3,
|
4307 | isRecoilValue: isRecoilValue$4,
|
4308 | setRecoilValueLoadable: setRecoilValueLoadable$3
|
4309 | } = Recoil_RecoilValueInterface;
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 | const {
|
4318 | startPerfBlock: startPerfBlock$2
|
4319 | } = Recoil_PerformanceTimings;
|
4320 |
|
4321 |
|
4322 | const emptySet$2 = Object.freeze(new Set());
|
4323 |
|
4324 | function cacheKeyFromDepValues(depValues) {
|
4325 | const answer = [];
|
4326 |
|
4327 | for (const key of Array.from(depValues.keys()).sort()) {
|
4328 | const loadable = Recoil_nullthrows(depValues.get(key));
|
4329 | answer.push(key);
|
4330 | answer.push(loadable.state);
|
4331 | answer.push(loadable.contents);
|
4332 | }
|
4333 |
|
4334 | return answer;
|
4335 | }
|
4336 |
|
4337 | const dependencyStack$1 = [];
|
4338 |
|
4339 | const waitingStores$1 = new Map();
|
4340 |
|
4341 |
|
4342 | function selector$1(options) {
|
4343 | const {
|
4344 | key,
|
4345 | get,
|
4346 | cacheImplementation_UNSTABLE: cacheImplementation
|
4347 | } = options;
|
4348 | const set = options.set != null ? options.set : undefined; // flow
|
4349 |
|
4350 | let cache = cacheImplementation !== null && cacheImplementation !== void 0 ? cacheImplementation : Recoil_cacheWithReferenceEquality();
|
4351 |
|
4352 | function initSelector(store) {
|
4353 | store.getState().knownSelectors.add(key);
|
4354 | }
|
4355 |
|
4356 | function letStoreBeNotifiedWhenAsyncSettles(store, loadable) {
|
4357 | if (loadable.state === 'loading') {
|
4358 | let stores = waitingStores$1.get(loadable);
|
4359 |
|
4360 | if (stores === undefined) {
|
4361 | waitingStores$1.set(loadable, stores = new Set());
|
4362 | }
|
4363 |
|
4364 | stores.add(store);
|
4365 | }
|
4366 | }
|
4367 |
|
4368 | function notifyStoresOfSettledAsync(originalLoadable, newLoadable) {
|
4369 | const stores = waitingStores$1.get(originalLoadable);
|
4370 |
|
4371 | if (stores !== undefined) {
|
4372 | for (const store of stores) {
|
4373 | setRecoilValueLoadable$3(store, new AbstractRecoilValue$4(key), newLoadable);
|
4374 | }
|
4375 |
|
4376 | waitingStores$1.delete(originalLoadable);
|
4377 | }
|
4378 | }
|
4379 |
|
4380 | function putIntoCache(state, cacheKey, loadable) {
|
4381 | if (loadable.state !== 'loading') {
|
4382 |
|
4383 | if (process.env.NODE_ENV !== "production") {
|
4384 | if (!options.dangerouslyAllowMutability === true) {
|
4385 | Recoil_deepFreezeValue(loadable.contents);
|
4386 | }
|
4387 | }
|
4388 | } else {
|
4389 |
|
4390 |
|
4391 |
|
4392 | loadable.contents.then(result => {
|
4393 | if (process.env.NODE_ENV !== "production") {
|
4394 | if (!options.dangerouslyAllowMutability === true) {
|
4395 | Recoil_deepFreezeValue(result);
|
4396 | }
|
4397 | }
|
4398 |
|
4399 | const newLoadable = loadableWithValue$2(result);
|
4400 |
|
4401 | cache = cache.set(cacheKey, newLoadable);
|
4402 |
|
4403 |
|
4404 |
|
4405 |
|
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 |
|
4416 |
|
4417 |
|
4418 |
|
4419 |
|
4420 | notifyStoresOfSettledAsync(loadable, newLoadable);
|
4421 | return result;
|
4422 | }).catch(error => {
|
4423 |
|
4424 |
|
4425 | if (Recoil_isPromise(error)) {
|
4426 | return error;
|
4427 | }
|
4428 |
|
4429 | if (process.env.NODE_ENV !== "production") {
|
4430 | if (!options.dangerouslyAllowMutability === true) {
|
4431 | Recoil_deepFreezeValue(error);
|
4432 | }
|
4433 | }
|
4434 |
|
4435 |
|
4436 |
|
4437 | const newLoadable = loadableWithError$2(error);
|
4438 | cache = cache.set(cacheKey, newLoadable);
|
4439 | notifyStoresOfSettledAsync(loadable, newLoadable);
|
4440 | return error;
|
4441 | });
|
4442 | }
|
4443 |
|
4444 | cache = cache.set(cacheKey, loadable);
|
4445 |
|
4446 | if (loadable.state !== 'loading') {
|
4447 | state.atomValues.set(key, loadable);
|
4448 | }
|
4449 | }
|
4450 |
|
4451 | function getFromCacheOrEvaluate(store, state) {
|
4452 | var _store$getGraph$nodeD;
|
4453 |
|
4454 | const dependencyMap = new Map();
|
4455 |
|
4456 | const currentDeps = (_store$getGraph$nodeD = store.getGraph(state.version).nodeDeps.get(key)) !== null && _store$getGraph$nodeD !== void 0 ? _store$getGraph$nodeD : emptySet$2;
|
4457 | const depValues = new Map(Array.from(currentDeps).sort().map(depKey => {
|
4458 | const [deps, loadable] = getNodeLoadable$3(store, state, depKey);
|
4459 | mergeDepsIntoDependencyMap$1(deps, dependencyMap);
|
4460 | saveDependencyMapToStore$4(dependencyMap, store, state.version);
|
4461 | return [depKey, loadable];
|
4462 | }));
|
4463 |
|
4464 |
|
4465 | const cacheKey = cacheKeyFromDepValues(depValues);
|
4466 | const cached = cache.get(cacheKey);
|
4467 |
|
4468 | if (cached != null) {
|
4469 | letStoreBeNotifiedWhenAsyncSettles(store, cached);
|
4470 | return [dependencyMap, cached];
|
4471 | }
|
4472 |
|
4473 |
|
4474 | const [deps, loadable, newDepValues] = evaluateSelectorFunction(store, state);
|
4475 | mergeDepsIntoDependencyMap$1(deps, dependencyMap);
|
4476 | saveDependencyMapToStore$4(dependencyMap, store, state.version);
|
4477 |
|
4478 | const newCacheKey = cacheKeyFromDepValues(newDepValues);
|
4479 | letStoreBeNotifiedWhenAsyncSettles(store, loadable);
|
4480 | putIntoCache(state, newCacheKey, loadable);
|
4481 | return [dependencyMap, loadable];
|
4482 | }
|
4483 |
|
4484 | function evaluateSelectorFunction(store, state) {
|
4485 | const endPerfBlock = startPerfBlock$2(key);
|
4486 | const depValues = new Map();
|
4487 |
|
4488 | const dependencyMap = new Map();
|
4489 |
|
4490 | function getRecoilValue({
|
4491 | key: depKey
|
4492 | }) {
|
4493 | addToDependencyMap$1(key, depKey, dependencyMap);
|
4494 | const [deps, loadable] = getNodeLoadable$3(store, state, depKey);
|
4495 | depValues.set(depKey, loadable);
|
4496 | mergeDepsIntoDependencyMap$1(deps, dependencyMap);
|
4497 | saveDependencyMapToStore$4(dependencyMap, store, state.version);
|
4498 |
|
4499 | if (loadable.state === 'hasValue') {
|
4500 | return loadable.contents;
|
4501 | } else {
|
4502 | throw loadable.contents;
|
4503 | }
|
4504 | }
|
4505 |
|
4506 | try {
|
4507 |
|
4508 | const output = get({
|
4509 | get: getRecoilValue
|
4510 | }); // TODO Allow user to also return Loadables for improved composability
|
4511 |
|
4512 | const result = isRecoilValue$4(output) ? getRecoilValue(output) : output;
|
4513 | let loadable;
|
4514 |
|
4515 | if (!Recoil_isPromise(result)) {
|
4516 |
|
4517 | endPerfBlock();
|
4518 | loadable = loadableWithValue$2(result);
|
4519 | } else {
|
4520 |
|
4521 |
|
4522 | loadable = loadableWithPromise$2(result.finally(endPerfBlock));
|
4523 | }
|
4524 |
|
4525 | return [dependencyMap, loadable, depValues];
|
4526 | } catch (errorOrDepPromise) {
|
4527 |
|
4528 | const isP = errorOrDepPromise.then !== undefined;
|
4529 | let loadable;
|
4530 |
|
4531 | if (!isP) {
|
4532 |
|
4533 | endPerfBlock();
|
4534 | loadable = loadableWithError$2(errorOrDepPromise);
|
4535 | } else {
|
4536 |
|
4537 |
|
4538 | loadable = loadableWithPromise$2(errorOrDepPromise.then(() => {
|
4539 |
|
4540 |
|
4541 | const loadable = getRecoilValueAsLoadable$3(store, new AbstractRecoilValue$4(key));
|
4542 |
|
4543 | if (loadable.state === 'hasError') {
|
4544 | throw loadable.contents;
|
4545 | }
|
4546 |
|
4547 |
|
4548 |
|
4549 | return loadable.contents;
|
4550 | }).finally(endPerfBlock));
|
4551 | }
|
4552 |
|
4553 | return [dependencyMap, loadable, depValues];
|
4554 | }
|
4555 | }
|
4556 |
|
4557 | function detectCircularDependencies(fn) {
|
4558 | if (dependencyStack$1.includes(key)) {
|
4559 | const message = `Recoil selector has circular dependencies: ${dependencyStack$1.slice(dependencyStack$1.indexOf(key)).join(' \u2192 ')}`;
|
4560 | return [new Map(), loadableWithError$2(new Error(message))];
|
4561 | }
|
4562 |
|
4563 | dependencyStack$1.push(key);
|
4564 |
|
4565 | try {
|
4566 | return fn();
|
4567 | } finally {
|
4568 | dependencyStack$1.pop();
|
4569 | }
|
4570 | }
|
4571 |
|
4572 | function myPeek(store, state) {
|
4573 | var _store$getGraph$nodeD2;
|
4574 |
|
4575 |
|
4576 | const currentDeps = (_store$getGraph$nodeD2 = store.getGraph(state.version).nodeDeps.get(key)) !== null && _store$getGraph$nodeD2 !== void 0 ? _store$getGraph$nodeD2 : emptySet$2;
|
4577 | const depValues = new Map(Array.from(currentDeps).sort().map(depKey => [depKey, peekNodeLoadable$3(store, state, depKey)]));
|
4578 | const cacheDepValues = new Map();
|
4579 |
|
4580 | for (const [depKey, depValue] of depValues.entries()) {
|
4581 | if (depValue == null) {
|
4582 | return undefined;
|
4583 | }
|
4584 |
|
4585 | cacheDepValues.set(depKey, depValue);
|
4586 | }
|
4587 |
|
4588 |
|
4589 |
|
4590 | const cacheKey = cacheKeyFromDepValues(cacheDepValues);
|
4591 | return cache.get(cacheKey);
|
4592 | }
|
4593 |
|
4594 | function invalidate(state) {
|
4595 | state.atomValues.delete(key);
|
4596 | }
|
4597 |
|
4598 | function myGet(store, state) {
|
4599 | initSelector(store);
|
4600 |
|
4601 |
|
4602 | const cached = state.atomValues.get(key);
|
4603 |
|
4604 | if (cached !== undefined) {
|
4605 | return [new Map(), cached];
|
4606 | }
|
4607 |
|
4608 |
|
4609 |
|
4610 | if (process.env.NODE_ENV !== "production") {
|
4611 | return detectCircularDependencies(() => getFromCacheOrEvaluate(store, state));
|
4612 | } else {
|
4613 | return getFromCacheOrEvaluate(store, state);
|
4614 | }
|
4615 | }
|
4616 |
|
4617 | if (set != null) {
|
4618 | function mySet(store, state, newValue) {
|
4619 | initSelector(store);
|
4620 | const dependencyMap = new Map();
|
4621 | const writes = new Map();
|
4622 |
|
4623 | function getRecoilValue({
|
4624 | key
|
4625 | }) {
|
4626 | const [deps, loadable] = getNodeLoadable$3(store, state, key);
|
4627 | mergeDepsIntoDependencyMap$1(deps, dependencyMap);
|
4628 |
|
4629 | if (loadable.state === 'hasValue') {
|
4630 | return loadable.contents;
|
4631 | } else if (loadable.state === 'loading') {
|
4632 | throw new RecoilValueNotReady$3(key);
|
4633 | } else {
|
4634 | throw loadable.contents;
|
4635 | }
|
4636 | }
|
4637 |
|
4638 | function setRecoilState(recoilState, valueOrUpdater) {
|
4639 | const newValue = typeof valueOrUpdater === 'function' ?
|
4640 |
|
4641 | valueOrUpdater(getRecoilValue(recoilState)) : valueOrUpdater;
|
4642 | const [deps, upstreamWrites] = setNodeValue$4(store, state, recoilState.key, newValue);
|
4643 | mergeDepsIntoDependencyMap$1(deps, dependencyMap);
|
4644 | upstreamWrites.forEach((v, k) => writes.set(k, v));
|
4645 | }
|
4646 |
|
4647 | function resetRecoilState(recoilState) {
|
4648 | setRecoilState(recoilState, DEFAULT_VALUE$4);
|
4649 | }
|
4650 |
|
4651 | set({
|
4652 | set: setRecoilState,
|
4653 | get: getRecoilValue,
|
4654 | reset: resetRecoilState
|
4655 | }, newValue);
|
4656 | return [dependencyMap, writes];
|
4657 | }
|
4658 |
|
4659 | return registerNode$2({
|
4660 | key,
|
4661 | peek: myPeek,
|
4662 | get: myGet,
|
4663 | set: mySet,
|
4664 | invalidate,
|
4665 | cleanUp: () => {},
|
4666 | dangerouslyAllowMutability: options.dangerouslyAllowMutability,
|
4667 | shouldRestoreFromSnapshots: false
|
4668 | });
|
4669 | } else {
|
4670 | return registerNode$2({
|
4671 | key,
|
4672 | peek: myPeek,
|
4673 | get: myGet,
|
4674 | invalidate,
|
4675 | cleanUp: () => {},
|
4676 | dangerouslyAllowMutability: options.dangerouslyAllowMutability,
|
4677 | shouldRestoreFromSnapshots: false
|
4678 | });
|
4679 | }
|
4680 | }
|
4681 |
|
4682 |
|
4683 |
|
4684 | var Recoil_selector_OLD = selector$1;
|
4685 |
|
4686 | const selector$2 = Recoil_gkx_1('recoil_async_selector_refactor') ? Recoil_selector_NEW : Recoil_selector_OLD;
|
4687 | var Recoil_selector = selector$2;
|
4688 |
|
4689 |
|
4690 | const {
|
4691 | loadableWithError: loadableWithError$3,
|
4692 | loadableWithPromise: loadableWithPromise$3,
|
4693 | loadableWithValue: loadableWithValue$3
|
4694 | } = Recoil_Loadable;
|
4695 |
|
4696 | const {
|
4697 | DEFAULT_VALUE: DEFAULT_VALUE$5,
|
4698 | DefaultValue: DefaultValue$2,
|
4699 | registerNode: registerNode$3
|
4700 | } = Recoil_Node;
|
4701 |
|
4702 | const {
|
4703 | isRecoilValue: isRecoilValue$5
|
4704 | } = Recoil_RecoilValue$1;
|
4705 |
|
4706 | const {
|
4707 | markRecoilValueModified: markRecoilValueModified$1,
|
4708 | setRecoilValue: setRecoilValue$3,
|
4709 | setRecoilValueLoadable: setRecoilValueLoadable$4
|
4710 | } = Recoil_RecoilValueInterface;
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 | function baseAtom(options) {
|
4725 | const {
|
4726 | key,
|
4727 | persistence_UNSTABLE: persistence
|
4728 | } = options;
|
4729 | let defaultLoadable = Recoil_isPromise(options.default) ? loadableWithPromise$3(options.default.then(value => {
|
4730 | defaultLoadable = loadableWithValue$3(value);
|
4731 |
|
4732 | const promiseInfo = {
|
4733 | __key: key,
|
4734 | __value: value
|
4735 | };
|
4736 | return promiseInfo;
|
4737 | }).catch(error => {
|
4738 | defaultLoadable = loadableWithError$3(error);
|
4739 | throw error;
|
4740 | })) : loadableWithValue$3(options.default);
|
4741 | let cachedAnswerForUnvalidatedValue = undefined;
|
4742 |
|
4743 |
|
4744 | const cleanupEffectsByStore = new Map();
|
4745 |
|
4746 | function wrapPendingPromise(store, promise) {
|
4747 | const wrappedPromise = promise.then(value => {
|
4748 | var _store$getState$nextT, _state$atomValues$get;
|
4749 |
|
4750 | const state = (_store$getState$nextT = store.getState().nextTree) !== null && _store$getState$nextT !== void 0 ? _store$getState$nextT : store.getState().currentTree;
|
4751 |
|
4752 | if (((_state$atomValues$get = state.atomValues.get(key)) === null || _state$atomValues$get === void 0 ? void 0 : _state$atomValues$get.contents) === wrappedPromise) {
|
4753 | setRecoilValue$3(store, node, value);
|
4754 | }
|
4755 |
|
4756 | return {
|
4757 | __key: key,
|
4758 | __value: value
|
4759 | };
|
4760 | }).catch(error => {
|
4761 | var _store$getState$nextT2, _state$atomValues$get2;
|
4762 |
|
4763 | const state = (_store$getState$nextT2 = store.getState().nextTree) !== null && _store$getState$nextT2 !== void 0 ? _store$getState$nextT2 : store.getState().currentTree;
|
4764 |
|
4765 | if (((_state$atomValues$get2 = state.atomValues.get(key)) === null || _state$atomValues$get2 === void 0 ? void 0 : _state$atomValues$get2.contents) === wrappedPromise) {
|
4766 | setRecoilValueLoadable$4(store, node, loadableWithError$3(error));
|
4767 | }
|
4768 |
|
4769 | throw error;
|
4770 | });
|
4771 | return wrappedPromise;
|
4772 | }
|
4773 |
|
4774 | function initAtom(store, initState, trigger) {
|
4775 | if (store.getState().knownAtoms.has(key)) {
|
4776 | return;
|
4777 | }
|
4778 |
|
4779 | store.getState().knownAtoms.add(key);
|
4780 |
|
4781 | if (defaultLoadable.state === 'loading') {
|
4782 | function notifyDefaultSubscribers() {
|
4783 | var _store$getState$nextT3;
|
4784 |
|
4785 | const state = (_store$getState$nextT3 = store.getState().nextTree) !== null && _store$getState$nextT3 !== void 0 ? _store$getState$nextT3 : store.getState().currentTree;
|
4786 |
|
4787 | if (!state.atomValues.has(key)) {
|
4788 | markRecoilValueModified$1(store, node);
|
4789 | }
|
4790 | }
|
4791 |
|
4792 | defaultLoadable.contents.then(notifyDefaultSubscribers).catch(notifyDefaultSubscribers);
|
4793 | }
|
4794 |
|
4795 |
|
4796 |
|
4797 | let initValue = DEFAULT_VALUE$5;
|
4798 | let pendingSetSelf = null;
|
4799 |
|
4800 | if (options.effects_UNSTABLE != null) {
|
4801 | let duringInit = true;
|
4802 |
|
4803 | const setSelf = effect => valueOrUpdater => {
|
4804 | if (duringInit) {
|
4805 | const currentValue = initValue instanceof DefaultValue$2 || Recoil_isPromise(initValue) ? defaultLoadable.state === 'hasValue' ? defaultLoadable.contents : DEFAULT_VALUE$5 : initValue;
|
4806 | initValue = typeof valueOrUpdater === 'function' ?
|
4807 | valueOrUpdater(currentValue)
|
4808 | : valueOrUpdater;
|
4809 | } else {
|
4810 | if (Recoil_isPromise(valueOrUpdater)) {
|
4811 | throw new Error('Setting atoms to async values is not implemented.');
|
4812 | }
|
4813 |
|
4814 | if (typeof valueOrUpdater !== 'function') {
|
4815 | pendingSetSelf = {
|
4816 | effect,
|
4817 | value: valueOrUpdater
|
4818 | };
|
4819 | }
|
4820 |
|
4821 | setRecoilValue$3(store, node, typeof valueOrUpdater === 'function' ? currentValue => {
|
4822 | const newValue =
|
4823 | valueOrUpdater(currentValue);
|
4824 |
|
4825 | pendingSetSelf = {
|
4826 | effect,
|
4827 | value: newValue
|
4828 | };
|
4829 | return newValue;
|
4830 | } : valueOrUpdater);
|
4831 | }
|
4832 | };
|
4833 |
|
4834 | const resetSelf = effect => () => setSelf(effect)(DEFAULT_VALUE$5);
|
4835 |
|
4836 | const onSet = effect => handler => {
|
4837 | store.subscribeToTransactions(currentStore => {
|
4838 | var _pendingSetSelf3;
|
4839 |
|
4840 |
|
4841 | let {
|
4842 | currentTree,
|
4843 | previousTree
|
4844 | } = currentStore.getState();
|
4845 |
|
4846 | if (!previousTree) {
|
4847 | Recoil_recoverableViolation('Transaction subscribers notified without a next tree being present -- this is a bug in Recoil');
|
4848 | previousTree = currentTree;
|
4849 | }
|
4850 |
|
4851 | const newLoadable = currentTree.atomValues.get(key);
|
4852 |
|
4853 | if (newLoadable == null || newLoadable.state === 'hasValue') {
|
4854 | var _previousTree$atomVal, _pendingSetSelf, _pendingSetSelf2;
|
4855 |
|
4856 | const newValue = newLoadable != null ? newLoadable.contents : DEFAULT_VALUE$5;
|
4857 | const oldLoadable = (_previousTree$atomVal = previousTree.atomValues.get(key)) !== null && _previousTree$atomVal !== void 0 ? _previousTree$atomVal : defaultLoadable;
|
4858 | const oldValue = oldLoadable.state === 'hasValue' ? oldLoadable.contents : DEFAULT_VALUE$5;
|
4859 |
|
4860 |
|
4861 |
|
4862 |
|
4863 |
|
4864 |
|
4865 |
|
4866 |
|
4867 | if (((_pendingSetSelf = pendingSetSelf) === null || _pendingSetSelf === void 0 ? void 0 : _pendingSetSelf.effect) !== effect || ((_pendingSetSelf2 = pendingSetSelf) === null || _pendingSetSelf2 === void 0 ? void 0 : _pendingSetSelf2.value) !== newValue) {
|
4868 | handler(newValue, oldValue);
|
4869 | }
|
4870 | }
|
4871 |
|
4872 | if (((_pendingSetSelf3 = pendingSetSelf) === null || _pendingSetSelf3 === void 0 ? void 0 : _pendingSetSelf3.effect) === effect) {
|
4873 | pendingSetSelf = null;
|
4874 | }
|
4875 | }, key);
|
4876 | };
|
4877 |
|
4878 | for (const effect of (_options$effects_UNST = options.effects_UNSTABLE) !== null && _options$effects_UNST !== void 0 ? _options$effects_UNST : []) {
|
4879 | var _options$effects_UNST;
|
4880 |
|
4881 | const cleanup = effect({
|
4882 | node,
|
4883 | trigger,
|
4884 | setSelf: setSelf(effect),
|
4885 | resetSelf: resetSelf(effect),
|
4886 | onSet: onSet(effect)
|
4887 | });
|
4888 |
|
4889 | if (cleanup != null) {
|
4890 | cleanupEffectsByStore.set(store, cleanup);
|
4891 | }
|
4892 | }
|
4893 |
|
4894 | duringInit = false;
|
4895 | }
|
4896 |
|
4897 |
|
4898 |
|
4899 | if (!(initValue instanceof DefaultValue$2)) {
|
4900 | initState.atomValues.set(key, Recoil_isPromise(initValue) ? loadableWithPromise$3(wrapPendingPromise(store, initValue)) : loadableWithValue$3(initValue));
|
4901 | }
|
4902 | }
|
4903 |
|
4904 | function myPeek(_store, state) {
|
4905 | var _ref, _state$atomValues$get3, _cachedAnswerForUnval;
|
4906 |
|
4907 | return (_ref = (_state$atomValues$get3 = state.atomValues.get(key)) !== null && _state$atomValues$get3 !== void 0 ? _state$atomValues$get3 : (_cachedAnswerForUnval = cachedAnswerForUnvalidatedValue) === null || _cachedAnswerForUnval === void 0 ? void 0 : _cachedAnswerForUnval[1]) !== null && _ref !== void 0 ? _ref : defaultLoadable;
|
4908 | }
|
4909 |
|
4910 | function myGet(store, state) {
|
4911 | initAtom(store, state, 'get');
|
4912 |
|
4913 | if (state.atomValues.has(key)) {
|
4914 |
|
4915 | return [new Map(), Recoil_nullthrows(state.atomValues.get(key))];
|
4916 | } else if (state.nonvalidatedAtoms.has(key)) {
|
4917 |
|
4918 |
|
4919 | if (cachedAnswerForUnvalidatedValue != null) {
|
4920 | return cachedAnswerForUnvalidatedValue;
|
4921 | }
|
4922 |
|
4923 | if (persistence == null) {
|
4924 | Recoil_expectationViolation(`Tried to restore a persisted value for atom ${key} but it has no persistence settings.`);
|
4925 | return [new Map(), defaultLoadable];
|
4926 | }
|
4927 |
|
4928 | const nonvalidatedValue = state.nonvalidatedAtoms.get(key);
|
4929 | const validatorResult = persistence.validator(nonvalidatedValue, DEFAULT_VALUE$5);
|
4930 | const validatedValueLoadable = validatorResult instanceof DefaultValue$2 ? defaultLoadable : loadableWithValue$3(validatorResult);
|
4931 | cachedAnswerForUnvalidatedValue = [new Map(), validatedValueLoadable];
|
4932 | return cachedAnswerForUnvalidatedValue;
|
4933 | } else {
|
4934 | return [new Map(), defaultLoadable];
|
4935 | }
|
4936 | }
|
4937 |
|
4938 | function myCleanup(store) {
|
4939 | var _cleanupEffectsByStor;
|
4940 |
|
4941 | (_cleanupEffectsByStor = cleanupEffectsByStore.get(store)) === null || _cleanupEffectsByStor === void 0 ? void 0 : _cleanupEffectsByStor();
|
4942 | cleanupEffectsByStore.delete(store);
|
4943 | }
|
4944 |
|
4945 | function invalidate() {
|
4946 | cachedAnswerForUnvalidatedValue = undefined;
|
4947 | }
|
4948 |
|
4949 | function mySet(store, state, newValue) {
|
4950 | initAtom(store, state, 'set');
|
4951 |
|
4952 |
|
4953 | if (state.atomValues.has(key)) {
|
4954 | const existing = Recoil_nullthrows(state.atomValues.get(key));
|
4955 |
|
4956 | if (existing.state === 'hasValue' && newValue === existing.contents) {
|
4957 | return [new Map(), new Map()];
|
4958 | }
|
4959 | } else if (!state.nonvalidatedAtoms.has(key) && newValue instanceof DefaultValue$2) {
|
4960 | return [new Map(), new Map()];
|
4961 | }
|
4962 |
|
4963 | if (process.env.NODE_ENV !== "production") {
|
4964 | if (options.dangerouslyAllowMutability !== true) {
|
4965 | Recoil_deepFreezeValue(newValue);
|
4966 | }
|
4967 | }
|
4968 |
|
4969 | cachedAnswerForUnvalidatedValue = undefined;
|
4970 |
|
4971 | return [new Map(), new Map().set(key, loadableWithValue$3(newValue))];
|
4972 | }
|
4973 |
|
4974 | const node = registerNode$3({
|
4975 | key,
|
4976 | peek: myPeek,
|
4977 | get: myGet,
|
4978 | set: mySet,
|
4979 | cleanUp: myCleanup,
|
4980 | invalidate,
|
4981 | dangerouslyAllowMutability: options.dangerouslyAllowMutability,
|
4982 | persistence_UNSTABLE: options.persistence_UNSTABLE ? {
|
4983 | type: options.persistence_UNSTABLE.type,
|
4984 | backButton: options.persistence_UNSTABLE.backButton
|
4985 | } : undefined,
|
4986 | shouldRestoreFromSnapshots: true
|
4987 | });
|
4988 | return node;
|
4989 | }
|
4990 |
|
4991 |
|
4992 | function atom(options) {
|
4993 | const {
|
4994 | default: optionsDefault,
|
4995 |
|
4996 | ...restOptions
|
4997 | } = options;
|
4998 |
|
4999 | if (isRecoilValue$5(optionsDefault)
|
5000 |
|
5001 |
|
5002 | ) {
|
5003 | return atomWithFallback({ ...restOptions,
|
5004 | default: optionsDefault
|
5005 |
|
5006 | });
|
5007 |
|
5008 |
|
5009 |
|
5010 |
|
5011 |
|
5012 | } else {
|
5013 | return baseAtom({ ...restOptions,
|
5014 | default: optionsDefault
|
5015 | });
|
5016 | }
|
5017 | }
|
5018 |
|
5019 | function atomWithFallback(options) {
|
5020 | const base = atom({ ...options,
|
5021 | default: DEFAULT_VALUE$5,
|
5022 | persistence_UNSTABLE: options.persistence_UNSTABLE === undefined ? undefined : { ...options.persistence_UNSTABLE,
|
5023 | validator: storedValue => storedValue instanceof DefaultValue$2 ? storedValue : Recoil_nullthrows(options.persistence_UNSTABLE).validator(storedValue, DEFAULT_VALUE$5)
|
5024 | },
|
5025 |
|
5026 |
|
5027 | effects_UNSTABLE: options.effects_UNSTABLE
|
5028 | });
|
5029 | return Recoil_selector({
|
5030 | key: `${options.key}__withFallback`,
|
5031 | get: ({
|
5032 | get
|
5033 | }) => {
|
5034 | const baseValue = get(base);
|
5035 | return baseValue instanceof DefaultValue$2 ? options.default : baseValue;
|
5036 | },
|
5037 | set: ({
|
5038 | set
|
5039 | }, newValue) => set(base, newValue),
|
5040 | dangerouslyAllowMutability: options.dangerouslyAllowMutability
|
5041 | });
|
5042 | }
|
5043 |
|
5044 | var Recoil_atom = atom;
|
5045 |
|
5046 | // Keep in mind the parameter needs to be serializable as a cahche key
|
5047 | // using Recoil_stableStringify
|
5048 |
|
5049 |
|
5050 | // Add a unique index to each selector in case the cache implementation allows
|
5051 | // duplicate keys based on equivalent stringified parameters
|
5052 | let nextIndex = 0;
|
5053 | /* eslint-disable no-redeclare */
|
5054 |
|
5055 | // Return a function that returns members of a family of selectors of the same type
|
5056 | // E.g.,
|
5057 | //
|
5058 | // const s = selectorFamily(...);
|
5059 | // s({a: 1}) => a selector
|
5060 |
|
5061 |
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 | function selectorFamily(options) {
|
5068 | var _options$cacheImpleme, _options$cacheImpleme2;
|
5069 |
|
5070 | let selectorCache = (_options$cacheImpleme = (_options$cacheImpleme2 = options.cacheImplementationForParams_UNSTABLE) === null || _options$cacheImpleme2 === void 0 ? void 0 : _options$cacheImpleme2.call(options)) !== null && _options$cacheImpleme !== void 0 ? _options$cacheImpleme : Recoil_cacheWithValueEquality();
|
5071 | return params => {
|
5072 | var _stableStringify, _options$cacheImpleme3;
|
5073 |
|
5074 | const cachedSelector = selectorCache.get(params);
|
5075 |
|
5076 | if (cachedSelector != null) {
|
5077 | return cachedSelector;
|
5078 | }
|
5079 |
|
5080 | const myKey = `${options.key}__selectorFamily/${(_stableStringify = Recoil_stableStringify(params, {
|
5081 | // It is possible to use functions in parameters if the user uses
|
5082 | // a cache with reference equality thanks to the incrementing index.
|
5083 | allowFunctions: true
|
5084 | })) !== null && _stableStringify !== void 0 ? _stableStringify : 'void'}/${nextIndex++}`;
|
5085 |
|
5086 | const myGet = callbacks => options.get(params)(callbacks);
|
5087 |
|
5088 | const myCacheImplementation = (_options$cacheImpleme3 = options.cacheImplementation_UNSTABLE) === null || _options$cacheImpleme3 === void 0 ? void 0 : _options$cacheImpleme3.call(options);
|
5089 | let newSelector;
|
5090 |
|
5091 | if (options.set != null) {
|
5092 | const set = options.set;
|
5093 |
|
5094 | const mySet = (callbacks, newValue) => set(params)(callbacks, newValue);
|
5095 |
|
5096 | newSelector = Recoil_selector({
|
5097 | key: myKey,
|
5098 | get: myGet,
|
5099 | set: mySet,
|
5100 | cacheImplementation_UNSTABLE: myCacheImplementation,
|
5101 | dangerouslyAllowMutability: options.dangerouslyAllowMutability
|
5102 | });
|
5103 | } else {
|
5104 | newSelector = Recoil_selector({
|
5105 | key: myKey,
|
5106 | get: myGet,
|
5107 | cacheImplementation_UNSTABLE: myCacheImplementation,
|
5108 | dangerouslyAllowMutability: options.dangerouslyAllowMutability
|
5109 | });
|
5110 | }
|
5111 |
|
5112 | selectorCache = selectorCache.set(params, newSelector);
|
5113 | return newSelector;
|
5114 | };
|
5115 | }
|
5116 | /* eslint-enable no-redeclare */
|
5117 |
|
5118 |
|
5119 | var Recoil_selectorFamily = selectorFamily;
|
5120 |
|
5121 | // @fb-only: const {parameterizedScopedAtomLegacy} = require('Recoil_ScopedAtom');
|
5122 |
|
5123 |
|
5124 | const {
|
5125 | DEFAULT_VALUE: DEFAULT_VALUE$6,
|
5126 | DefaultValue: DefaultValue$3
|
5127 | } = Recoil_Node;
|
5128 |
|
5129 |
|
5130 |
|
5131 |
|
5132 |
|
5133 |
|
5134 |
|
5135 |
|
5136 |
|
5137 |
|
5138 |
|
5139 |
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 |
|
5145 | function atomFamily(options) {
|
5146 | let atomCache = Recoil_cacheWithValueEquality();
|
5147 |
|
5148 | const legacyAtomOptions = {
|
5149 | key: options.key,
|
5150 |
|
5151 | default: DEFAULT_VALUE$6,
|
5152 | persistence_UNSTABLE: options.persistence_UNSTABLE
|
5153 | };
|
5154 | let legacyAtom;
|
5155 |
|
5156 |
|
5157 |
|
5158 |
|
5159 |
|
5160 |
|
5161 |
|
5162 |
|
5163 |
|
5164 |
|
5165 | legacyAtom = Recoil_atom(legacyAtomOptions);
|
5166 |
|
5167 |
|
5168 |
|
5169 | const atomFamilyDefault = Recoil_selectorFamily({
|
5170 | key: `${options.key}__atomFamily/Default`,
|
5171 | get: param => ({
|
5172 | get
|
5173 | }) => {
|
5174 | const legacyValue = get(typeof legacyAtom === 'function' ? legacyAtom(param) : legacyAtom); // Atom was upgraded from a non-parameterized atom
|
5175 |
|
5176 | if (!(legacyValue instanceof DefaultValue$3)) {
|
5177 | return legacyValue;
|
5178 | }
|
5179 |
|
5180 |
|
5181 | return typeof options.default === 'function' ?
|
5182 |
|
5183 | options.default(param)
|
5184 | :
|
5185 | options.default;
|
5186 | },
|
5187 | dangerouslyAllowMutability: options.dangerouslyAllowMutability
|
5188 | });
|
5189 |
|
5190 |
|
5191 | return params => {
|
5192 | var _stableStringify;
|
5193 |
|
5194 | const cachedAtom = atomCache.get(params);
|
5195 |
|
5196 | if (cachedAtom != null) {
|
5197 | return cachedAtom;
|
5198 | }
|
5199 |
|
5200 | const newAtom = Recoil_atom({ ...options,
|
5201 | key: `${options.key}__${(_stableStringify = Recoil_stableStringify(params)) !== null && _stableStringify !== void 0 ? _stableStringify : 'void'}`,
|
5202 | default: atomFamilyDefault(params),
|
5203 | effects_UNSTABLE: typeof options.effects_UNSTABLE === 'function' ? options.effects_UNSTABLE(params) : options.effects_UNSTABLE
|
5204 |
|
5205 |
|
5206 |
|
5207 |
|
5208 |
|
5209 | });
|
5210 | atomCache = atomCache.set(params, newAtom);
|
5211 | return newAtom;
|
5212 | };
|
5213 | }
|
5214 |
|
5215 | var Recoil_atomFamily = atomFamily;
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 | const constantSelector = Recoil_selectorFamily({
|
5221 | key: '__constant',
|
5222 | get: constant => () => constant,
|
5223 | cacheImplementationForParams_UNSTABLE: Recoil_cacheWithReferenceEquality
|
5224 | }); // Function that returns a selector which always produces the
|
5225 | // same constant value. It may be called multiple times with the
|
5226 | // same value, based on reference equality, and will provide the
|
5227 | // same selector.
|
5228 |
|
5229 | function constSelector(constant) {
|
5230 | return constantSelector(constant);
|
5231 | }
|
5232 |
|
5233 | var Recoil_constSelector = constSelector;
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 | const throwingSelector = Recoil_selectorFamily({
|
5239 | key: '__error',
|
5240 | get: message => () => {
|
5241 | throw new Error(message);
|
5242 | },
|
5243 | cacheImplementationForParams_UNSTABLE: Recoil_cacheWithReferenceEquality
|
5244 | });
|
5245 |
|
5246 |
|
5247 | function errorSelector(message) {
|
5248 | return throwingSelector(message);
|
5249 | }
|
5250 |
|
5251 | var Recoil_errorSelector = errorSelector;
|
5252 |
|
5253 |
|
5254 |
|
5255 |
|
5256 |
|
5257 |
|
5258 |
|
5259 |
|
5260 |
|
5261 |
|
5262 |
|
5263 |
|
5264 |
|
5265 |
|
5266 | function readOnlySelector(atom) {
|
5267 |
|
5268 | return atom;
|
5269 | }
|
5270 |
|
5271 | var Recoil_readOnlySelector = readOnlySelector;
|
5272 |
|
5273 | const {
|
5274 | loadableWithError: loadableWithError$4,
|
5275 | loadableWithPromise: loadableWithPromise$4,
|
5276 | loadableWithValue: loadableWithValue$4
|
5277 | } = Recoil_Loadable;
|
5278 |
|
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 |
|
5294 |
|
5295 |
|
5296 |
|
5297 |
|
5298 | function concurrentRequests(getRecoilValue, deps) {
|
5299 | const results = Array(deps.length).fill(undefined);
|
5300 | const exceptions = Array(deps.length).fill(undefined);
|
5301 |
|
5302 | for (const [i, dep] of deps.entries()) {
|
5303 | try {
|
5304 | results[i] = getRecoilValue(dep);
|
5305 | } catch (e) {
|
5306 |
|
5307 | exceptions[i] = e;
|
5308 | }
|
5309 | }
|
5310 |
|
5311 | return [results, exceptions];
|
5312 | }
|
5313 |
|
5314 | function isError(exp) {
|
5315 | return exp != null && !Recoil_isPromise(exp);
|
5316 | }
|
5317 |
|
5318 | function unwrapDependencies(dependencies) {
|
5319 | return Array.isArray(dependencies) ? dependencies : Object.getOwnPropertyNames(dependencies).map(key => dependencies[key]);
|
5320 | }
|
5321 |
|
5322 | function getValueFromLoadablePromiseResult(result) {
|
5323 | if (result != null && typeof result === 'object' && result.hasOwnProperty('__value')) {
|
5324 | return result.__value;
|
5325 | }
|
5326 |
|
5327 | return result;
|
5328 | }
|
5329 |
|
5330 | function wrapResults(dependencies, results) {
|
5331 | return Array.isArray(dependencies) ? results :
|
5332 | Object.getOwnPropertyNames(dependencies).reduce((out, key, idx) => ({ ...out,
|
5333 | [key]: results[idx]
|
5334 | }), {});
|
5335 | }
|
5336 |
|
5337 | function wrapLoadables(dependencies, results, exceptions) {
|
5338 | const output = exceptions.map((exception, idx) => exception == null ? loadableWithValue$4(results[idx]) : Recoil_isPromise(exception) ? loadableWithPromise$4(exception) : loadableWithError$4(exception));
|
5339 | return wrapResults(dependencies, output);
|
5340 | }
|
5341 |
|
5342 | function combineAsyncResultsWithSyncResults(syncResults, asyncResults) {
|
5343 | return asyncResults.map((result, idx) =>
|
5344 | |
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 | result === undefined ? syncResults[idx] : result);
|
5352 | }
|
5353 |
|
5354 |
|
5355 |
|
5356 | const waitForNone = Recoil_selectorFamily({
|
5357 | key: '__waitForNone',
|
5358 | get: dependencies => ({
|
5359 | get
|
5360 | }) => {
|
5361 |
|
5362 | const deps = unwrapDependencies(dependencies);
|
5363 | const [results, exceptions] = concurrentRequests(get, deps); // Always return the current status of the results; never block.
|
5364 |
|
5365 | return wrapLoadables(dependencies, results, exceptions);
|
5366 | }
|
5367 | }); // Selector that requests all dependencies in parallel and waits for at least
|
5368 | // one to be available before returning results. It will only error if all
|
5369 | // dependencies have errors.
|
5370 |
|
5371 | const waitForAny = Recoil_selectorFamily({
|
5372 | key: '__waitForAny',
|
5373 | get: dependencies => ({
|
5374 | get
|
5375 | }) => {
|
5376 |
|
5377 |
|
5378 | const deps = unwrapDependencies(dependencies);
|
5379 | const [results, exceptions] = concurrentRequests(get, deps); // If any results are available, return the current status
|
5380 |
|
5381 | if (exceptions.some(exp => exp == null)) {
|
5382 | return wrapLoadables(dependencies, results, exceptions);
|
5383 | }
|
5384 |
|
5385 |
|
5386 |
|
5387 | if (exceptions.every(isError)) {
|
5388 | throw exceptions.find(isError);
|
5389 | }
|
5390 |
|
5391 | if (Recoil_gkx_1('recoil_async_selector_refactor')) {
|
5392 |
|
5393 |
|
5394 |
|
5395 | return new Promise((resolve, reject) => {
|
5396 | for (const [i, exp] of exceptions.entries()) {
|
5397 | if (Recoil_isPromise(exp)) {
|
5398 | exp.then(result => {
|
5399 | results[i] = getValueFromLoadablePromiseResult(result);
|
5400 | exceptions[i] = null;
|
5401 | resolve(wrapLoadables(dependencies, results, exceptions));
|
5402 | }).catch(error => {
|
5403 | exceptions[i] = error;
|
5404 |
|
5405 | if (exceptions.every(isError)) {
|
5406 | reject(exceptions[0]);
|
5407 | }
|
5408 | });
|
5409 | }
|
5410 | }
|
5411 | });
|
5412 | } else {
|
5413 | throw new Promise((resolve, reject) => {
|
5414 | for (const [i, exp] of exceptions.entries()) {
|
5415 | if (Recoil_isPromise(exp)) {
|
5416 | exp.then(result => {
|
5417 | results[i] = result;
|
5418 | exceptions[i] = null;
|
5419 | resolve(wrapLoadables(dependencies, results, exceptions));
|
5420 | }).catch(error => {
|
5421 | exceptions[i] = error;
|
5422 |
|
5423 | if (exceptions.every(isError)) {
|
5424 | reject(exceptions[0]);
|
5425 | }
|
5426 | });
|
5427 | }
|
5428 | }
|
5429 | });
|
5430 | }
|
5431 | }
|
5432 | });
|
5433 |
|
5434 |
|
5435 | const waitForAll = Recoil_selectorFamily({
|
5436 | key: '__waitForAll',
|
5437 | get: dependencies => ({
|
5438 | get
|
5439 | }) => {
|
5440 |
|
5441 |
|
5442 | const deps = unwrapDependencies(dependencies);
|
5443 | const [results, exceptions] = concurrentRequests(get, deps); // If all results are available, return the results
|
5444 |
|
5445 | if (exceptions.every(exp => exp == null)) {
|
5446 | return wrapResults(dependencies, results);
|
5447 | }
|
5448 |
|
5449 |
|
5450 | const error = exceptions.find(isError);
|
5451 |
|
5452 | if (error != null) {
|
5453 | throw error;
|
5454 | }
|
5455 |
|
5456 | if (Recoil_gkx_1('recoil_async_selector_refactor')) {
|
5457 |
|
5458 | return Promise.all(exceptions).then(exceptionResults => wrapResults(dependencies, combineAsyncResultsWithSyncResults(results, exceptionResults).map(getValueFromLoadablePromiseResult)));
|
5459 | } else {
|
5460 | throw Promise.all(exceptions).then(results => wrapResults(dependencies, results));
|
5461 | }
|
5462 | }
|
5463 | });
|
5464 | const noWait = Recoil_selectorFamily({
|
5465 | key: '__noWait',
|
5466 | get: dependency => ({
|
5467 | get
|
5468 | }) => {
|
5469 | try {
|
5470 | return loadableWithValue$4(get(dependency));
|
5471 | } catch (exception) {
|
5472 | return Recoil_isPromise(exception) ? loadableWithPromise$4(exception) : loadableWithError$4(exception);
|
5473 | }
|
5474 | }
|
5475 | });
|
5476 | var Recoil_WaitFor = {
|
5477 | waitForNone,
|
5478 | waitForAny,
|
5479 | waitForAll,
|
5480 | noWait
|
5481 | };
|
5482 |
|
5483 | const {
|
5484 | batchUpdates: batchUpdates$3,
|
5485 | setBatcher: setBatcher$1
|
5486 | } = Recoil_Batching;
|
5487 |
|
5488 | const {
|
5489 | DefaultValue: DefaultValue$4
|
5490 | } = Recoil_Node;
|
5491 |
|
5492 | const {
|
5493 | RecoilRoot: RecoilRoot$2
|
5494 | } = Recoil_RecoilRoot_react;
|
5495 |
|
5496 | const {
|
5497 | isRecoilValue: isRecoilValue$6
|
5498 | } = Recoil_RecoilValue$1;
|
5499 |
|
5500 | const {
|
5501 | freshSnapshot: freshSnapshot$2
|
5502 | } = Recoil_Snapshot$1;
|
5503 |
|
5504 | const {
|
5505 | useGotoRecoilSnapshot: useGotoRecoilSnapshot$1,
|
5506 | useRecoilCallback: useRecoilCallback$1,
|
5507 | useRecoilSnapshot: useRecoilSnapshot$1,
|
5508 | useRecoilState: useRecoilState$1,
|
5509 | useRecoilStateLoadable: useRecoilStateLoadable$1,
|
5510 | useRecoilTransactionObserver: useRecoilTransactionObserver$1,
|
5511 | useRecoilValue: useRecoilValue$1,
|
5512 | useRecoilValueLoadable: useRecoilValueLoadable$1,
|
5513 | useResetRecoilState: useResetRecoilState$1,
|
5514 | useSetRecoilState: useSetRecoilState$1,
|
5515 | useSetUnvalidatedAtomValues: useSetUnvalidatedAtomValues$1,
|
5516 | useTransactionObservation_DEPRECATED: useTransactionObservation_DEPRECATED$1
|
5517 | } = Recoil_Hooks;
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 | const {
|
5536 | noWait: noWait$1,
|
5537 | waitForAll: waitForAll$1,
|
5538 | waitForAny: waitForAny$1,
|
5539 | waitForNone: waitForNone$1
|
5540 | } = Recoil_WaitFor;
|
5541 |
|
5542 | var Recoil_index = {
|
5543 |
|
5544 | DefaultValue: DefaultValue$4,
|
5545 |
|
5546 | RecoilRoot: RecoilRoot$2,
|
5547 | useRecoilBridgeAcrossReactRoots_UNSTABLE: Recoil_useRecoilBridgeAcrossReactRoots,
|
5548 |
|
5549 | atom: Recoil_atom,
|
5550 | selector: Recoil_selector,
|
5551 |
|
5552 | atomFamily: Recoil_atomFamily,
|
5553 | selectorFamily: Recoil_selectorFamily,
|
5554 | constSelector: Recoil_constSelector,
|
5555 | errorSelector: Recoil_errorSelector,
|
5556 | readOnlySelector: Recoil_readOnlySelector,
|
5557 |
|
5558 | useRecoilValue: useRecoilValue$1,
|
5559 | useRecoilValueLoadable: useRecoilValueLoadable$1,
|
5560 | useRecoilState: useRecoilState$1,
|
5561 | useRecoilStateLoadable: useRecoilStateLoadable$1,
|
5562 | useSetRecoilState: useSetRecoilState$1,
|
5563 | useResetRecoilState: useResetRecoilState$1,
|
5564 |
|
5565 | useRecoilCallback: useRecoilCallback$1,
|
5566 |
|
5567 | useGotoRecoilSnapshot: useGotoRecoilSnapshot$1,
|
5568 | useRecoilSnapshot: useRecoilSnapshot$1,
|
5569 | useRecoilTransactionObserver_UNSTABLE: useRecoilTransactionObserver$1,
|
5570 | useTransactionObservation_UNSTABLE: useTransactionObservation_DEPRECATED$1,
|
5571 | useSetUnvalidatedAtomValues_UNSTABLE: useSetUnvalidatedAtomValues$1,
|
5572 |
|
5573 | noWait: noWait$1,
|
5574 | waitForNone: waitForNone$1,
|
5575 | waitForAny: waitForAny$1,
|
5576 | waitForAll: waitForAll$1,
|
5577 |
|
5578 | isRecoilValue: isRecoilValue$6,
|
5579 |
|
5580 | batchUpdates: batchUpdates$3,
|
5581 | setBatcher: setBatcher$1,
|
5582 |
|
5583 | snapshot_UNSTABLE: freshSnapshot$2
|
5584 | };
|
5585 | var Recoil_index_1 = Recoil_index.DefaultValue;
|
5586 | var Recoil_index_2 = Recoil_index.RecoilRoot;
|
5587 | var Recoil_index_3 = Recoil_index.useRecoilBridgeAcrossReactRoots_UNSTABLE;
|
5588 | var Recoil_index_4 = Recoil_index.atom;
|
5589 | var Recoil_index_5 = Recoil_index.selector;
|
5590 | var Recoil_index_6 = Recoil_index.atomFamily;
|
5591 | var Recoil_index_7 = Recoil_index.selectorFamily;
|
5592 | var Recoil_index_8 = Recoil_index.constSelector;
|
5593 | var Recoil_index_9 = Recoil_index.errorSelector;
|
5594 | var Recoil_index_10 = Recoil_index.readOnlySelector;
|
5595 | var Recoil_index_11 = Recoil_index.useRecoilValue;
|
5596 | var Recoil_index_12 = Recoil_index.useRecoilValueLoadable;
|
5597 | var Recoil_index_13 = Recoil_index.useRecoilState;
|
5598 | var Recoil_index_14 = Recoil_index.useRecoilStateLoadable;
|
5599 | var Recoil_index_15 = Recoil_index.useSetRecoilState;
|
5600 | var Recoil_index_16 = Recoil_index.useResetRecoilState;
|
5601 | var Recoil_index_17 = Recoil_index.useRecoilCallback;
|
5602 | var Recoil_index_18 = Recoil_index.useGotoRecoilSnapshot;
|
5603 | var Recoil_index_19 = Recoil_index.useRecoilSnapshot;
|
5604 | var Recoil_index_20 = Recoil_index.useRecoilTransactionObserver_UNSTABLE;
|
5605 | var Recoil_index_21 = Recoil_index.useTransactionObservation_UNSTABLE;
|
5606 | var Recoil_index_22 = Recoil_index.useSetUnvalidatedAtomValues_UNSTABLE;
|
5607 | var Recoil_index_23 = Recoil_index.noWait;
|
5608 | var Recoil_index_24 = Recoil_index.waitForNone;
|
5609 | var Recoil_index_25 = Recoil_index.waitForAny;
|
5610 | var Recoil_index_26 = Recoil_index.waitForAll;
|
5611 | var Recoil_index_27 = Recoil_index.isRecoilValue;
|
5612 | var Recoil_index_28 = Recoil_index.batchUpdates;
|
5613 | var Recoil_index_29 = Recoil_index.setBatcher;
|
5614 | var Recoil_index_30 = Recoil_index.snapshot_UNSTABLE;
|
5615 |
|
5616 | exports.DefaultValue = Recoil_index_1;
|
5617 | exports.RecoilRoot = Recoil_index_2;
|
5618 | exports.atom = Recoil_index_4;
|
5619 | exports.atomFamily = Recoil_index_6;
|
5620 | exports.batchUpdates = Recoil_index_28;
|
5621 | exports.constSelector = Recoil_index_8;
|
5622 | exports.default = Recoil_index;
|
5623 | exports.errorSelector = Recoil_index_9;
|
5624 | exports.isRecoilValue = Recoil_index_27;
|
5625 | exports.noWait = Recoil_index_23;
|
5626 | exports.readOnlySelector = Recoil_index_10;
|
5627 | exports.selector = Recoil_index_5;
|
5628 | exports.selectorFamily = Recoil_index_7;
|
5629 | exports.setBatcher = Recoil_index_29;
|
5630 | exports.snapshot_UNSTABLE = Recoil_index_30;
|
5631 | exports.useGotoRecoilSnapshot = Recoil_index_18;
|
5632 | exports.useRecoilBridgeAcrossReactRoots_UNSTABLE = Recoil_index_3;
|
5633 | exports.useRecoilCallback = Recoil_index_17;
|
5634 | exports.useRecoilSnapshot = Recoil_index_19;
|
5635 | exports.useRecoilState = Recoil_index_13;
|
5636 | exports.useRecoilStateLoadable = Recoil_index_14;
|
5637 | exports.useRecoilTransactionObserver_UNSTABLE = Recoil_index_20;
|
5638 | exports.useRecoilValue = Recoil_index_11;
|
5639 | exports.useRecoilValueLoadable = Recoil_index_12;
|
5640 | exports.useResetRecoilState = Recoil_index_16;
|
5641 | exports.useSetRecoilState = Recoil_index_15;
|
5642 | exports.useSetUnvalidatedAtomValues_UNSTABLE = Recoil_index_22;
|
5643 | exports.useTransactionObservation_UNSTABLE = Recoil_index_21;
|
5644 | exports.waitForAll = Recoil_index_26;
|
5645 | exports.waitForAny = Recoil_index_25;
|
5646 | exports.waitForNone = Recoil_index_24;
|