atom.io 0.10.1 → 0.10.3
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 +53 -8
- package/dist/index.d.ts +53 -8
- package/dist/index.js +64 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -33
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +251 -110
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +251 -110
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/create-atom.ts +15 -4
- package/internal/src/atom/delete-atom.ts +1 -1
- package/internal/src/caching.ts +4 -4
- package/internal/src/get-state-internal.ts +3 -5
- package/internal/src/mutable/create-mutable-atom.ts +4 -10
- package/internal/src/operation.ts +23 -4
- package/internal/src/selector/create-read-write-selector.ts +12 -2
- package/internal/src/selector/create-readonly-selector.ts +7 -1
- package/internal/src/selector/create-selector.ts +4 -5
- package/internal/src/selector/register-selector.ts +7 -1
- package/internal/src/selector/update-selector-atoms.ts +10 -3
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +0 -3
- package/internal/src/set-state/emit-update.ts +6 -3
- package/internal/src/set-state/evict-downstream.ts +15 -14
- package/internal/src/set-state/set-atom.ts +1 -1
- package/internal/src/set-state/stow-update.ts +9 -4
- package/internal/src/store/store.ts +8 -19
- package/internal/src/store/withdraw-new-family-member.ts +4 -1
- package/internal/src/store/withdraw.ts +6 -1
- package/internal/src/subscribe/recall-state.ts +4 -1
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +11 -5
- package/internal/src/timeline/add-atom-to-timeline.ts +40 -9
- package/internal/src/timeline/time-travel-internal.ts +26 -8
- package/internal/src/timeline/timeline-internal.ts +8 -2
- package/internal/src/transaction/abort-transaction.ts +10 -2
- package/internal/src/transaction/apply-transaction.ts +22 -5
- package/internal/src/transaction/build-transaction.ts +5 -1
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/transaction-internal.ts +1 -4
- package/internal/src/transaction/undo-transaction.ts +7 -1
- package/package.json +3 -3
- package/realtime-client/dist/index.js +30 -5
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/dist/index.mjs +30 -5
- package/realtime-client/dist/index.mjs.map +1 -1
- package/realtime-client/src/use-server-action.ts +30 -5
- package/src/logger.ts +82 -14
- package/src/subscribe.ts +30 -7
package/internal/dist/index.mjs
CHANGED
|
@@ -312,27 +312,20 @@ var Store = class {
|
|
|
312
312
|
name: `IMPLICIT_STORE`
|
|
313
313
|
};
|
|
314
314
|
this.loggers = [
|
|
315
|
-
new AtomIOLogger(
|
|
316
|
-
__spreadValues({}, console),
|
|
317
|
-
`warn`,
|
|
318
|
-
(message) => !message.includes(`\u{1F441}\u200D\u{1F5E8}`)
|
|
319
|
-
)
|
|
315
|
+
new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
320
316
|
];
|
|
321
317
|
this.logger = {
|
|
322
318
|
error: (...messages) => {
|
|
323
|
-
for (const logger of this.loggers)
|
|
319
|
+
for (const logger of this.loggers)
|
|
324
320
|
logger.error(...messages);
|
|
325
|
-
}
|
|
326
321
|
},
|
|
327
322
|
info: (...messages) => {
|
|
328
|
-
for (const logger of this.loggers)
|
|
323
|
+
for (const logger of this.loggers)
|
|
329
324
|
logger.info(...messages);
|
|
330
|
-
}
|
|
331
325
|
},
|
|
332
326
|
warn: (...messages) => {
|
|
333
|
-
for (const logger of this.loggers)
|
|
327
|
+
for (const logger of this.loggers)
|
|
334
328
|
logger.warn(...messages);
|
|
335
|
-
}
|
|
336
329
|
}
|
|
337
330
|
};
|
|
338
331
|
if (store !== null) {
|
|
@@ -377,17 +370,28 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
377
370
|
var abortTransaction = (store) => {
|
|
378
371
|
if (store.transactionStatus.phase === `idle`) {
|
|
379
372
|
store.logger.warn(
|
|
380
|
-
`\u{1F41E}
|
|
373
|
+
`\u{1F41E}`,
|
|
374
|
+
`transaction`,
|
|
375
|
+
`???`,
|
|
376
|
+
`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`
|
|
381
377
|
);
|
|
382
378
|
return;
|
|
383
379
|
}
|
|
380
|
+
store.logger.info(
|
|
381
|
+
`\u{1FA82}`,
|
|
382
|
+
`transaction`,
|
|
383
|
+
store.transactionStatus.key,
|
|
384
|
+
`Aborting transaction`
|
|
385
|
+
);
|
|
384
386
|
store.transactionStatus = { phase: `idle` };
|
|
385
|
-
store.logger.info(`\u{1FA82}`, `transaction fail`);
|
|
386
387
|
};
|
|
387
388
|
var applyTransaction = (output, store) => {
|
|
388
389
|
if (store.transactionStatus.phase !== `building`) {
|
|
389
390
|
store.logger.warn(
|
|
390
|
-
`\u{1F41E}
|
|
391
|
+
`\u{1F41E}`,
|
|
392
|
+
`transaction`,
|
|
393
|
+
`???`,
|
|
394
|
+
`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`
|
|
391
395
|
);
|
|
392
396
|
return;
|
|
393
397
|
}
|
|
@@ -395,9 +399,12 @@ var applyTransaction = (output, store) => {
|
|
|
395
399
|
store.transactionStatus.output = output;
|
|
396
400
|
const { atomUpdates } = store.transactionStatus;
|
|
397
401
|
store.logger.info(
|
|
398
|
-
`\u{
|
|
402
|
+
`\u{1F6C4}`,
|
|
403
|
+
`transaction`,
|
|
404
|
+
store.transactionStatus.key,
|
|
405
|
+
`Applying transaction with ${atomUpdates.length} updates:`,
|
|
406
|
+
atomUpdates
|
|
399
407
|
);
|
|
400
|
-
store.logger.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
401
408
|
for (const { key, newValue } of atomUpdates) {
|
|
402
409
|
const token = { key, type: `atom` };
|
|
403
410
|
if (!store.valueMap.has(token.key)) {
|
|
@@ -415,7 +422,12 @@ var applyTransaction = (output, store) => {
|
|
|
415
422
|
}
|
|
416
423
|
store.atoms.set(newAtom.key, newAtom);
|
|
417
424
|
store.valueMap.set(newAtom.key, newAtom.default);
|
|
418
|
-
store.logger.info(
|
|
425
|
+
store.logger.info(
|
|
426
|
+
`\u{1F528}`,
|
|
427
|
+
`transaction`,
|
|
428
|
+
store.transactionStatus.key,
|
|
429
|
+
`Adding atom "${newAtom.key}"`
|
|
430
|
+
);
|
|
419
431
|
}
|
|
420
432
|
}
|
|
421
433
|
setState(token, newValue, store);
|
|
@@ -435,8 +447,13 @@ var applyTransaction = (output, store) => {
|
|
|
435
447
|
output,
|
|
436
448
|
params: store.transactionStatus.params
|
|
437
449
|
});
|
|
450
|
+
store.logger.info(
|
|
451
|
+
`\u{1F6EC}`,
|
|
452
|
+
`transaction`,
|
|
453
|
+
store.transactionStatus.key,
|
|
454
|
+
`Finished applying transaction.`
|
|
455
|
+
);
|
|
438
456
|
store.transactionStatus = { phase: `idle` };
|
|
439
|
-
store.logger.info(`\u{1F6EC} transaction "${myTransaction.key}" applied`);
|
|
440
457
|
};
|
|
441
458
|
|
|
442
459
|
// src/transaction/build-transaction.ts
|
|
@@ -467,7 +484,11 @@ var buildTransaction = (key, params, store) => {
|
|
|
467
484
|
output: void 0
|
|
468
485
|
};
|
|
469
486
|
store.logger.info(
|
|
470
|
-
`\u{1F6EB}
|
|
487
|
+
`\u{1F6EB}`,
|
|
488
|
+
`transaction`,
|
|
489
|
+
key,
|
|
490
|
+
`Building transaction with params:`,
|
|
491
|
+
params
|
|
471
492
|
);
|
|
472
493
|
};
|
|
473
494
|
|
|
@@ -490,10 +511,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
490
511
|
return output;
|
|
491
512
|
} catch (thrown) {
|
|
492
513
|
abortTransaction(store);
|
|
493
|
-
store.logger.
|
|
494
|
-
`\u2757 Transaction "${options.key}" failed in store "${store.config.name}":`,
|
|
495
|
-
thrown
|
|
496
|
-
);
|
|
514
|
+
store.logger.warn(`\u{1F4A5}`, `transaction`, options.key, `caught:`, thrown);
|
|
497
515
|
throw thrown;
|
|
498
516
|
}
|
|
499
517
|
},
|
|
@@ -508,7 +526,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
508
526
|
}
|
|
509
527
|
var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
|
|
510
528
|
var redoTransactionUpdate = (update, store) => {
|
|
511
|
-
store.logger.info(
|
|
529
|
+
store.logger.info(`\u23ED\uFE0F`, `transaction`, update.key, `Redo`);
|
|
512
530
|
for (const { key, newValue } of update.atomUpdates) {
|
|
513
531
|
const token = { key, type: `atom` };
|
|
514
532
|
const state = withdraw(token, store);
|
|
@@ -521,7 +539,13 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
521
539
|
}
|
|
522
540
|
};
|
|
523
541
|
var undoTransactionUpdate = (update, store) => {
|
|
524
|
-
store.logger.info(
|
|
542
|
+
store.logger.info(
|
|
543
|
+
`\u23EE\uFE0F`,
|
|
544
|
+
`transaction`,
|
|
545
|
+
update.key,
|
|
546
|
+
`Undoing transaction update`,
|
|
547
|
+
update
|
|
548
|
+
);
|
|
525
549
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
526
550
|
const token = { key, type: `atom` };
|
|
527
551
|
const state = withdraw(token, store);
|
|
@@ -552,11 +576,16 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
552
576
|
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
553
577
|
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
554
578
|
store.logger.info(
|
|
555
|
-
`\u23F3
|
|
579
|
+
`\u23F3`,
|
|
580
|
+
`timeline`,
|
|
581
|
+
tl.key,
|
|
582
|
+
`atom`,
|
|
583
|
+
atomToken.key,
|
|
584
|
+
`went`,
|
|
556
585
|
update.oldValue,
|
|
557
586
|
`->`,
|
|
558
587
|
update.newValue,
|
|
559
|
-
currentTransactionKey ? `
|
|
588
|
+
currentTransactionKey ? `in transaction "${currentTransactionKey}"` : currentSelectorKey ? `in selector "${currentSelectorKey}"` : ``
|
|
560
589
|
);
|
|
561
590
|
if (tl.timeTraveling === null) {
|
|
562
591
|
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
@@ -580,7 +609,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
580
609
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
581
610
|
if (tl.transactionKey) {
|
|
582
611
|
store.logger.error(
|
|
583
|
-
`\u{1F41E}
|
|
612
|
+
`\u{1F41E}`,
|
|
613
|
+
`timeline`,
|
|
614
|
+
tl.key,
|
|
615
|
+
`unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`
|
|
584
616
|
);
|
|
585
617
|
}
|
|
586
618
|
tl.transactionKey = currentTransactionKey;
|
|
@@ -620,7 +652,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
620
652
|
}
|
|
621
653
|
tl.transactionKey = null;
|
|
622
654
|
store.logger.info(
|
|
623
|
-
`\u231B
|
|
655
|
+
`\u231B`,
|
|
656
|
+
`timeline`,
|
|
657
|
+
tl.key,
|
|
658
|
+
`got a transaction_update "${update2.key}"`
|
|
624
659
|
);
|
|
625
660
|
}
|
|
626
661
|
);
|
|
@@ -643,7 +678,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
643
678
|
}
|
|
644
679
|
tl.history.push(latestUpdate);
|
|
645
680
|
store.logger.info(
|
|
646
|
-
`\u231B
|
|
681
|
+
`\u231B`,
|
|
682
|
+
`timeline`,
|
|
683
|
+
tl.key,
|
|
684
|
+
`got a selector_update "${currentSelectorKey}" with`,
|
|
647
685
|
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
648
686
|
);
|
|
649
687
|
tl.at = tl.history.length;
|
|
@@ -655,7 +693,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
655
693
|
type: `atom_update`
|
|
656
694
|
}, update));
|
|
657
695
|
store.logger.info(
|
|
658
|
-
`\u231B
|
|
696
|
+
`\u231B`,
|
|
697
|
+
`timeline`,
|
|
698
|
+
tl.key,
|
|
699
|
+
`set selector_update "${currentSelectorKey}" to`,
|
|
659
700
|
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
660
701
|
);
|
|
661
702
|
}
|
|
@@ -687,7 +728,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
687
728
|
}
|
|
688
729
|
const willCapture = (_d = (_c = tl.shouldCapture) == null ? void 0 : _c.call(tl, atomUpdate, tl)) != null ? _d : true;
|
|
689
730
|
store.logger.info(
|
|
690
|
-
`\u231B
|
|
731
|
+
`\u231B`,
|
|
732
|
+
`timeline`,
|
|
733
|
+
tl.key,
|
|
734
|
+
`got an atom_update to "${atom.key}"`
|
|
691
735
|
);
|
|
692
736
|
if (willCapture) {
|
|
693
737
|
tl.history.push(atomUpdate);
|
|
@@ -699,17 +743,23 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
699
743
|
});
|
|
700
744
|
};
|
|
701
745
|
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
702
|
-
store.logger.info(`\u23E9
|
|
746
|
+
store.logger.info(`\u23E9`, `timeline`, token.key, `redo`);
|
|
703
747
|
const timelineData = store.timelines.get(token.key);
|
|
704
748
|
if (!timelineData) {
|
|
705
749
|
store.logger.error(
|
|
706
|
-
`\u{1F41E}
|
|
750
|
+
`\u{1F41E}`,
|
|
751
|
+
`timeline`,
|
|
752
|
+
token.key,
|
|
753
|
+
`Failed to redo. This timeline has not been initialized.`
|
|
707
754
|
);
|
|
708
755
|
return;
|
|
709
756
|
}
|
|
710
757
|
if (timelineData.at === timelineData.history.length) {
|
|
711
758
|
store.logger.warn(
|
|
712
|
-
`\
|
|
759
|
+
`\u{1F481}`,
|
|
760
|
+
`timeline`,
|
|
761
|
+
token.key,
|
|
762
|
+
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
713
763
|
);
|
|
714
764
|
return;
|
|
715
765
|
}
|
|
@@ -734,21 +784,30 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
734
784
|
timelineData.subject.next(`redo`);
|
|
735
785
|
timelineData.timeTraveling = null;
|
|
736
786
|
store.logger.info(
|
|
737
|
-
`\u23F9\uFE0F
|
|
787
|
+
`\u23F9\uFE0F`,
|
|
788
|
+
`timeline`,
|
|
789
|
+
token.key,
|
|
790
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
738
791
|
);
|
|
739
792
|
};
|
|
740
793
|
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
741
|
-
store.logger.info(`\u23EA
|
|
794
|
+
store.logger.info(`\u23EA`, `timeline`, token.key, `undo`);
|
|
742
795
|
const timelineData = store.timelines.get(token.key);
|
|
743
796
|
if (!timelineData) {
|
|
744
797
|
store.logger.error(
|
|
745
|
-
`\u{1F41E}
|
|
798
|
+
`\u{1F41E}`,
|
|
799
|
+
`timeline`,
|
|
800
|
+
token.key,
|
|
801
|
+
`Failed to undo. This timeline has not been initialized.`
|
|
746
802
|
);
|
|
747
803
|
return;
|
|
748
804
|
}
|
|
749
805
|
if (timelineData.at === 0) {
|
|
750
806
|
store.logger.warn(
|
|
751
|
-
`\
|
|
807
|
+
`\u{1F481}`,
|
|
808
|
+
`timeline`,
|
|
809
|
+
token.key,
|
|
810
|
+
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
752
811
|
);
|
|
753
812
|
return;
|
|
754
813
|
}
|
|
@@ -773,7 +832,10 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
773
832
|
timelineData.subject.next(`undo`);
|
|
774
833
|
timelineData.timeTraveling = null;
|
|
775
834
|
store.logger.info(
|
|
776
|
-
`\u23F9\uFE0F
|
|
835
|
+
`\u23F9\uFE0F`,
|
|
836
|
+
`timeline`,
|
|
837
|
+
token.key,
|
|
838
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
777
839
|
);
|
|
778
840
|
};
|
|
779
841
|
|
|
@@ -800,7 +862,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
800
862
|
const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
|
|
801
863
|
if (timelineKey) {
|
|
802
864
|
store.logger.error(
|
|
803
|
-
`\u274C
|
|
865
|
+
`\u274C`,
|
|
866
|
+
`timeline`,
|
|
867
|
+
options.key,
|
|
868
|
+
`Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
|
|
804
869
|
);
|
|
805
870
|
continue;
|
|
806
871
|
}
|
|
@@ -822,7 +887,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
822
887
|
);
|
|
823
888
|
if (familyTimelineKey) {
|
|
824
889
|
store.logger.error(
|
|
825
|
-
`\u274C
|
|
890
|
+
`\u274C`,
|
|
891
|
+
`timeline`,
|
|
892
|
+
options.key,
|
|
893
|
+
`Failed to add atom "${token2.key}" because its family "${token2.family.key}" already belongs to timeline "${familyTimelineKey}"`
|
|
826
894
|
);
|
|
827
895
|
continue;
|
|
828
896
|
}
|
|
@@ -855,7 +923,12 @@ function withdraw(token, store) {
|
|
|
855
923
|
core = store.transactionStatus.core;
|
|
856
924
|
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);
|
|
857
925
|
if (state) {
|
|
858
|
-
store.logger.info(
|
|
926
|
+
store.logger.info(
|
|
927
|
+
`\u{1F6E0}\uFE0F`,
|
|
928
|
+
token.type,
|
|
929
|
+
token.key,
|
|
930
|
+
`add ${token.type} "${token.key}"`
|
|
931
|
+
);
|
|
859
932
|
switch (state.type) {
|
|
860
933
|
case `atom`: {
|
|
861
934
|
store.atoms.set(token.key, state);
|
|
@@ -894,7 +967,10 @@ function withdraw(token, store) {
|
|
|
894
967
|
// src/store/withdraw-new-family-member.ts
|
|
895
968
|
function withdrawNewFamilyMember(token, store) {
|
|
896
969
|
store.logger.info(
|
|
897
|
-
`\u{1F46A}
|
|
970
|
+
`\u{1F46A}`,
|
|
971
|
+
token.type,
|
|
972
|
+
token.key,
|
|
973
|
+
`creating new family member in store "${store.config.name}"`
|
|
898
974
|
);
|
|
899
975
|
if (token.family) {
|
|
900
976
|
const core = target(store);
|
|
@@ -924,9 +1000,9 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
924
1000
|
}
|
|
925
1001
|
cacheValue(key, value2, subject, store);
|
|
926
1002
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
927
|
-
}).catch((
|
|
928
|
-
if (
|
|
929
|
-
store.logger.error(`\u{
|
|
1003
|
+
}).catch((thrown) => {
|
|
1004
|
+
if (thrown !== `canceled`) {
|
|
1005
|
+
store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
930
1006
|
}
|
|
931
1007
|
});
|
|
932
1008
|
} else {
|
|
@@ -945,7 +1021,7 @@ var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
|
945
1021
|
core.operation.prev.set(key, currentValue);
|
|
946
1022
|
}
|
|
947
1023
|
core.valueMap.delete(key);
|
|
948
|
-
store.logger.info(`\u{1F5D1}
|
|
1024
|
+
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
949
1025
|
};
|
|
950
1026
|
var Tracker = class {
|
|
951
1027
|
constructor(mutableState, store = IMPLICIT.STORE) {
|
|
@@ -1066,7 +1142,10 @@ var Tracker = class {
|
|
|
1066
1142
|
// src/mutable/create-mutable-atom.ts
|
|
1067
1143
|
function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
1068
1144
|
store.logger.info(
|
|
1069
|
-
`\u{1F527}
|
|
1145
|
+
`\u{1F527}`,
|
|
1146
|
+
`atom`,
|
|
1147
|
+
options.key,
|
|
1148
|
+
`creating in store "${store.config.name}"`
|
|
1070
1149
|
);
|
|
1071
1150
|
const coreState = createAtom(options, void 0, store);
|
|
1072
1151
|
new Tracker(coreState, store);
|
|
@@ -1074,10 +1153,6 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1074
1153
|
subscribe(
|
|
1075
1154
|
jsonState,
|
|
1076
1155
|
() => {
|
|
1077
|
-
store.logger.info(
|
|
1078
|
-
`\u{1F50D} tracker-initializer:${store == null ? void 0 : store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
1079
|
-
`Initializing tracker for ${coreState.key}`
|
|
1080
|
-
);
|
|
1081
1156
|
const trackerHasBeenInitialized = target(store).trackers.has(coreState.key);
|
|
1082
1157
|
if (!trackerHasBeenInitialized) {
|
|
1083
1158
|
new Tracker(coreState, store);
|
|
@@ -1137,16 +1212,14 @@ var getSelectorDependencyKeys = (key, store) => {
|
|
|
1137
1212
|
// src/get-state-internal.ts
|
|
1138
1213
|
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
1139
1214
|
if (isValueCached(state.key, store)) {
|
|
1140
|
-
store.logger.info(`\u{1F4D6}
|
|
1215
|
+
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
1141
1216
|
return readCachedValue(state.key, store);
|
|
1142
1217
|
}
|
|
1143
1218
|
if (state.type !== `atom`) {
|
|
1144
|
-
store.logger.info(`\u{1F9EE}
|
|
1219
|
+
store.logger.info(`\u{1F9EE}`, state.type, state.key, `calculating value`);
|
|
1145
1220
|
return state.get();
|
|
1146
1221
|
}
|
|
1147
|
-
store.logger.error(
|
|
1148
|
-
`\u{1F41E} Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
1149
|
-
);
|
|
1222
|
+
store.logger.error(`\u{1F41E}`, `atom`, state.key, `could not find cached value`);
|
|
1150
1223
|
return state.default;
|
|
1151
1224
|
};
|
|
1152
1225
|
|
|
@@ -1160,7 +1233,10 @@ var openOperation = (token, store) => {
|
|
|
1160
1233
|
const core = target(store);
|
|
1161
1234
|
if (core.operation.open) {
|
|
1162
1235
|
store.logger.error(
|
|
1163
|
-
`\u274C
|
|
1236
|
+
`\u274C`,
|
|
1237
|
+
token.type,
|
|
1238
|
+
token.key,
|
|
1239
|
+
`failed to setState during a setState for "${core.operation.token.key}"`
|
|
1164
1240
|
);
|
|
1165
1241
|
return `rejection`;
|
|
1166
1242
|
}
|
|
@@ -1172,19 +1248,32 @@ var openOperation = (token, store) => {
|
|
|
1172
1248
|
token
|
|
1173
1249
|
};
|
|
1174
1250
|
store.logger.info(
|
|
1175
|
-
`\u2B55
|
|
1251
|
+
`\u2B55`,
|
|
1252
|
+
token.type,
|
|
1253
|
+
token.key,
|
|
1254
|
+
`operation start in store "${store.config.name}"${store.transactionStatus.phase === `idle` ? `` : ` ${store.transactionStatus.phase} "${store.transactionStatus.key}"`}`
|
|
1176
1255
|
);
|
|
1177
1256
|
};
|
|
1178
1257
|
var closeOperation = (store) => {
|
|
1179
1258
|
const core = target(store);
|
|
1259
|
+
if (core.operation.open) {
|
|
1260
|
+
store.logger.info(
|
|
1261
|
+
`\u{1F534}`,
|
|
1262
|
+
core.operation.token.type,
|
|
1263
|
+
core.operation.token.key,
|
|
1264
|
+
`operation done in store "${store.config.name}"`
|
|
1265
|
+
);
|
|
1266
|
+
}
|
|
1180
1267
|
core.operation = { open: false };
|
|
1181
|
-
store.logger.info(`\u{1F534} operation done`);
|
|
1182
1268
|
store.subject.operationStatus.next(core.operation);
|
|
1183
1269
|
};
|
|
1184
1270
|
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
1185
1271
|
const core = target(store);
|
|
1186
1272
|
if (!core.operation.open) {
|
|
1187
1273
|
store.logger.warn(
|
|
1274
|
+
`\u{1F41E}`,
|
|
1275
|
+
`unknown`,
|
|
1276
|
+
key,
|
|
1188
1277
|
`isDone called outside of an operation. This is probably a bug.`
|
|
1189
1278
|
);
|
|
1190
1279
|
return true;
|
|
@@ -1195,7 +1284,10 @@ var markDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1195
1284
|
const core = target(store);
|
|
1196
1285
|
if (!core.operation.open) {
|
|
1197
1286
|
store.logger.warn(
|
|
1198
|
-
`\u{1F41E}
|
|
1287
|
+
`\u{1F41E}`,
|
|
1288
|
+
`unknown`,
|
|
1289
|
+
key,
|
|
1290
|
+
`markDone called outside of an operation. This is probably a bug.`
|
|
1199
1291
|
);
|
|
1200
1292
|
return;
|
|
1201
1293
|
}
|
|
@@ -1207,7 +1299,7 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1207
1299
|
const originValue = origin.valueMap.get(atom.key);
|
|
1208
1300
|
const targetValue = target2.valueMap.get(atom.key);
|
|
1209
1301
|
if (originValue === targetValue) {
|
|
1210
|
-
origin.logger.info(`\u{1F4C3}
|
|
1302
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
1211
1303
|
const copiedValue = transform.fromJson(transform.toJson(originValue));
|
|
1212
1304
|
target2.valueMap.set(atom.key, copiedValue);
|
|
1213
1305
|
new Tracker(atom, origin);
|
|
@@ -1220,9 +1312,6 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1220
1312
|
function copyMutableIfWithinTransaction(atom, store) {
|
|
1221
1313
|
if (store.transactionStatus.phase === `building` || store.transactionStatus.phase === `applying`) {
|
|
1222
1314
|
if (`toJson` in atom && `fromJson` in atom) {
|
|
1223
|
-
store.logger.info(
|
|
1224
|
-
`\u{1F4C4} copyMutableIfWithinTransaction: ${atom.key} is mutable`
|
|
1225
|
-
);
|
|
1226
1315
|
const copiedValue = copyMutableIfNeeded(
|
|
1227
1316
|
atom,
|
|
1228
1317
|
atom,
|
|
@@ -1258,43 +1347,46 @@ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target2)
|
|
|
1258
1347
|
|
|
1259
1348
|
// src/set-state/emit-update.ts
|
|
1260
1349
|
var emitUpdate = (state, update, store) => {
|
|
1261
|
-
const { key } = state;
|
|
1262
1350
|
const { logger } = store;
|
|
1263
1351
|
logger.info(
|
|
1264
|
-
`\u{1F4E2}
|
|
1352
|
+
`\u{1F4E2}`,
|
|
1353
|
+
state.type,
|
|
1354
|
+
state.key,
|
|
1355
|
+
`went (`,
|
|
1265
1356
|
update.oldValue,
|
|
1266
1357
|
`->`,
|
|
1267
1358
|
update.newValue,
|
|
1268
|
-
`)
|
|
1359
|
+
`) subscribers:`,
|
|
1360
|
+
state.subject.subscribers
|
|
1269
1361
|
);
|
|
1270
|
-
logger.info(`\u{1F4E2} notifying subscribers:`, state.subject.subscribers);
|
|
1271
1362
|
state.subject.next(update);
|
|
1272
1363
|
};
|
|
1273
1364
|
|
|
1274
1365
|
// src/set-state/evict-downstream.ts
|
|
1275
|
-
var evictDownStream = (
|
|
1366
|
+
var evictDownStream = (atom, store = IMPLICIT.STORE) => {
|
|
1276
1367
|
var _a;
|
|
1277
1368
|
const core = target(store);
|
|
1278
|
-
const downstreamKeys = core.selectorAtoms.getRelatedKeys(
|
|
1369
|
+
const downstreamKeys = core.selectorAtoms.getRelatedKeys(atom.key);
|
|
1279
1370
|
store.logger.info(
|
|
1280
|
-
`\u{1F9F9}
|
|
1371
|
+
`\u{1F9F9}`,
|
|
1372
|
+
atom.type,
|
|
1373
|
+
atom.key,
|
|
1374
|
+
`evicting ${(_a = downstreamKeys == null ? void 0 : downstreamKeys.size) != null ? _a : 0} states downstream:`,
|
|
1281
1375
|
downstreamKeys
|
|
1282
1376
|
);
|
|
1283
|
-
if (
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1377
|
+
if (downstreamKeys !== void 0) {
|
|
1378
|
+
if (core.operation.open) {
|
|
1379
|
+
store.logger.info(
|
|
1380
|
+
`\u{1F9F9}`,
|
|
1381
|
+
atom.type,
|
|
1382
|
+
atom.key,
|
|
1383
|
+
`[ ${[...core.operation.done].join(`, `)} ] already done`
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1287
1386
|
for (const key of downstreamKeys) {
|
|
1288
1387
|
if (isDone(key, store)) {
|
|
1289
1388
|
continue;
|
|
1290
1389
|
}
|
|
1291
|
-
const state2 = (_a = core.selectors.get(key)) != null ? _a : core.readonlySelectors.get(key);
|
|
1292
|
-
if (!state2) {
|
|
1293
|
-
store.logger.error(
|
|
1294
|
-
`\u{1F41E} "${key}" was not found in selectors or readonlySelectors`
|
|
1295
|
-
);
|
|
1296
|
-
return;
|
|
1297
|
-
}
|
|
1298
1390
|
evictCachedValue(key, store);
|
|
1299
1391
|
markDone(key, store);
|
|
1300
1392
|
}
|
|
@@ -1314,8 +1406,11 @@ function shouldUpdateBeStowed(key, update) {
|
|
|
1314
1406
|
var stowUpdate = (state, update, store) => {
|
|
1315
1407
|
const { key } = state;
|
|
1316
1408
|
if (store.transactionStatus.phase !== `building`) {
|
|
1317
|
-
store.logger.
|
|
1318
|
-
`\u{1F41E}
|
|
1409
|
+
store.logger.error(
|
|
1410
|
+
`\u{1F41E}`,
|
|
1411
|
+
`atom`,
|
|
1412
|
+
key,
|
|
1413
|
+
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
1319
1414
|
);
|
|
1320
1415
|
return;
|
|
1321
1416
|
}
|
|
@@ -1329,7 +1424,10 @@ var stowUpdate = (state, update, store) => {
|
|
|
1329
1424
|
}
|
|
1330
1425
|
store.transactionStatus.atomUpdates.push(atomUpdate);
|
|
1331
1426
|
store.logger.info(
|
|
1332
|
-
`\u{1F4C1}
|
|
1427
|
+
`\u{1F4C1}`,
|
|
1428
|
+
`atom`,
|
|
1429
|
+
key,
|
|
1430
|
+
`stowed (`,
|
|
1333
1431
|
update.oldValue,
|
|
1334
1432
|
`->`,
|
|
1335
1433
|
update.newValue,
|
|
@@ -1342,7 +1440,7 @@ var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1342
1440
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1343
1441
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
1344
1442
|
newValue = become(next)(newValue);
|
|
1345
|
-
store.logger.info(`\u{1F4DD}
|
|
1443
|
+
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
1346
1444
|
cacheValue(atom.key, newValue, atom.subject, store);
|
|
1347
1445
|
if (isAtomDefault(atom.key, store)) {
|
|
1348
1446
|
markAtomAsNotDefault(atom.key, store);
|
|
@@ -1408,13 +1506,18 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1408
1506
|
atomKey: dependency.key
|
|
1409
1507
|
});
|
|
1410
1508
|
store.logger.info(
|
|
1411
|
-
`\u{1F50D}
|
|
1509
|
+
`\u{1F50D}`,
|
|
1510
|
+
`selector`,
|
|
1511
|
+
selectorKey,
|
|
1512
|
+
`discovers root atom "${dependency.key}"`
|
|
1412
1513
|
);
|
|
1413
1514
|
} else {
|
|
1414
1515
|
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1415
1516
|
store.logger.info(
|
|
1416
|
-
`\u{1F50D}
|
|
1417
|
-
|
|
1517
|
+
`\u{1F50D}`,
|
|
1518
|
+
`selector`,
|
|
1519
|
+
selectorKey,
|
|
1520
|
+
`discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
|
|
1418
1521
|
);
|
|
1419
1522
|
for (const atomKey of rootKeys) {
|
|
1420
1523
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
@@ -1438,7 +1541,12 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1438
1541
|
}
|
|
1439
1542
|
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1440
1543
|
store.logger.info(
|
|
1441
|
-
`\u{1F50C}
|
|
1544
|
+
`\u{1F50C}`,
|
|
1545
|
+
`selector`,
|
|
1546
|
+
selectorKey,
|
|
1547
|
+
`registers dependency ( "${dependency.key}" =`,
|
|
1548
|
+
dependencyValue,
|
|
1549
|
+
`)`
|
|
1442
1550
|
);
|
|
1443
1551
|
if (!alreadyRegistered) {
|
|
1444
1552
|
core.selectorGraph = core.selectorGraph.set(
|
|
@@ -1477,7 +1585,16 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1477
1585
|
const setSelf = (next) => {
|
|
1478
1586
|
const oldValue = getSelf();
|
|
1479
1587
|
const newValue = become(next)(oldValue);
|
|
1480
|
-
store.logger.info(
|
|
1588
|
+
store.logger.info(
|
|
1589
|
+
`\u{1F4DD}`,
|
|
1590
|
+
`selector`,
|
|
1591
|
+
options.key,
|
|
1592
|
+
`set (`,
|
|
1593
|
+
oldValue,
|
|
1594
|
+
`->`,
|
|
1595
|
+
newValue,
|
|
1596
|
+
`)`
|
|
1597
|
+
);
|
|
1481
1598
|
cacheValue(options.key, newValue, subject, store);
|
|
1482
1599
|
markDone(options.key, store);
|
|
1483
1600
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1494,7 +1611,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1494
1611
|
}), family && { family });
|
|
1495
1612
|
core.selectors.set(options.key, mySelector);
|
|
1496
1613
|
const initialValue = getSelf();
|
|
1497
|
-
store.logger.info(`\u2728
|
|
1614
|
+
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1498
1615
|
const token = {
|
|
1499
1616
|
key: options.key,
|
|
1500
1617
|
type: `selector`
|
|
@@ -1523,7 +1640,13 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1523
1640
|
}), family && { family });
|
|
1524
1641
|
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1525
1642
|
const initialValue = getSelf();
|
|
1526
|
-
store.logger.info(
|
|
1643
|
+
store.logger.info(
|
|
1644
|
+
`\u2728`,
|
|
1645
|
+
readonlySelector.type,
|
|
1646
|
+
readonlySelector.key,
|
|
1647
|
+
`=`,
|
|
1648
|
+
initialValue
|
|
1649
|
+
);
|
|
1527
1650
|
const token = {
|
|
1528
1651
|
key: options.key,
|
|
1529
1652
|
type: `readonly_selector`
|
|
@@ -1542,9 +1665,10 @@ function createSelector(options, family, store = IMPLICIT.STORE) {
|
|
|
1542
1665
|
const existingReadonly = core.readonlySelectors.get(options.key);
|
|
1543
1666
|
if (existingWritable || existingReadonly) {
|
|
1544
1667
|
store.logger.error(
|
|
1545
|
-
`\
|
|
1546
|
-
|
|
1547
|
-
|
|
1668
|
+
`\u274C`,
|
|
1669
|
+
existingReadonly ? `readonly_selector` : `selector`,
|
|
1670
|
+
options.key,
|
|
1671
|
+
`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
|
|
1548
1672
|
);
|
|
1549
1673
|
}
|
|
1550
1674
|
if (`set` in options) {
|
|
@@ -1726,14 +1850,19 @@ var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1726
1850
|
function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
1727
1851
|
var _a;
|
|
1728
1852
|
store.logger.info(
|
|
1729
|
-
`\u{1F528}
|
|
1853
|
+
`\u{1F528}`,
|
|
1854
|
+
`atom`,
|
|
1855
|
+
options.key,
|
|
1856
|
+
`creating in store "${store.config.name}"`
|
|
1730
1857
|
);
|
|
1731
1858
|
const core = target(store);
|
|
1732
1859
|
const existing = core.atoms.get(options.key);
|
|
1733
1860
|
if (existing) {
|
|
1734
1861
|
store.logger.error(
|
|
1735
|
-
`\
|
|
1736
|
-
`
|
|
1862
|
+
`\u274C`,
|
|
1863
|
+
`atom`,
|
|
1864
|
+
options.key,
|
|
1865
|
+
`Tried to create atom, but it already exists in the store.`,
|
|
1737
1866
|
`(Ignore if you are in development using hot module replacement.)`
|
|
1738
1867
|
);
|
|
1739
1868
|
return deposit(existing);
|
|
@@ -1743,7 +1872,10 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1743
1872
|
type: `atom`,
|
|
1744
1873
|
install: (store2) => {
|
|
1745
1874
|
store2.logger.info(
|
|
1746
|
-
`\u{1F6E0}\uFE0F
|
|
1875
|
+
`\u{1F6E0}\uFE0F`,
|
|
1876
|
+
`atom`,
|
|
1877
|
+
options.key,
|
|
1878
|
+
`installing in store "${store2.config.name}"`
|
|
1747
1879
|
);
|
|
1748
1880
|
return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
|
|
1749
1881
|
},
|
|
@@ -1773,7 +1905,7 @@ function deleteAtom(atomToken, store = IMPLICIT.STORE) {
|
|
|
1773
1905
|
core.selectorAtoms.delete(key);
|
|
1774
1906
|
core.atomsThatAreDefault.delete(key);
|
|
1775
1907
|
core.timelineAtoms.delete(key);
|
|
1776
|
-
store.logger.info(`\u{1F525}
|
|
1908
|
+
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1777
1909
|
}
|
|
1778
1910
|
|
|
1779
1911
|
// src/subscribe/recall-state.ts
|
|
@@ -1781,7 +1913,10 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1781
1913
|
const core = target(store);
|
|
1782
1914
|
if (!core.operation.open) {
|
|
1783
1915
|
store.logger.warn(
|
|
1784
|
-
`\u{1F41E}
|
|
1916
|
+
`\u{1F41E}`,
|
|
1917
|
+
state.type,
|
|
1918
|
+
state.key,
|
|
1919
|
+
`recall called outside of an operation. This is probably a bug.`
|
|
1785
1920
|
);
|
|
1786
1921
|
return core.valueMap.get(state.key);
|
|
1787
1922
|
}
|
|
@@ -1801,20 +1936,26 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1801
1936
|
`${state.type}:${state.key}`,
|
|
1802
1937
|
(atomChange) => {
|
|
1803
1938
|
store.logger.info(
|
|
1804
|
-
`\u{1F4E2}
|
|
1939
|
+
`\u{1F4E2}`,
|
|
1940
|
+
state.type,
|
|
1941
|
+
state.key,
|
|
1942
|
+
`root`,
|
|
1943
|
+
atomKey,
|
|
1944
|
+
`went`,
|
|
1805
1945
|
atomChange.oldValue,
|
|
1806
1946
|
`->`,
|
|
1807
|
-
atomChange.newValue
|
|
1808
|
-
`)`
|
|
1947
|
+
atomChange.newValue
|
|
1809
1948
|
);
|
|
1810
1949
|
const oldValue = recallState(state, store);
|
|
1811
1950
|
const newValue = getState__INTERNAL(state, store);
|
|
1812
1951
|
store.logger.info(
|
|
1813
|
-
`\u2728
|
|
1952
|
+
`\u2728`,
|
|
1953
|
+
state.type,
|
|
1954
|
+
state.key,
|
|
1955
|
+
`went`,
|
|
1814
1956
|
oldValue,
|
|
1815
1957
|
`->`,
|
|
1816
|
-
newValue
|
|
1817
|
-
`)`
|
|
1958
|
+
newValue
|
|
1818
1959
|
);
|
|
1819
1960
|
state.subject.next({ newValue, oldValue });
|
|
1820
1961
|
}
|