atom.io 0.9.10 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +36 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -55
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +30 -19
- package/internal/dist/index.d.ts +30 -19
- package/internal/dist/index.js +156 -184
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +157 -185
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/create-atom.ts +5 -5
- package/internal/src/atom/delete-atom.ts +9 -2
- package/internal/src/caching.ts +5 -5
- package/internal/src/get-state-internal.ts +4 -4
- package/internal/src/mutable/create-mutable-atom.ts +2 -2
- package/internal/src/mutable/tracker.ts +1 -1
- package/internal/src/operation.ts +7 -7
- package/internal/src/selector/create-read-write-selector.ts +2 -8
- package/internal/src/selector/create-readonly-selector.ts +1 -1
- package/internal/src/selector/create-selector.ts +5 -3
- package/internal/src/selector/register-selector.ts +4 -11
- package/internal/src/selector/update-selector-atoms.ts +14 -14
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +5 -6
- package/internal/src/set-state/set-atom.ts +1 -4
- package/internal/src/set-state/stow-update.ts +10 -4
- package/internal/src/store/store.ts +27 -10
- package/internal/src/store/withdraw-new-family-member.ts +1 -1
- package/internal/src/store/withdraw.ts +1 -1
- package/internal/src/subscribe/recall-state.ts +2 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/timeline/add-atom-to-timeline.ts +8 -8
- package/internal/src/timeline/time-travel-internal.ts +12 -12
- package/internal/src/timeline/timeline-internal.ts +2 -2
- package/internal/src/transaction/abort-transaction.ts +3 -3
- package/internal/src/transaction/apply-transaction.ts +6 -6
- package/internal/src/transaction/build-transaction.ts +2 -3
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/transaction-internal.ts +2 -2
- package/internal/src/transaction/undo-transaction.ts +1 -1
- package/package.json +2 -2
- package/react-devtools/dist/index.d.mts +3 -3
- package/react-devtools/dist/index.d.ts +3 -3
- package/realtime-client/dist/index.js +6 -9
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/dist/index.mjs +6 -9
- package/realtime-client/dist/index.mjs.map +1 -1
- package/realtime-client/src/use-server-action.ts +6 -8
- package/src/atom.ts +3 -0
- package/src/logger.ts +25 -36
- package/src/subscribe.ts +7 -7
package/internal/dist/index.js
CHANGED
|
@@ -311,20 +311,37 @@ var Store = class {
|
|
|
311
311
|
this.operation = { open: false };
|
|
312
312
|
this.transactionStatus = { phase: `idle` };
|
|
313
313
|
this.config = {
|
|
314
|
-
name: `IMPLICIT_STORE
|
|
315
|
-
|
|
316
|
-
|
|
314
|
+
name: `IMPLICIT_STORE`
|
|
315
|
+
};
|
|
316
|
+
this.loggers = [
|
|
317
|
+
new atom_io.AtomIOLogger(
|
|
318
|
+
__spreadValues({}, console),
|
|
319
|
+
`warn`,
|
|
320
|
+
(message) => !message.includes(`\u{1F441}\u200D\u{1F5E8}`)
|
|
321
|
+
)
|
|
322
|
+
];
|
|
323
|
+
this.logger = {
|
|
324
|
+
error: (message) => {
|
|
325
|
+
for (const logger of this.loggers) {
|
|
326
|
+
logger.error(message);
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
info: (message) => {
|
|
330
|
+
for (const logger of this.loggers) {
|
|
331
|
+
logger.info(message);
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
warn: (message) => {
|
|
335
|
+
for (const logger of this.loggers) {
|
|
336
|
+
logger.warn(message);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
317
339
|
};
|
|
318
|
-
var _a;
|
|
319
340
|
if (store !== null) {
|
|
320
341
|
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
321
342
|
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
322
343
|
this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
|
|
323
344
|
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
324
|
-
logger__INTERNAL: console,
|
|
325
|
-
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
326
|
-
info: () => void 0
|
|
327
|
-
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
328
345
|
name
|
|
329
346
|
});
|
|
330
347
|
for (const [, atom] of store.atoms) {
|
|
@@ -360,31 +377,29 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
360
377
|
|
|
361
378
|
// src/transaction/abort-transaction.ts
|
|
362
379
|
var abortTransaction = (store) => {
|
|
363
|
-
var _a, _b;
|
|
364
380
|
if (store.transactionStatus.phase === `idle`) {
|
|
365
|
-
|
|
366
|
-
|
|
381
|
+
store.logger.warn(
|
|
382
|
+
`\u{1F41E} abortTransaction called outside of a transaction. This is probably a bug.`
|
|
367
383
|
);
|
|
368
384
|
return;
|
|
369
385
|
}
|
|
370
386
|
store.transactionStatus = { phase: `idle` };
|
|
371
|
-
|
|
387
|
+
store.logger.info(`\u{1FA82}`, `transaction fail`);
|
|
372
388
|
};
|
|
373
389
|
var applyTransaction = (output, store) => {
|
|
374
|
-
var _a, _b, _c, _d, _e;
|
|
375
390
|
if (store.transactionStatus.phase !== `building`) {
|
|
376
|
-
|
|
377
|
-
|
|
391
|
+
store.logger.warn(
|
|
392
|
+
`\u{1F41E} applyTransaction called outside of a transaction. This is probably a bug.`
|
|
378
393
|
);
|
|
379
394
|
return;
|
|
380
395
|
}
|
|
381
396
|
store.transactionStatus.phase = `applying`;
|
|
382
397
|
store.transactionStatus.output = output;
|
|
383
398
|
const { atomUpdates } = store.transactionStatus;
|
|
384
|
-
|
|
399
|
+
store.logger.info(
|
|
385
400
|
`\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
|
|
386
401
|
);
|
|
387
|
-
|
|
402
|
+
store.logger.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
388
403
|
for (const { key, newValue } of atomUpdates) {
|
|
389
404
|
const token = { key, type: `atom` };
|
|
390
405
|
if (!store.valueMap.has(token.key)) {
|
|
@@ -402,7 +417,7 @@ var applyTransaction = (output, store) => {
|
|
|
402
417
|
}
|
|
403
418
|
store.atoms.set(newAtom.key, newAtom);
|
|
404
419
|
store.valueMap.set(newAtom.key, newAtom.default);
|
|
405
|
-
|
|
420
|
+
store.logger.info(`\u{1F527} add atom "${newAtom.key}"`);
|
|
406
421
|
}
|
|
407
422
|
}
|
|
408
423
|
atom_io.setState(token, newValue, store);
|
|
@@ -423,12 +438,11 @@ var applyTransaction = (output, store) => {
|
|
|
423
438
|
params: store.transactionStatus.params
|
|
424
439
|
});
|
|
425
440
|
store.transactionStatus = { phase: `idle` };
|
|
426
|
-
|
|
441
|
+
store.logger.info(`\u{1F6EC} transaction "${myTransaction.key}" applied`);
|
|
427
442
|
};
|
|
428
443
|
|
|
429
444
|
// src/transaction/build-transaction.ts
|
|
430
445
|
var buildTransaction = (key, params, store) => {
|
|
431
|
-
var _a;
|
|
432
446
|
store.transactionStatus = {
|
|
433
447
|
key,
|
|
434
448
|
phase: `building`,
|
|
@@ -454,9 +468,8 @@ var buildTransaction = (key, params, store) => {
|
|
|
454
468
|
params,
|
|
455
469
|
output: void 0
|
|
456
470
|
};
|
|
457
|
-
|
|
458
|
-
`\u{1F6EB}
|
|
459
|
-
`transaction "${key}" building in store "${store.config.name}"`
|
|
471
|
+
store.logger.info(
|
|
472
|
+
`\u{1F6EB} transaction "${key}" building in store "${store.config.name}"`
|
|
460
473
|
);
|
|
461
474
|
};
|
|
462
475
|
|
|
@@ -466,7 +479,6 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
466
479
|
key: options.key,
|
|
467
480
|
type: `transaction`,
|
|
468
481
|
run: (...params) => {
|
|
469
|
-
var _a;
|
|
470
482
|
buildTransaction(options.key, params, store);
|
|
471
483
|
try {
|
|
472
484
|
const output = options.do(
|
|
@@ -480,8 +492,8 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
480
492
|
return output;
|
|
481
493
|
} catch (thrown) {
|
|
482
494
|
abortTransaction(store);
|
|
483
|
-
|
|
484
|
-
|
|
495
|
+
store.logger.error(
|
|
496
|
+
`\u2757 Transaction "${options.key}" failed in store "${store.config.name}":`,
|
|
485
497
|
thrown
|
|
486
498
|
);
|
|
487
499
|
throw thrown;
|
|
@@ -498,8 +510,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
498
510
|
}
|
|
499
511
|
var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
|
|
500
512
|
var redoTransactionUpdate = (update, store) => {
|
|
501
|
-
|
|
502
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23ED redo transaction "${update.key}" (redo)`);
|
|
513
|
+
store.logger.info(` \u23ED redo transaction "${update.key}" (redo)`);
|
|
503
514
|
for (const { key, newValue } of update.atomUpdates) {
|
|
504
515
|
const token = { key, type: `atom` };
|
|
505
516
|
const state = withdraw(token, store);
|
|
@@ -512,8 +523,7 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
512
523
|
}
|
|
513
524
|
};
|
|
514
525
|
var undoTransactionUpdate = (update, store) => {
|
|
515
|
-
|
|
516
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23EE undo transaction "${update.key}" (undo)`);
|
|
526
|
+
store.logger.info(` \u23EE undo transaction "${update.key}" (undo)`);
|
|
517
527
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
518
528
|
const token = { key, type: `atom` };
|
|
519
529
|
const state = withdraw(token, store);
|
|
@@ -538,12 +548,12 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
538
548
|
);
|
|
539
549
|
}
|
|
540
550
|
atom.subject.subscribe(`timeline`, (update) => {
|
|
541
|
-
var _a, _b, _c, _d
|
|
551
|
+
var _a, _b, _c, _d;
|
|
542
552
|
const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
543
553
|
const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
544
554
|
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
545
555
|
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
546
|
-
|
|
556
|
+
store.logger.info(
|
|
547
557
|
`\u23F3 timeline "${tl.key}" saw atom "${atomToken.key}" go (`,
|
|
548
558
|
update.oldValue,
|
|
549
559
|
`->`,
|
|
@@ -571,15 +581,15 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
571
581
|
}
|
|
572
582
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
573
583
|
if (tl.transactionKey) {
|
|
574
|
-
|
|
575
|
-
|
|
584
|
+
store.logger.error(
|
|
585
|
+
`\u{1F41E} Timeline "${tl.key}" was unable to resolve transaction "${tl.transactionKey}. This is probably a bug.`
|
|
576
586
|
);
|
|
577
587
|
}
|
|
578
588
|
tl.transactionKey = currentTransactionKey;
|
|
579
589
|
const unsubscribe = currentTransaction.subject.subscribe(
|
|
580
590
|
`timeline:${tl.key}`,
|
|
581
591
|
(update2) => {
|
|
582
|
-
var _a2, _b2
|
|
592
|
+
var _a2, _b2;
|
|
583
593
|
unsubscribe();
|
|
584
594
|
if (tl.timeTraveling === null && currentTransactionTime) {
|
|
585
595
|
if (tl.at !== tl.history.length) {
|
|
@@ -611,7 +621,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
611
621
|
}
|
|
612
622
|
}
|
|
613
623
|
tl.transactionKey = null;
|
|
614
|
-
|
|
624
|
+
store.logger.info(
|
|
615
625
|
`\u231B timeline "${tl.key}" got a transaction_update "${update2.key}"`
|
|
616
626
|
);
|
|
617
627
|
}
|
|
@@ -634,7 +644,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
634
644
|
tl.history.splice(tl.at);
|
|
635
645
|
}
|
|
636
646
|
tl.history.push(latestUpdate);
|
|
637
|
-
|
|
647
|
+
store.logger.info(
|
|
638
648
|
`\u231B timeline "${tl.key}" got a selector_update "${currentSelectorKey}" with`,
|
|
639
649
|
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
640
650
|
);
|
|
@@ -646,14 +656,14 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
646
656
|
key: atom.key,
|
|
647
657
|
type: `atom_update`
|
|
648
658
|
}, update));
|
|
649
|
-
|
|
650
|
-
|
|
659
|
+
store.logger.info(
|
|
660
|
+
`\u231B timeline "${tl.key}" set selector_update "${currentSelectorKey}" to`,
|
|
651
661
|
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
652
662
|
);
|
|
653
663
|
}
|
|
654
664
|
}
|
|
655
665
|
if (latestUpdate) {
|
|
656
|
-
const willCaptureSelectorUpdate = (
|
|
666
|
+
const willCaptureSelectorUpdate = (_b = (_a = tl.shouldCapture) == null ? void 0 : _a.call(tl, latestUpdate, tl)) != null ? _b : true;
|
|
657
667
|
if (willCaptureSelectorUpdate) {
|
|
658
668
|
tl.subject.next(latestUpdate);
|
|
659
669
|
} else {
|
|
@@ -677,8 +687,8 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
677
687
|
if (atom.family) {
|
|
678
688
|
atomUpdate.family = atom.family;
|
|
679
689
|
}
|
|
680
|
-
const willCapture = (
|
|
681
|
-
|
|
690
|
+
const willCapture = (_d = (_c = tl.shouldCapture) == null ? void 0 : _c.call(tl, atomUpdate, tl)) != null ? _d : true;
|
|
691
|
+
store.logger.info(
|
|
682
692
|
`\u231B timeline "${tl.key}" got an atom_update to "${atom.key}"`
|
|
683
693
|
);
|
|
684
694
|
if (willCapture) {
|
|
@@ -691,18 +701,17 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
691
701
|
});
|
|
692
702
|
};
|
|
693
703
|
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
694
|
-
|
|
695
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23E9 redo "${token.key}"`);
|
|
704
|
+
store.logger.info(`\u23E9 redo "${token.key}"`);
|
|
696
705
|
const timelineData = store.timelines.get(token.key);
|
|
697
706
|
if (!timelineData) {
|
|
698
|
-
|
|
699
|
-
|
|
707
|
+
store.logger.error(
|
|
708
|
+
`\u{1F41E} Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
|
|
700
709
|
);
|
|
701
710
|
return;
|
|
702
711
|
}
|
|
703
712
|
if (timelineData.at === timelineData.history.length) {
|
|
704
|
-
|
|
705
|
-
|
|
713
|
+
store.logger.warn(
|
|
714
|
+
`\u261D\uFE0F Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
706
715
|
);
|
|
707
716
|
return;
|
|
708
717
|
}
|
|
@@ -726,23 +735,22 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
726
735
|
++timelineData.at;
|
|
727
736
|
timelineData.subject.next(`redo`);
|
|
728
737
|
timelineData.timeTraveling = null;
|
|
729
|
-
|
|
738
|
+
store.logger.info(
|
|
730
739
|
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
731
740
|
);
|
|
732
741
|
};
|
|
733
742
|
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
734
|
-
|
|
735
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23EA undo "${token.key}"`);
|
|
743
|
+
store.logger.info(`\u23EA undo "${token.key}"`);
|
|
736
744
|
const timelineData = store.timelines.get(token.key);
|
|
737
745
|
if (!timelineData) {
|
|
738
|
-
|
|
739
|
-
|
|
746
|
+
store.logger.error(
|
|
747
|
+
`\u{1F41E} Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
|
|
740
748
|
);
|
|
741
749
|
return;
|
|
742
750
|
}
|
|
743
751
|
if (timelineData.at === 0) {
|
|
744
|
-
|
|
745
|
-
|
|
752
|
+
store.logger.warn(
|
|
753
|
+
`\u261D\uFE0F Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
746
754
|
);
|
|
747
755
|
return;
|
|
748
756
|
}
|
|
@@ -766,14 +774,14 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
766
774
|
}
|
|
767
775
|
timelineData.subject.next(`undo`);
|
|
768
776
|
timelineData.timeTraveling = null;
|
|
769
|
-
|
|
777
|
+
store.logger.info(
|
|
770
778
|
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
771
779
|
);
|
|
772
780
|
};
|
|
773
781
|
|
|
774
782
|
// src/timeline/timeline-internal.ts
|
|
775
783
|
function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
776
|
-
var _a, _b
|
|
784
|
+
var _a, _b;
|
|
777
785
|
const tl = __spreadProps(__spreadValues({
|
|
778
786
|
type: `timeline`,
|
|
779
787
|
key: options.key,
|
|
@@ -793,7 +801,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
793
801
|
for (const tokenOrFamily of options.atoms) {
|
|
794
802
|
const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
|
|
795
803
|
if (timelineKey) {
|
|
796
|
-
|
|
804
|
+
store.logger.error(
|
|
797
805
|
`\u274C Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`
|
|
798
806
|
);
|
|
799
807
|
continue;
|
|
@@ -804,7 +812,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
804
812
|
addAtomToTimeline(token2, tl, store);
|
|
805
813
|
});
|
|
806
814
|
for (const atom of core.atoms.values()) {
|
|
807
|
-
if (((
|
|
815
|
+
if (((_b = atom.family) == null ? void 0 : _b.key) === family.key) {
|
|
808
816
|
addAtomToTimeline(atom, tl, store);
|
|
809
817
|
}
|
|
810
818
|
}
|
|
@@ -815,7 +823,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
815
823
|
token2.family.key
|
|
816
824
|
);
|
|
817
825
|
if (familyTimelineKey) {
|
|
818
|
-
|
|
826
|
+
store.logger.error(
|
|
819
827
|
`\u274C Failed to add atom "${token2.key}" to timeline "${options.key}" because its family "${token2.family.key}" belongs to timeline "${familyTimelineKey}"`
|
|
820
828
|
);
|
|
821
829
|
continue;
|
|
@@ -839,7 +847,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
839
847
|
|
|
840
848
|
// src/store/withdraw.ts
|
|
841
849
|
function withdraw(token, store) {
|
|
842
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i
|
|
850
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
843
851
|
let core = target(store);
|
|
844
852
|
let state = (_d = (_c = (_b = (_a = core.atoms.get(token.key)) != null ? _a : core.selectors.get(token.key)) != null ? _b : core.readonlySelectors.get(token.key)) != null ? _c : core.transactions.get(token.key)) != null ? _d : core.timelines.get(token.key);
|
|
845
853
|
if (state) {
|
|
@@ -849,13 +857,13 @@ function withdraw(token, store) {
|
|
|
849
857
|
core = store.transactionStatus.core;
|
|
850
858
|
state = (_h = (_g = (_f = (_e = core.atoms.get(token.key)) != null ? _e : core.selectors.get(token.key)) != null ? _f : core.readonlySelectors.get(token.key)) != null ? _g : core.transactions.get(token.key)) != null ? _h : core.timelines.get(token.key);
|
|
851
859
|
if (state) {
|
|
852
|
-
|
|
860
|
+
store.logger.info(`\u{1F6E0}\uFE0F add ${token.type} "${token.key}"`);
|
|
853
861
|
switch (state.type) {
|
|
854
862
|
case `atom`: {
|
|
855
863
|
store.atoms.set(token.key, state);
|
|
856
864
|
store.valueMap.set(token.key, state.default);
|
|
857
865
|
const stateKey = state.key;
|
|
858
|
-
const familyKey = (
|
|
866
|
+
const familyKey = (_i = state.family) == null ? void 0 : _i.key;
|
|
859
867
|
let timelineKey = core.timelineAtoms.getRelatedKey(stateKey);
|
|
860
868
|
if (timelineKey === void 0 && typeof familyKey === `string`) {
|
|
861
869
|
timelineKey = core.timelineAtoms.getRelatedKey(familyKey);
|
|
@@ -887,8 +895,7 @@ function withdraw(token, store) {
|
|
|
887
895
|
|
|
888
896
|
// src/store/withdraw-new-family-member.ts
|
|
889
897
|
function withdrawNewFamilyMember(token, store) {
|
|
890
|
-
|
|
891
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
898
|
+
store.logger.info(
|
|
892
899
|
`\u{1F46A} creating new family member "${token.key}" in store "${store.config.name}"`
|
|
893
900
|
);
|
|
894
901
|
if (token.family) {
|
|
@@ -920,12 +927,8 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
920
927
|
cacheValue(key, value2, subject, store);
|
|
921
928
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
922
929
|
}).catch((error) => {
|
|
923
|
-
var _a;
|
|
924
930
|
if (error !== `canceled`) {
|
|
925
|
-
|
|
926
|
-
`Promised value for "${key}" rejected:`,
|
|
927
|
-
error
|
|
928
|
-
);
|
|
931
|
+
store.logger.error(`\u{1F645}\u200D\u2642\uFE0F Promised value for "${key}" rejected:`, error);
|
|
929
932
|
}
|
|
930
933
|
});
|
|
931
934
|
} else {
|
|
@@ -935,14 +938,16 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
935
938
|
var readCachedValue = (key, store = IMPLICIT.STORE) => target(store).valueMap.get(key);
|
|
936
939
|
var isValueCached = (key, store = IMPLICIT.STORE) => target(store).valueMap.has(key);
|
|
937
940
|
var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
938
|
-
var _a;
|
|
939
941
|
const core = target(store);
|
|
940
942
|
const currentValue = core.valueMap.get(key);
|
|
941
943
|
if (currentValue instanceof Future) {
|
|
942
944
|
currentValue.cancel();
|
|
943
945
|
}
|
|
946
|
+
if (core.operation.open) {
|
|
947
|
+
core.operation.prev.set(key, currentValue);
|
|
948
|
+
}
|
|
944
949
|
core.valueMap.delete(key);
|
|
945
|
-
|
|
950
|
+
store.logger.info(`\u{1F5D1} evicted "${key}"`);
|
|
946
951
|
};
|
|
947
952
|
var Tracker = class {
|
|
948
953
|
constructor(mutableState, store = IMPLICIT.STORE) {
|
|
@@ -956,7 +961,7 @@ var Tracker = class {
|
|
|
956
961
|
}
|
|
957
962
|
initializeState(mutableState, store = IMPLICIT.STORE) {
|
|
958
963
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
959
|
-
deleteAtom(latestUpdateStateKey,
|
|
964
|
+
deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
|
|
960
965
|
const familyMetaData = mutableState.family ? {
|
|
961
966
|
key: `*${mutableState.family.key}`,
|
|
962
967
|
subKey: mutableState.family.subKey
|
|
@@ -1062,8 +1067,7 @@ var Tracker = class {
|
|
|
1062
1067
|
|
|
1063
1068
|
// src/mutable/create-mutable-atom.ts
|
|
1064
1069
|
function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
1065
|
-
|
|
1066
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1070
|
+
store.logger.info(
|
|
1067
1071
|
`\u{1F527} creating mutable atom "${options.key}" in store "${store.config.name}"`
|
|
1068
1072
|
);
|
|
1069
1073
|
const coreState = createAtom(options, void 0, store);
|
|
@@ -1072,8 +1076,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1072
1076
|
atom_io.subscribe(
|
|
1073
1077
|
jsonState,
|
|
1074
1078
|
() => {
|
|
1075
|
-
|
|
1076
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1079
|
+
store.logger.info(
|
|
1077
1080
|
`\u{1F50D} tracker-initializer:${store == null ? void 0 : store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
1078
1081
|
`Initializing tracker for ${coreState.key}`
|
|
1079
1082
|
);
|
|
@@ -1135,17 +1138,16 @@ var getSelectorDependencyKeys = (key, store) => {
|
|
|
1135
1138
|
|
|
1136
1139
|
// src/get-state-internal.ts
|
|
1137
1140
|
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
1138
|
-
var _a, _b, _c;
|
|
1139
1141
|
if (isValueCached(state.key, store)) {
|
|
1140
|
-
|
|
1142
|
+
store.logger.info(`\u{1F4D6} reading "${state.key}"`);
|
|
1141
1143
|
return readCachedValue(state.key, store);
|
|
1142
1144
|
}
|
|
1143
1145
|
if (state.type !== `atom`) {
|
|
1144
|
-
|
|
1146
|
+
store.logger.info(`\u{1F9EE} calculating "${state.key}"`);
|
|
1145
1147
|
return state.get();
|
|
1146
1148
|
}
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
+
store.logger.error(
|
|
1150
|
+
`\u{1F41E} Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
1149
1151
|
);
|
|
1150
1152
|
return state.default;
|
|
1151
1153
|
};
|
|
@@ -1157,10 +1159,9 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
1157
1159
|
|
|
1158
1160
|
// src/operation.ts
|
|
1159
1161
|
var openOperation = (token, store) => {
|
|
1160
|
-
var _a, _b;
|
|
1161
1162
|
const core = target(store);
|
|
1162
1163
|
if (core.operation.open) {
|
|
1163
|
-
|
|
1164
|
+
store.logger.error(
|
|
1164
1165
|
`\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
|
|
1165
1166
|
);
|
|
1166
1167
|
return `rejection`;
|
|
@@ -1168,26 +1169,24 @@ var openOperation = (token, store) => {
|
|
|
1168
1169
|
core.operation = {
|
|
1169
1170
|
open: true,
|
|
1170
1171
|
done: /* @__PURE__ */ new Set(),
|
|
1171
|
-
prev: new Map(
|
|
1172
|
+
prev: /* @__PURE__ */ new Map(),
|
|
1172
1173
|
time: Date.now(),
|
|
1173
1174
|
token
|
|
1174
1175
|
};
|
|
1175
|
-
|
|
1176
|
+
store.logger.info(
|
|
1176
1177
|
`\u2B55 operation start from "${token.key}" in store "${store.config.name}"${store.transactionStatus.phase === `idle` ? `` : ` ${store.transactionStatus.phase} "${store.transactionStatus.key}"`}`
|
|
1177
1178
|
);
|
|
1178
1179
|
};
|
|
1179
1180
|
var closeOperation = (store) => {
|
|
1180
|
-
var _a;
|
|
1181
1181
|
const core = target(store);
|
|
1182
1182
|
core.operation = { open: false };
|
|
1183
|
-
|
|
1183
|
+
store.logger.info(`\u{1F534} operation done`);
|
|
1184
1184
|
store.subject.operationStatus.next(core.operation);
|
|
1185
1185
|
};
|
|
1186
1186
|
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
1187
|
-
var _a;
|
|
1188
1187
|
const core = target(store);
|
|
1189
1188
|
if (!core.operation.open) {
|
|
1190
|
-
|
|
1189
|
+
store.logger.warn(
|
|
1191
1190
|
`isDone called outside of an operation. This is probably a bug.`
|
|
1192
1191
|
);
|
|
1193
1192
|
return true;
|
|
@@ -1195,11 +1194,10 @@ var isDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1195
1194
|
return core.operation.done.has(key);
|
|
1196
1195
|
};
|
|
1197
1196
|
var markDone = (key, store = IMPLICIT.STORE) => {
|
|
1198
|
-
var _a;
|
|
1199
1197
|
const core = target(store);
|
|
1200
1198
|
if (!core.operation.open) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1199
|
+
store.logger.warn(
|
|
1200
|
+
`\u{1F41E} markDone called outside of an operation. This is probably a bug.`
|
|
1203
1201
|
);
|
|
1204
1202
|
return;
|
|
1205
1203
|
}
|
|
@@ -1207,14 +1205,13 @@ var markDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1207
1205
|
};
|
|
1208
1206
|
|
|
1209
1207
|
// src/set-state/copy-mutable-if-needed.ts
|
|
1210
|
-
function copyMutableIfNeeded(atom, transform, origin,
|
|
1211
|
-
var _a;
|
|
1208
|
+
function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
1212
1209
|
const originValue = origin.valueMap.get(atom.key);
|
|
1213
|
-
const targetValue =
|
|
1210
|
+
const targetValue = target2.valueMap.get(atom.key);
|
|
1214
1211
|
if (originValue === targetValue) {
|
|
1215
|
-
|
|
1212
|
+
origin.logger.info(`\u{1F4C3} copying`, `${atom.key}`);
|
|
1216
1213
|
const copiedValue = transform.fromJson(transform.toJson(originValue));
|
|
1217
|
-
|
|
1214
|
+
target2.valueMap.set(atom.key, copiedValue);
|
|
1218
1215
|
new Tracker(atom, origin);
|
|
1219
1216
|
return copiedValue;
|
|
1220
1217
|
}
|
|
@@ -1223,10 +1220,9 @@ function copyMutableIfNeeded(atom, transform, origin, target3) {
|
|
|
1223
1220
|
|
|
1224
1221
|
// src/set-state/copy-mutable-in-transaction.ts
|
|
1225
1222
|
function copyMutableIfWithinTransaction(atom, store) {
|
|
1226
|
-
var _a;
|
|
1227
1223
|
if (store.transactionStatus.phase === `building` || store.transactionStatus.phase === `applying`) {
|
|
1228
1224
|
if (`toJson` in atom && `fromJson` in atom) {
|
|
1229
|
-
|
|
1225
|
+
store.logger.info(
|
|
1230
1226
|
`\u{1F4C4} copyMutableIfWithinTransaction: ${atom.key} is mutable`
|
|
1231
1227
|
);
|
|
1232
1228
|
const copiedValue = copyMutableIfNeeded(
|
|
@@ -1254,9 +1250,9 @@ function copyMutableIfWithinTransaction(atom, store) {
|
|
|
1254
1250
|
}
|
|
1255
1251
|
return getState__INTERNAL(atom, store);
|
|
1256
1252
|
}
|
|
1257
|
-
function copyMutableFamilyMemberWithinTransaction(atom, family, origin,
|
|
1253
|
+
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target2) {
|
|
1258
1254
|
if (`toJson` in family && `fromJson` in family) {
|
|
1259
|
-
const copyCreated = copyMutableIfNeeded(atom, family, origin,
|
|
1255
|
+
const copyCreated = copyMutableIfNeeded(atom, family, origin, target2);
|
|
1260
1256
|
return copyCreated;
|
|
1261
1257
|
}
|
|
1262
1258
|
return null;
|
|
@@ -1265,7 +1261,7 @@ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target3)
|
|
|
1265
1261
|
// src/set-state/emit-update.ts
|
|
1266
1262
|
var emitUpdate = (state, update, store) => {
|
|
1267
1263
|
const { key } = state;
|
|
1268
|
-
const { logger } = store
|
|
1264
|
+
const { logger } = store;
|
|
1269
1265
|
logger == null ? void 0 : logger.info(
|
|
1270
1266
|
`\u{1F4E2} ${state.type} "${key}" went (`,
|
|
1271
1267
|
update.oldValue,
|
|
@@ -1279,26 +1275,25 @@ var emitUpdate = (state, update, store) => {
|
|
|
1279
1275
|
|
|
1280
1276
|
// src/set-state/evict-downstream.ts
|
|
1281
1277
|
var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
1282
|
-
var _a
|
|
1278
|
+
var _a;
|
|
1283
1279
|
const core = target(store);
|
|
1284
1280
|
const downstreamKeys = core.selectorAtoms.getRelatedKeys(state.key);
|
|
1285
|
-
|
|
1286
|
-
|
|
1281
|
+
store.logger.info(
|
|
1282
|
+
`\u{1F9F9} evicting ${downstreamKeys == null ? void 0 : downstreamKeys.size} states downstream from ${state.type} "${state.key}":`,
|
|
1287
1283
|
downstreamKeys
|
|
1288
1284
|
);
|
|
1289
1285
|
if (core.operation.open) {
|
|
1290
|
-
|
|
1286
|
+
store.logger.info(`\u{1F9F9}`, [...core.operation.done], `already done`);
|
|
1291
1287
|
}
|
|
1292
1288
|
if (downstreamKeys) {
|
|
1293
1289
|
for (const key of downstreamKeys) {
|
|
1294
1290
|
if (isDone(key, store)) {
|
|
1295
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(` || ${key} already done`);
|
|
1296
1291
|
continue;
|
|
1297
1292
|
}
|
|
1298
|
-
const state2 = (
|
|
1293
|
+
const state2 = (_a = core.selectors.get(key)) != null ? _a : core.readonlySelectors.get(key);
|
|
1299
1294
|
if (!state2) {
|
|
1300
|
-
|
|
1301
|
-
|
|
1295
|
+
store.logger.error(
|
|
1296
|
+
`\u{1F41E} "${key}" was not found in selectors or readonlySelectors`
|
|
1302
1297
|
);
|
|
1303
1298
|
return;
|
|
1304
1299
|
}
|
|
@@ -1319,12 +1314,10 @@ function shouldUpdateBeStowed(key, update) {
|
|
|
1319
1314
|
return true;
|
|
1320
1315
|
}
|
|
1321
1316
|
var stowUpdate = (state, update, store) => {
|
|
1322
|
-
var _a;
|
|
1323
1317
|
const { key } = state;
|
|
1324
|
-
const { logger } = store.config;
|
|
1325
1318
|
if (store.transactionStatus.phase !== `building`) {
|
|
1326
|
-
|
|
1327
|
-
|
|
1319
|
+
store.logger.warn(
|
|
1320
|
+
`\u{1F41E} stowUpdate called outside of a transaction. This is probably a bug.`
|
|
1328
1321
|
);
|
|
1329
1322
|
return;
|
|
1330
1323
|
}
|
|
@@ -1337,24 +1330,26 @@ var stowUpdate = (state, update, store) => {
|
|
|
1337
1330
|
atomUpdate.family = state.family;
|
|
1338
1331
|
}
|
|
1339
1332
|
store.transactionStatus.atomUpdates.push(atomUpdate);
|
|
1340
|
-
logger
|
|
1333
|
+
store.logger.info(
|
|
1334
|
+
`\u{1F4C1} ${key} stowed (`,
|
|
1335
|
+
update.oldValue,
|
|
1336
|
+
`->`,
|
|
1337
|
+
update.newValue,
|
|
1338
|
+
`)`
|
|
1339
|
+
);
|
|
1341
1340
|
};
|
|
1342
1341
|
|
|
1343
1342
|
// src/set-state/set-atom.ts
|
|
1344
1343
|
var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
1345
|
-
var _a, _b;
|
|
1346
1344
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1347
1345
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
1348
1346
|
newValue = become(next)(newValue);
|
|
1349
|
-
|
|
1347
|
+
store.logger.info(`\u{1F4DD} setting atom "${atom.key}" to`, newValue);
|
|
1350
1348
|
cacheValue(atom.key, newValue, atom.subject, store);
|
|
1351
1349
|
if (isAtomDefault(atom.key, store)) {
|
|
1352
1350
|
markAtomAsNotDefault(atom.key, store);
|
|
1353
1351
|
}
|
|
1354
1352
|
markDone(atom.key, store);
|
|
1355
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1356
|
-
` || evicting caches downstream from "${atom.key}"`
|
|
1357
|
-
);
|
|
1358
1353
|
evictDownStream(atom, store);
|
|
1359
1354
|
const update = { oldValue, newValue };
|
|
1360
1355
|
if (store.transactionStatus.phase !== `building`) {
|
|
@@ -1408,35 +1403,33 @@ var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
|
1408
1403
|
|
|
1409
1404
|
// src/selector/update-selector-atoms.ts
|
|
1410
1405
|
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1411
|
-
var _a, _b;
|
|
1412
1406
|
const core = target(store);
|
|
1413
1407
|
if (dependency.type === `atom`) {
|
|
1414
1408
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
1415
1409
|
selectorKey,
|
|
1416
1410
|
atomKey: dependency.key
|
|
1417
1411
|
});
|
|
1418
|
-
|
|
1419
|
-
|
|
1412
|
+
store.logger.info(
|
|
1413
|
+
`\u{1F50D} selector "${selectorKey}" discovers root atom "${dependency.key}"`
|
|
1420
1414
|
);
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
}
|
|
1415
|
+
} else {
|
|
1416
|
+
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1417
|
+
store.logger.info(
|
|
1418
|
+
`\u{1F50D} selector "${selectorKey}" discovers root atoms:`,
|
|
1419
|
+
rootKeys.map((r) => r)
|
|
1420
|
+
);
|
|
1421
|
+
for (const atomKey of rootKeys) {
|
|
1422
|
+
core.selectorAtoms = core.selectorAtoms.set({
|
|
1423
|
+
selectorKey,
|
|
1424
|
+
atomKey
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1433
1427
|
}
|
|
1434
1428
|
};
|
|
1435
1429
|
|
|
1436
1430
|
// src/selector/register-selector.ts
|
|
1437
1431
|
var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
1438
1432
|
get: (dependency) => {
|
|
1439
|
-
var _a, _b;
|
|
1440
1433
|
const core = target(store);
|
|
1441
1434
|
const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
|
|
1442
1435
|
const dependencyState = withdraw(dependency, store);
|
|
@@ -1446,17 +1439,10 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1446
1439
|
);
|
|
1447
1440
|
}
|
|
1448
1441
|
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
);
|
|
1454
|
-
} else {
|
|
1455
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1456
|
-
`\u{1F50C} registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
|
|
1457
|
-
dependencyValue,
|
|
1458
|
-
`)`
|
|
1459
|
-
);
|
|
1442
|
+
store.logger.info(
|
|
1443
|
+
`\u{1F50C} selector "${selectorKey}" registers dependency ( "${dependency.key}" = ${dependencyValue} )`
|
|
1444
|
+
);
|
|
1445
|
+
if (!alreadyRegistered) {
|
|
1460
1446
|
core.selectorGraph = core.selectorGraph.set(
|
|
1461
1447
|
{
|
|
1462
1448
|
upstreamSelectorKey: dependency.key,
|
|
@@ -1483,7 +1469,6 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1483
1469
|
|
|
1484
1470
|
// src/selector/create-read-write-selector.ts
|
|
1485
1471
|
var createReadWriteSelector = (options, family, store, core) => {
|
|
1486
|
-
var _a;
|
|
1487
1472
|
const subject = new Subject();
|
|
1488
1473
|
const { get, set } = registerSelector(options.key, store);
|
|
1489
1474
|
const getSelf = () => {
|
|
@@ -1492,16 +1477,9 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1492
1477
|
return value;
|
|
1493
1478
|
};
|
|
1494
1479
|
const setSelf = (next) => {
|
|
1495
|
-
var _a2;
|
|
1496
1480
|
const oldValue = getSelf();
|
|
1497
1481
|
const newValue = become(next)(oldValue);
|
|
1498
|
-
|
|
1499
|
-
` <- "${options.key}" went (`,
|
|
1500
|
-
oldValue,
|
|
1501
|
-
`->`,
|
|
1502
|
-
newValue,
|
|
1503
|
-
`)`
|
|
1504
|
-
);
|
|
1482
|
+
store.logger.info(`\u{1F4DD} set "${options.key}" (`, oldValue, `->`, newValue, `)`);
|
|
1505
1483
|
cacheValue(options.key, newValue, subject, store);
|
|
1506
1484
|
markDone(options.key, store);
|
|
1507
1485
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1518,7 +1496,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1518
1496
|
}), family && { family });
|
|
1519
1497
|
core.selectors.set(options.key, mySelector);
|
|
1520
1498
|
const initialValue = getSelf();
|
|
1521
|
-
|
|
1499
|
+
store.logger.info(`\u2728 "${options.key}" =`, initialValue);
|
|
1522
1500
|
const token = {
|
|
1523
1501
|
key: options.key,
|
|
1524
1502
|
type: `selector`
|
|
@@ -1532,7 +1510,6 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1532
1510
|
|
|
1533
1511
|
// src/selector/create-readonly-selector.ts
|
|
1534
1512
|
var createReadonlySelector = (options, family, store, core) => {
|
|
1535
|
-
var _a;
|
|
1536
1513
|
const subject = new Subject();
|
|
1537
1514
|
const { get } = registerSelector(options.key, store);
|
|
1538
1515
|
const getSelf = () => {
|
|
@@ -1548,7 +1525,7 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1548
1525
|
}), family && { family });
|
|
1549
1526
|
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1550
1527
|
const initialValue = getSelf();
|
|
1551
|
-
|
|
1528
|
+
store.logger.info(`\u2728 "${options.key}" =`, initialValue);
|
|
1552
1529
|
const token = {
|
|
1553
1530
|
key: options.key,
|
|
1554
1531
|
type: `readonly_selector`
|
|
@@ -1562,16 +1539,14 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1562
1539
|
|
|
1563
1540
|
// src/selector/create-selector.ts
|
|
1564
1541
|
function createSelector(options, family, store = IMPLICIT.STORE) {
|
|
1565
|
-
var _a, _b;
|
|
1566
1542
|
const core = target(store);
|
|
1567
1543
|
const existingWritable = core.selectors.get(options.key);
|
|
1568
1544
|
const existingReadonly = core.readonlySelectors.get(options.key);
|
|
1569
1545
|
if (existingWritable || existingReadonly) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
`Tried to create ${existingReadonly ? `readonly selector` : `selector`}`,
|
|
1546
|
+
store.logger.error(
|
|
1547
|
+
`\u2753 Tried to create ${existingReadonly ? `readonly selector` : `selector`}`,
|
|
1573
1548
|
`"${options.key}", but it already exists in the store.`,
|
|
1574
|
-
`(Ignore if you are using hot module replacement.)`
|
|
1549
|
+
`(Ignore if you are in development using hot module replacement.)`
|
|
1575
1550
|
);
|
|
1576
1551
|
}
|
|
1577
1552
|
if (`set` in options) {
|
|
@@ -1751,19 +1726,17 @@ var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1751
1726
|
|
|
1752
1727
|
// src/atom/create-atom.ts
|
|
1753
1728
|
function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
1754
|
-
var _a
|
|
1755
|
-
|
|
1756
|
-
_a,
|
|
1729
|
+
var _a;
|
|
1730
|
+
store.logger.info(
|
|
1757
1731
|
`\u{1F528} creating atom "${options.key}" in store "${store.config.name}"`
|
|
1758
1732
|
);
|
|
1759
1733
|
const core = target(store);
|
|
1760
1734
|
const existing = core.atoms.get(options.key);
|
|
1761
1735
|
if (existing) {
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
`Tried to create atom "${options.key}",`,
|
|
1736
|
+
store.logger.error(
|
|
1737
|
+
`\u2753 Tried to create atom "${options.key}",`,
|
|
1765
1738
|
`but it already exists in the store.`,
|
|
1766
|
-
`(Ignore if you are using hot module replacement.)`
|
|
1739
|
+
`(Ignore if you are in development using hot module replacement.)`
|
|
1767
1740
|
);
|
|
1768
1741
|
return deposit(existing);
|
|
1769
1742
|
}
|
|
@@ -1771,9 +1744,7 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1771
1744
|
const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1772
1745
|
type: `atom`,
|
|
1773
1746
|
install: (store2) => {
|
|
1774
|
-
|
|
1775
|
-
(_b2 = (_a2 = store2.config.logger) == null ? void 0 : _a2.info) == null ? void 0 : _b2.call(
|
|
1776
|
-
_a2,
|
|
1747
|
+
store2.logger.info(
|
|
1777
1748
|
`\u{1F6E0}\uFE0F installing atom "${options.key}" in store "${store2.config.name}"`
|
|
1778
1749
|
);
|
|
1779
1750
|
return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
|
|
@@ -1785,7 +1756,7 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1785
1756
|
markAtomAsDefault(options.key, store);
|
|
1786
1757
|
cacheValue(options.key, initialValue, subject, store);
|
|
1787
1758
|
const token = deposit(newAtom);
|
|
1788
|
-
for (const effect of (
|
|
1759
|
+
for (const effect of (_a = options.effects) != null ? _a : []) {
|
|
1789
1760
|
effect({
|
|
1790
1761
|
setSelf: (next) => atom_io.setState(token, next, store),
|
|
1791
1762
|
onSet: (handle) => atom_io.subscribe(token, handle, `effect[${subject.subscribers.size}]`, store)
|
|
@@ -1796,21 +1767,23 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1796
1767
|
}
|
|
1797
1768
|
|
|
1798
1769
|
// src/atom/delete-atom.ts
|
|
1799
|
-
function deleteAtom(
|
|
1770
|
+
function deleteAtom(atomToken, store = IMPLICIT.STORE) {
|
|
1771
|
+
const core = target(store);
|
|
1772
|
+
const { key } = atomToken;
|
|
1800
1773
|
core.atoms.delete(key);
|
|
1801
1774
|
core.valueMap.delete(key);
|
|
1802
1775
|
core.selectorAtoms.delete(key);
|
|
1803
1776
|
core.atomsThatAreDefault.delete(key);
|
|
1804
1777
|
core.timelineAtoms.delete(key);
|
|
1778
|
+
store.logger.info(`\u{1F525} Atom "${key}" deleted`);
|
|
1805
1779
|
}
|
|
1806
1780
|
|
|
1807
1781
|
// src/subscribe/recall-state.ts
|
|
1808
1782
|
var recallState = (state, store = IMPLICIT.STORE) => {
|
|
1809
|
-
var _a;
|
|
1810
1783
|
const core = target(store);
|
|
1811
1784
|
if (!core.operation.open) {
|
|
1812
|
-
|
|
1813
|
-
|
|
1785
|
+
store.logger.warn(
|
|
1786
|
+
`\u{1F41E}recall called outside of an operation. This is probably a bug.`
|
|
1814
1787
|
);
|
|
1815
1788
|
return core.valueMap.get(state.key);
|
|
1816
1789
|
}
|
|
@@ -1829,8 +1802,7 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1829
1802
|
return atom.subject.subscribe(
|
|
1830
1803
|
`${state.type}:${state.key}`,
|
|
1831
1804
|
(atomChange) => {
|
|
1832
|
-
|
|
1833
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1805
|
+
store.logger.info(
|
|
1834
1806
|
`\u{1F4E2} selector "${state.key}" saw root "${atomKey}" go (`,
|
|
1835
1807
|
atomChange.oldValue,
|
|
1836
1808
|
`->`,
|
|
@@ -1839,8 +1811,8 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1839
1811
|
);
|
|
1840
1812
|
const oldValue = recallState(state, store);
|
|
1841
1813
|
const newValue = getState__INTERNAL(state, store);
|
|
1842
|
-
|
|
1843
|
-
|
|
1814
|
+
store.logger.info(
|
|
1815
|
+
`\u2728 "${state.key}" went (`,
|
|
1844
1816
|
oldValue,
|
|
1845
1817
|
`->`,
|
|
1846
1818
|
newValue,
|