atom.io 0.10.2 → 0.10.4
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 +53 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -33
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.js +239 -113
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +239 -113
- 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 +20 -7
- 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 +5 -5
- package/internal/src/set-state/evict-downstream.ts +10 -13
- package/internal/src/set-state/set-atom.ts +1 -1
- package/internal/src/set-state/stow-update.ts +9 -3
- 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 +7 -2
- package/internal/src/transaction/apply-transaction.ts +21 -7
- 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 +4 -4
- package/realtime-client/dist/index.js +24 -5
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/dist/index.mjs +24 -5
- package/realtime-client/dist/index.mjs.map +1 -1
- package/realtime-client/src/use-server-action.ts +24 -5
- package/src/logger.ts +79 -14
- package/src/subscribe.ts +22 -7
package/internal/dist/index.js
CHANGED
|
@@ -314,27 +314,20 @@ var Store = class {
|
|
|
314
314
|
name: `IMPLICIT_STORE`
|
|
315
315
|
};
|
|
316
316
|
this.loggers = [
|
|
317
|
-
new atom_io.AtomIOLogger(
|
|
318
|
-
__spreadValues({}, console),
|
|
319
|
-
`warn`,
|
|
320
|
-
(message) => !message.includes(`\u{1F441}\u200D\u{1F5E8}`)
|
|
321
|
-
)
|
|
317
|
+
new atom_io.AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
322
318
|
];
|
|
323
319
|
this.logger = {
|
|
324
320
|
error: (...messages) => {
|
|
325
|
-
for (const logger of this.loggers)
|
|
321
|
+
for (const logger of this.loggers)
|
|
326
322
|
logger.error(...messages);
|
|
327
|
-
}
|
|
328
323
|
},
|
|
329
324
|
info: (...messages) => {
|
|
330
|
-
for (const logger of this.loggers)
|
|
325
|
+
for (const logger of this.loggers)
|
|
331
326
|
logger.info(...messages);
|
|
332
|
-
}
|
|
333
327
|
},
|
|
334
328
|
warn: (...messages) => {
|
|
335
|
-
for (const logger of this.loggers)
|
|
329
|
+
for (const logger of this.loggers)
|
|
336
330
|
logger.warn(...messages);
|
|
337
|
-
}
|
|
338
331
|
}
|
|
339
332
|
};
|
|
340
333
|
if (store !== null) {
|
|
@@ -379,20 +372,28 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
379
372
|
var abortTransaction = (store) => {
|
|
380
373
|
if (store.transactionStatus.phase === `idle`) {
|
|
381
374
|
store.logger.warn(
|
|
382
|
-
`\u{1F41E}
|
|
375
|
+
`\u{1F41E}`,
|
|
376
|
+
`transaction`,
|
|
377
|
+
`???`,
|
|
378
|
+
`abortTransaction called outside of a transaction. This is probably a bug in AtomIO.`
|
|
383
379
|
);
|
|
384
380
|
return;
|
|
385
381
|
}
|
|
386
382
|
store.logger.info(
|
|
387
383
|
`\u{1FA82}`,
|
|
388
|
-
`
|
|
384
|
+
`transaction`,
|
|
385
|
+
store.transactionStatus.key,
|
|
386
|
+
`Aborting transaction`
|
|
389
387
|
);
|
|
390
388
|
store.transactionStatus = { phase: `idle` };
|
|
391
389
|
};
|
|
392
390
|
var applyTransaction = (output, store) => {
|
|
393
391
|
if (store.transactionStatus.phase !== `building`) {
|
|
394
392
|
store.logger.warn(
|
|
395
|
-
`\u{1F41E}
|
|
393
|
+
`\u{1F41E}`,
|
|
394
|
+
`transaction`,
|
|
395
|
+
`???`,
|
|
396
|
+
`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`
|
|
396
397
|
);
|
|
397
398
|
return;
|
|
398
399
|
}
|
|
@@ -400,10 +401,10 @@ var applyTransaction = (output, store) => {
|
|
|
400
401
|
store.transactionStatus.output = output;
|
|
401
402
|
const { atomUpdates } = store.transactionStatus;
|
|
402
403
|
store.logger.info(
|
|
403
|
-
`\u{
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
404
|
+
`\u{1F6C4}`,
|
|
405
|
+
`transaction`,
|
|
406
|
+
store.transactionStatus.key,
|
|
407
|
+
`Applying transaction with ${atomUpdates.length} updates:`,
|
|
407
408
|
atomUpdates
|
|
408
409
|
);
|
|
409
410
|
for (const { key, newValue } of atomUpdates) {
|
|
@@ -423,7 +424,12 @@ var applyTransaction = (output, store) => {
|
|
|
423
424
|
}
|
|
424
425
|
store.atoms.set(newAtom.key, newAtom);
|
|
425
426
|
store.valueMap.set(newAtom.key, newAtom.default);
|
|
426
|
-
store.logger.info(
|
|
427
|
+
store.logger.info(
|
|
428
|
+
`\u{1F528}`,
|
|
429
|
+
`transaction`,
|
|
430
|
+
store.transactionStatus.key,
|
|
431
|
+
`Adding atom "${newAtom.key}"`
|
|
432
|
+
);
|
|
427
433
|
}
|
|
428
434
|
}
|
|
429
435
|
atom_io.setState(token, newValue, store);
|
|
@@ -443,8 +449,13 @@ var applyTransaction = (output, store) => {
|
|
|
443
449
|
output,
|
|
444
450
|
params: store.transactionStatus.params
|
|
445
451
|
});
|
|
452
|
+
store.logger.info(
|
|
453
|
+
`\u{1F6EC}`,
|
|
454
|
+
`transaction`,
|
|
455
|
+
store.transactionStatus.key,
|
|
456
|
+
`Finished applying transaction.`
|
|
457
|
+
);
|
|
446
458
|
store.transactionStatus = { phase: `idle` };
|
|
447
|
-
store.logger.info(`\u{1F6EC} Successfully applied transaction "${myTransaction.key}"`);
|
|
448
459
|
};
|
|
449
460
|
|
|
450
461
|
// src/transaction/build-transaction.ts
|
|
@@ -475,7 +486,11 @@ var buildTransaction = (key, params, store) => {
|
|
|
475
486
|
output: void 0
|
|
476
487
|
};
|
|
477
488
|
store.logger.info(
|
|
478
|
-
`\u{1F6EB}
|
|
489
|
+
`\u{1F6EB}`,
|
|
490
|
+
`transaction`,
|
|
491
|
+
key,
|
|
492
|
+
`Building transaction with params:`,
|
|
493
|
+
params
|
|
479
494
|
);
|
|
480
495
|
};
|
|
481
496
|
|
|
@@ -498,10 +513,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
498
513
|
return output;
|
|
499
514
|
} catch (thrown) {
|
|
500
515
|
abortTransaction(store);
|
|
501
|
-
store.logger.
|
|
502
|
-
`\u2757 Transaction "${options.key}" failed in store "${store.config.name}":`,
|
|
503
|
-
thrown
|
|
504
|
-
);
|
|
516
|
+
store.logger.warn(`\u{1F4A5}`, `transaction`, options.key, `caught:`, thrown);
|
|
505
517
|
throw thrown;
|
|
506
518
|
}
|
|
507
519
|
},
|
|
@@ -516,7 +528,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
516
528
|
}
|
|
517
529
|
var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
|
|
518
530
|
var redoTransactionUpdate = (update, store) => {
|
|
519
|
-
store.logger.info(
|
|
531
|
+
store.logger.info(`\u23ED\uFE0F`, `transaction`, update.key, `Redo`);
|
|
520
532
|
for (const { key, newValue } of update.atomUpdates) {
|
|
521
533
|
const token = { key, type: `atom` };
|
|
522
534
|
const state = withdraw(token, store);
|
|
@@ -529,7 +541,13 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
529
541
|
}
|
|
530
542
|
};
|
|
531
543
|
var undoTransactionUpdate = (update, store) => {
|
|
532
|
-
store.logger.info(
|
|
544
|
+
store.logger.info(
|
|
545
|
+
`\u23EE\uFE0F`,
|
|
546
|
+
`transaction`,
|
|
547
|
+
update.key,
|
|
548
|
+
`Undoing transaction update`,
|
|
549
|
+
update
|
|
550
|
+
);
|
|
533
551
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
534
552
|
const token = { key, type: `atom` };
|
|
535
553
|
const state = withdraw(token, store);
|
|
@@ -560,11 +578,16 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
560
578
|
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
561
579
|
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
562
580
|
store.logger.info(
|
|
563
|
-
`\u23F3
|
|
581
|
+
`\u23F3`,
|
|
582
|
+
`timeline`,
|
|
583
|
+
tl.key,
|
|
584
|
+
`atom`,
|
|
585
|
+
atomToken.key,
|
|
586
|
+
`went`,
|
|
564
587
|
update.oldValue,
|
|
565
588
|
`->`,
|
|
566
589
|
update.newValue,
|
|
567
|
-
currentTransactionKey ? `
|
|
590
|
+
currentTransactionKey ? `in transaction "${currentTransactionKey}"` : currentSelectorKey ? `in selector "${currentSelectorKey}"` : ``
|
|
568
591
|
);
|
|
569
592
|
if (tl.timeTraveling === null) {
|
|
570
593
|
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
@@ -588,7 +611,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
588
611
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
589
612
|
if (tl.transactionKey) {
|
|
590
613
|
store.logger.error(
|
|
591
|
-
`\u{1F41E}
|
|
614
|
+
`\u{1F41E}`,
|
|
615
|
+
`timeline`,
|
|
616
|
+
tl.key,
|
|
617
|
+
`unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`
|
|
592
618
|
);
|
|
593
619
|
}
|
|
594
620
|
tl.transactionKey = currentTransactionKey;
|
|
@@ -628,7 +654,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
628
654
|
}
|
|
629
655
|
tl.transactionKey = null;
|
|
630
656
|
store.logger.info(
|
|
631
|
-
`\u231B
|
|
657
|
+
`\u231B`,
|
|
658
|
+
`timeline`,
|
|
659
|
+
tl.key,
|
|
660
|
+
`got a transaction_update "${update2.key}"`
|
|
632
661
|
);
|
|
633
662
|
}
|
|
634
663
|
);
|
|
@@ -651,7 +680,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
651
680
|
}
|
|
652
681
|
tl.history.push(latestUpdate);
|
|
653
682
|
store.logger.info(
|
|
654
|
-
`\u231B
|
|
683
|
+
`\u231B`,
|
|
684
|
+
`timeline`,
|
|
685
|
+
tl.key,
|
|
686
|
+
`got a selector_update "${currentSelectorKey}" with`,
|
|
655
687
|
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
656
688
|
);
|
|
657
689
|
tl.at = tl.history.length;
|
|
@@ -663,7 +695,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
663
695
|
type: `atom_update`
|
|
664
696
|
}, update));
|
|
665
697
|
store.logger.info(
|
|
666
|
-
`\u231B
|
|
698
|
+
`\u231B`,
|
|
699
|
+
`timeline`,
|
|
700
|
+
tl.key,
|
|
701
|
+
`set selector_update "${currentSelectorKey}" to`,
|
|
667
702
|
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
668
703
|
);
|
|
669
704
|
}
|
|
@@ -695,7 +730,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
695
730
|
}
|
|
696
731
|
const willCapture = (_d = (_c = tl.shouldCapture) == null ? void 0 : _c.call(tl, atomUpdate, tl)) != null ? _d : true;
|
|
697
732
|
store.logger.info(
|
|
698
|
-
`\u231B
|
|
733
|
+
`\u231B`,
|
|
734
|
+
`timeline`,
|
|
735
|
+
tl.key,
|
|
736
|
+
`got an atom_update to "${atom.key}"`
|
|
699
737
|
);
|
|
700
738
|
if (willCapture) {
|
|
701
739
|
tl.history.push(atomUpdate);
|
|
@@ -707,17 +745,23 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
707
745
|
});
|
|
708
746
|
};
|
|
709
747
|
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
710
|
-
store.logger.info(`\u23E9
|
|
748
|
+
store.logger.info(`\u23E9`, `timeline`, token.key, `redo`);
|
|
711
749
|
const timelineData = store.timelines.get(token.key);
|
|
712
750
|
if (!timelineData) {
|
|
713
751
|
store.logger.error(
|
|
714
|
-
`\u{1F41E}
|
|
752
|
+
`\u{1F41E}`,
|
|
753
|
+
`timeline`,
|
|
754
|
+
token.key,
|
|
755
|
+
`Failed to redo. This timeline has not been initialized.`
|
|
715
756
|
);
|
|
716
757
|
return;
|
|
717
758
|
}
|
|
718
759
|
if (timelineData.at === timelineData.history.length) {
|
|
719
760
|
store.logger.warn(
|
|
720
|
-
`\
|
|
761
|
+
`\u{1F481}`,
|
|
762
|
+
`timeline`,
|
|
763
|
+
token.key,
|
|
764
|
+
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
721
765
|
);
|
|
722
766
|
return;
|
|
723
767
|
}
|
|
@@ -742,21 +786,30 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
742
786
|
timelineData.subject.next(`redo`);
|
|
743
787
|
timelineData.timeTraveling = null;
|
|
744
788
|
store.logger.info(
|
|
745
|
-
`\u23F9\uFE0F
|
|
789
|
+
`\u23F9\uFE0F`,
|
|
790
|
+
`timeline`,
|
|
791
|
+
token.key,
|
|
792
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
746
793
|
);
|
|
747
794
|
};
|
|
748
795
|
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
749
|
-
store.logger.info(`\u23EA
|
|
796
|
+
store.logger.info(`\u23EA`, `timeline`, token.key, `undo`);
|
|
750
797
|
const timelineData = store.timelines.get(token.key);
|
|
751
798
|
if (!timelineData) {
|
|
752
799
|
store.logger.error(
|
|
753
|
-
`\u{1F41E}
|
|
800
|
+
`\u{1F41E}`,
|
|
801
|
+
`timeline`,
|
|
802
|
+
token.key,
|
|
803
|
+
`Failed to undo. This timeline has not been initialized.`
|
|
754
804
|
);
|
|
755
805
|
return;
|
|
756
806
|
}
|
|
757
807
|
if (timelineData.at === 0) {
|
|
758
808
|
store.logger.warn(
|
|
759
|
-
`\
|
|
809
|
+
`\u{1F481}`,
|
|
810
|
+
`timeline`,
|
|
811
|
+
token.key,
|
|
812
|
+
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
760
813
|
);
|
|
761
814
|
return;
|
|
762
815
|
}
|
|
@@ -781,7 +834,10 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
781
834
|
timelineData.subject.next(`undo`);
|
|
782
835
|
timelineData.timeTraveling = null;
|
|
783
836
|
store.logger.info(
|
|
784
|
-
`\u23F9\uFE0F
|
|
837
|
+
`\u23F9\uFE0F`,
|
|
838
|
+
`timeline`,
|
|
839
|
+
token.key,
|
|
840
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
785
841
|
);
|
|
786
842
|
};
|
|
787
843
|
|
|
@@ -808,7 +864,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
808
864
|
const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
|
|
809
865
|
if (timelineKey) {
|
|
810
866
|
store.logger.error(
|
|
811
|
-
`\u274C
|
|
867
|
+
`\u274C`,
|
|
868
|
+
`timeline`,
|
|
869
|
+
options.key,
|
|
870
|
+
`Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
|
|
812
871
|
);
|
|
813
872
|
continue;
|
|
814
873
|
}
|
|
@@ -830,7 +889,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
830
889
|
);
|
|
831
890
|
if (familyTimelineKey) {
|
|
832
891
|
store.logger.error(
|
|
833
|
-
`\u274C
|
|
892
|
+
`\u274C`,
|
|
893
|
+
`timeline`,
|
|
894
|
+
options.key,
|
|
895
|
+
`Failed to add atom "${token2.key}" because its family "${token2.family.key}" already belongs to timeline "${familyTimelineKey}"`
|
|
834
896
|
);
|
|
835
897
|
continue;
|
|
836
898
|
}
|
|
@@ -863,7 +925,12 @@ function withdraw(token, store) {
|
|
|
863
925
|
core = store.transactionStatus.core;
|
|
864
926
|
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);
|
|
865
927
|
if (state) {
|
|
866
|
-
store.logger.info(
|
|
928
|
+
store.logger.info(
|
|
929
|
+
`\u{1F6E0}\uFE0F`,
|
|
930
|
+
token.type,
|
|
931
|
+
token.key,
|
|
932
|
+
`add ${token.type} "${token.key}"`
|
|
933
|
+
);
|
|
867
934
|
switch (state.type) {
|
|
868
935
|
case `atom`: {
|
|
869
936
|
store.atoms.set(token.key, state);
|
|
@@ -902,7 +969,10 @@ function withdraw(token, store) {
|
|
|
902
969
|
// src/store/withdraw-new-family-member.ts
|
|
903
970
|
function withdrawNewFamilyMember(token, store) {
|
|
904
971
|
store.logger.info(
|
|
905
|
-
`\u{1F46A}
|
|
972
|
+
`\u{1F46A}`,
|
|
973
|
+
token.type,
|
|
974
|
+
token.key,
|
|
975
|
+
`creating new family member in store "${store.config.name}"`
|
|
906
976
|
);
|
|
907
977
|
if (token.family) {
|
|
908
978
|
const core = target(store);
|
|
@@ -932,9 +1002,9 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
932
1002
|
}
|
|
933
1003
|
cacheValue(key, value2, subject, store);
|
|
934
1004
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
935
|
-
}).catch((
|
|
936
|
-
if (
|
|
937
|
-
store.logger.error(`\u{
|
|
1005
|
+
}).catch((thrown) => {
|
|
1006
|
+
if (thrown !== `canceled`) {
|
|
1007
|
+
store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
938
1008
|
}
|
|
939
1009
|
});
|
|
940
1010
|
} else {
|
|
@@ -953,7 +1023,7 @@ var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
|
953
1023
|
core.operation.prev.set(key, currentValue);
|
|
954
1024
|
}
|
|
955
1025
|
core.valueMap.delete(key);
|
|
956
|
-
store.logger.info(`\u{1F5D1}
|
|
1026
|
+
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
957
1027
|
};
|
|
958
1028
|
var Tracker = class {
|
|
959
1029
|
constructor(mutableState, store = IMPLICIT.STORE) {
|
|
@@ -1074,7 +1144,10 @@ var Tracker = class {
|
|
|
1074
1144
|
// src/mutable/create-mutable-atom.ts
|
|
1075
1145
|
function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
1076
1146
|
store.logger.info(
|
|
1077
|
-
`\u{1F527}
|
|
1147
|
+
`\u{1F527}`,
|
|
1148
|
+
`atom`,
|
|
1149
|
+
options.key,
|
|
1150
|
+
`creating in store "${store.config.name}"`
|
|
1078
1151
|
);
|
|
1079
1152
|
const coreState = createAtom(options, void 0, store);
|
|
1080
1153
|
new Tracker(coreState, store);
|
|
@@ -1082,10 +1155,6 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1082
1155
|
atom_io.subscribe(
|
|
1083
1156
|
jsonState,
|
|
1084
1157
|
() => {
|
|
1085
|
-
store.logger.info(
|
|
1086
|
-
`\u{1F50D} tracker-initializer:${store == null ? void 0 : store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
1087
|
-
`Initializing tracker for ${coreState.key}`
|
|
1088
|
-
);
|
|
1089
1158
|
const trackerHasBeenInitialized = target(store).trackers.has(coreState.key);
|
|
1090
1159
|
if (!trackerHasBeenInitialized) {
|
|
1091
1160
|
new Tracker(coreState, store);
|
|
@@ -1145,16 +1214,14 @@ var getSelectorDependencyKeys = (key, store) => {
|
|
|
1145
1214
|
// src/get-state-internal.ts
|
|
1146
1215
|
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
1147
1216
|
if (isValueCached(state.key, store)) {
|
|
1148
|
-
store.logger.info(`\u{1F4D6}
|
|
1217
|
+
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
1149
1218
|
return readCachedValue(state.key, store);
|
|
1150
1219
|
}
|
|
1151
1220
|
if (state.type !== `atom`) {
|
|
1152
|
-
store.logger.info(`\u{1F9EE}
|
|
1221
|
+
store.logger.info(`\u{1F9EE}`, state.type, state.key, `calculating value`);
|
|
1153
1222
|
return state.get();
|
|
1154
1223
|
}
|
|
1155
|
-
store.logger.error(
|
|
1156
|
-
`\u{1F41E} Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
1157
|
-
);
|
|
1224
|
+
store.logger.error(`\u{1F41E}`, `atom`, state.key, `could not find cached value`);
|
|
1158
1225
|
return state.default;
|
|
1159
1226
|
};
|
|
1160
1227
|
|
|
@@ -1168,7 +1235,10 @@ var openOperation = (token, store) => {
|
|
|
1168
1235
|
const core = target(store);
|
|
1169
1236
|
if (core.operation.open) {
|
|
1170
1237
|
store.logger.error(
|
|
1171
|
-
`\u274C
|
|
1238
|
+
`\u274C`,
|
|
1239
|
+
token.type,
|
|
1240
|
+
token.key,
|
|
1241
|
+
`failed to setState during a setState for "${core.operation.token.key}"`
|
|
1172
1242
|
);
|
|
1173
1243
|
return `rejection`;
|
|
1174
1244
|
}
|
|
@@ -1180,14 +1250,20 @@ var openOperation = (token, store) => {
|
|
|
1180
1250
|
token
|
|
1181
1251
|
};
|
|
1182
1252
|
store.logger.info(
|
|
1183
|
-
`\u2B55
|
|
1253
|
+
`\u2B55`,
|
|
1254
|
+
token.type,
|
|
1255
|
+
token.key,
|
|
1256
|
+
`operation start in store "${store.config.name}"${store.transactionStatus.phase === `idle` ? `` : ` ${store.transactionStatus.phase} "${store.transactionStatus.key}"`}`
|
|
1184
1257
|
);
|
|
1185
1258
|
};
|
|
1186
1259
|
var closeOperation = (store) => {
|
|
1187
1260
|
const core = target(store);
|
|
1188
1261
|
if (core.operation.open) {
|
|
1189
1262
|
store.logger.info(
|
|
1190
|
-
`\u{1F534}
|
|
1263
|
+
`\u{1F534}`,
|
|
1264
|
+
core.operation.token.type,
|
|
1265
|
+
core.operation.token.key,
|
|
1266
|
+
`operation done in store "${store.config.name}"`
|
|
1191
1267
|
);
|
|
1192
1268
|
}
|
|
1193
1269
|
core.operation = { open: false };
|
|
@@ -1197,7 +1273,10 @@ var isDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1197
1273
|
const core = target(store);
|
|
1198
1274
|
if (!core.operation.open) {
|
|
1199
1275
|
store.logger.warn(
|
|
1200
|
-
`\u{1F41E}
|
|
1276
|
+
`\u{1F41E}`,
|
|
1277
|
+
`unknown`,
|
|
1278
|
+
key,
|
|
1279
|
+
`isDone called outside of an operation. This is probably a bug.`
|
|
1201
1280
|
);
|
|
1202
1281
|
return true;
|
|
1203
1282
|
}
|
|
@@ -1207,7 +1286,10 @@ var markDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1207
1286
|
const core = target(store);
|
|
1208
1287
|
if (!core.operation.open) {
|
|
1209
1288
|
store.logger.warn(
|
|
1210
|
-
`\u{1F41E}
|
|
1289
|
+
`\u{1F41E}`,
|
|
1290
|
+
`unknown`,
|
|
1291
|
+
key,
|
|
1292
|
+
`markDone called outside of an operation. This is probably a bug.`
|
|
1211
1293
|
);
|
|
1212
1294
|
return;
|
|
1213
1295
|
}
|
|
@@ -1219,7 +1301,7 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1219
1301
|
const originValue = origin.valueMap.get(atom.key);
|
|
1220
1302
|
const targetValue = target2.valueMap.get(atom.key);
|
|
1221
1303
|
if (originValue === targetValue) {
|
|
1222
|
-
origin.logger.info(`\u{1F4C3}
|
|
1304
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
1223
1305
|
const copiedValue = transform.fromJson(transform.toJson(originValue));
|
|
1224
1306
|
target2.valueMap.set(atom.key, copiedValue);
|
|
1225
1307
|
new Tracker(atom, origin);
|
|
@@ -1232,9 +1314,6 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1232
1314
|
function copyMutableIfWithinTransaction(atom, store) {
|
|
1233
1315
|
if (store.transactionStatus.phase === `building` || store.transactionStatus.phase === `applying`) {
|
|
1234
1316
|
if (`toJson` in atom && `fromJson` in atom) {
|
|
1235
|
-
store.logger.info(
|
|
1236
|
-
`\u{1F4C4} copyMutableIfWithinTransaction: ${atom.key} is mutable`
|
|
1237
|
-
);
|
|
1238
1317
|
const copiedValue = copyMutableIfNeeded(
|
|
1239
1318
|
atom,
|
|
1240
1319
|
atom,
|
|
@@ -1270,48 +1349,46 @@ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target2)
|
|
|
1270
1349
|
|
|
1271
1350
|
// src/set-state/emit-update.ts
|
|
1272
1351
|
var emitUpdate = (state, update, store) => {
|
|
1273
|
-
const { key } = state;
|
|
1274
1352
|
const { logger } = store;
|
|
1275
1353
|
logger.info(
|
|
1276
|
-
`\u{1F4E2}
|
|
1354
|
+
`\u{1F4E2}`,
|
|
1355
|
+
state.type,
|
|
1356
|
+
state.key,
|
|
1357
|
+
`went (`,
|
|
1277
1358
|
update.oldValue,
|
|
1278
1359
|
`->`,
|
|
1279
1360
|
update.newValue,
|
|
1280
|
-
`)
|
|
1281
|
-
);
|
|
1282
|
-
logger.info(
|
|
1283
|
-
`\u{1F4E2} notifying subscribers to "${state.key}"`,
|
|
1361
|
+
`) subscribers:`,
|
|
1284
1362
|
state.subject.subscribers
|
|
1285
1363
|
);
|
|
1286
1364
|
state.subject.next(update);
|
|
1287
1365
|
};
|
|
1288
1366
|
|
|
1289
1367
|
// src/set-state/evict-downstream.ts
|
|
1290
|
-
var evictDownStream = (
|
|
1291
|
-
var _a
|
|
1368
|
+
var evictDownStream = (atom, store = IMPLICIT.STORE) => {
|
|
1369
|
+
var _a;
|
|
1292
1370
|
const core = target(store);
|
|
1293
|
-
const downstreamKeys = core.selectorAtoms.getRelatedKeys(
|
|
1371
|
+
const downstreamKeys = core.selectorAtoms.getRelatedKeys(atom.key);
|
|
1294
1372
|
store.logger.info(
|
|
1295
|
-
`\u{1F9F9}
|
|
1373
|
+
`\u{1F9F9}`,
|
|
1374
|
+
atom.type,
|
|
1375
|
+
atom.key,
|
|
1376
|
+
`evicting ${(_a = downstreamKeys == null ? void 0 : downstreamKeys.size) != null ? _a : 0} states downstream:`,
|
|
1296
1377
|
downstreamKeys
|
|
1297
1378
|
);
|
|
1298
1379
|
if (downstreamKeys !== void 0) {
|
|
1299
1380
|
if (core.operation.open) {
|
|
1300
1381
|
store.logger.info(
|
|
1301
|
-
`\u{1F9F9}
|
|
1382
|
+
`\u{1F9F9}`,
|
|
1383
|
+
atom.type,
|
|
1384
|
+
atom.key,
|
|
1385
|
+
`[ ${[...core.operation.done].join(`, `)} ] already done`
|
|
1302
1386
|
);
|
|
1303
1387
|
}
|
|
1304
1388
|
for (const key of downstreamKeys) {
|
|
1305
1389
|
if (isDone(key, store)) {
|
|
1306
1390
|
continue;
|
|
1307
1391
|
}
|
|
1308
|
-
const state2 = (_b = core.selectors.get(key)) != null ? _b : core.readonlySelectors.get(key);
|
|
1309
|
-
if (!state2) {
|
|
1310
|
-
store.logger.error(
|
|
1311
|
-
`\u{1F41E} "${key}" was not found in selectors or readonlySelectors`
|
|
1312
|
-
);
|
|
1313
|
-
return;
|
|
1314
|
-
}
|
|
1315
1392
|
evictCachedValue(key, store);
|
|
1316
1393
|
markDone(key, store);
|
|
1317
1394
|
}
|
|
@@ -1331,8 +1408,11 @@ function shouldUpdateBeStowed(key, update) {
|
|
|
1331
1408
|
var stowUpdate = (state, update, store) => {
|
|
1332
1409
|
const { key } = state;
|
|
1333
1410
|
if (store.transactionStatus.phase !== `building`) {
|
|
1334
|
-
store.logger.
|
|
1335
|
-
`\u{1F41E}
|
|
1411
|
+
store.logger.error(
|
|
1412
|
+
`\u{1F41E}`,
|
|
1413
|
+
`atom`,
|
|
1414
|
+
key,
|
|
1415
|
+
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
1336
1416
|
);
|
|
1337
1417
|
return;
|
|
1338
1418
|
}
|
|
@@ -1346,7 +1426,10 @@ var stowUpdate = (state, update, store) => {
|
|
|
1346
1426
|
}
|
|
1347
1427
|
store.transactionStatus.atomUpdates.push(atomUpdate);
|
|
1348
1428
|
store.logger.info(
|
|
1349
|
-
`\u{1F4C1}
|
|
1429
|
+
`\u{1F4C1}`,
|
|
1430
|
+
`atom`,
|
|
1431
|
+
key,
|
|
1432
|
+
`stowed (`,
|
|
1350
1433
|
update.oldValue,
|
|
1351
1434
|
`->`,
|
|
1352
1435
|
update.newValue,
|
|
@@ -1359,7 +1442,7 @@ var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1359
1442
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1360
1443
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
1361
1444
|
newValue = become(next)(newValue);
|
|
1362
|
-
store.logger.info(`\u{1F4DD}
|
|
1445
|
+
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
1363
1446
|
cacheValue(atom.key, newValue, atom.subject, store);
|
|
1364
1447
|
if (isAtomDefault(atom.key, store)) {
|
|
1365
1448
|
markAtomAsNotDefault(atom.key, store);
|
|
@@ -1425,13 +1508,18 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1425
1508
|
atomKey: dependency.key
|
|
1426
1509
|
});
|
|
1427
1510
|
store.logger.info(
|
|
1428
|
-
`\u{1F50D}
|
|
1511
|
+
`\u{1F50D}`,
|
|
1512
|
+
`selector`,
|
|
1513
|
+
selectorKey,
|
|
1514
|
+
`discovers root atom "${dependency.key}"`
|
|
1429
1515
|
);
|
|
1430
1516
|
} else {
|
|
1431
1517
|
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1432
1518
|
store.logger.info(
|
|
1433
|
-
`\u{1F50D}
|
|
1434
|
-
|
|
1519
|
+
`\u{1F50D}`,
|
|
1520
|
+
`selector`,
|
|
1521
|
+
selectorKey,
|
|
1522
|
+
`discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
|
|
1435
1523
|
);
|
|
1436
1524
|
for (const atomKey of rootKeys) {
|
|
1437
1525
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
@@ -1455,7 +1543,12 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1455
1543
|
}
|
|
1456
1544
|
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1457
1545
|
store.logger.info(
|
|
1458
|
-
`\u{1F50C}
|
|
1546
|
+
`\u{1F50C}`,
|
|
1547
|
+
`selector`,
|
|
1548
|
+
selectorKey,
|
|
1549
|
+
`registers dependency ( "${dependency.key}" =`,
|
|
1550
|
+
dependencyValue,
|
|
1551
|
+
`)`
|
|
1459
1552
|
);
|
|
1460
1553
|
if (!alreadyRegistered) {
|
|
1461
1554
|
core.selectorGraph = core.selectorGraph.set(
|
|
@@ -1494,7 +1587,16 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1494
1587
|
const setSelf = (next) => {
|
|
1495
1588
|
const oldValue = getSelf();
|
|
1496
1589
|
const newValue = become(next)(oldValue);
|
|
1497
|
-
store.logger.info(
|
|
1590
|
+
store.logger.info(
|
|
1591
|
+
`\u{1F4DD}`,
|
|
1592
|
+
`selector`,
|
|
1593
|
+
options.key,
|
|
1594
|
+
`set (`,
|
|
1595
|
+
oldValue,
|
|
1596
|
+
`->`,
|
|
1597
|
+
newValue,
|
|
1598
|
+
`)`
|
|
1599
|
+
);
|
|
1498
1600
|
cacheValue(options.key, newValue, subject, store);
|
|
1499
1601
|
markDone(options.key, store);
|
|
1500
1602
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1511,7 +1613,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1511
1613
|
}), family && { family });
|
|
1512
1614
|
core.selectors.set(options.key, mySelector);
|
|
1513
1615
|
const initialValue = getSelf();
|
|
1514
|
-
store.logger.info(`\u2728
|
|
1616
|
+
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1515
1617
|
const token = {
|
|
1516
1618
|
key: options.key,
|
|
1517
1619
|
type: `selector`
|
|
@@ -1540,7 +1642,13 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1540
1642
|
}), family && { family });
|
|
1541
1643
|
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1542
1644
|
const initialValue = getSelf();
|
|
1543
|
-
store.logger.info(
|
|
1645
|
+
store.logger.info(
|
|
1646
|
+
`\u2728`,
|
|
1647
|
+
readonlySelector.type,
|
|
1648
|
+
readonlySelector.key,
|
|
1649
|
+
`=`,
|
|
1650
|
+
initialValue
|
|
1651
|
+
);
|
|
1544
1652
|
const token = {
|
|
1545
1653
|
key: options.key,
|
|
1546
1654
|
type: `readonly_selector`
|
|
@@ -1559,9 +1667,10 @@ function createSelector(options, family, store = IMPLICIT.STORE) {
|
|
|
1559
1667
|
const existingReadonly = core.readonlySelectors.get(options.key);
|
|
1560
1668
|
if (existingWritable || existingReadonly) {
|
|
1561
1669
|
store.logger.error(
|
|
1562
|
-
`\
|
|
1563
|
-
|
|
1564
|
-
|
|
1670
|
+
`\u274C`,
|
|
1671
|
+
existingReadonly ? `readonly_selector` : `selector`,
|
|
1672
|
+
options.key,
|
|
1673
|
+
`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
|
|
1565
1674
|
);
|
|
1566
1675
|
}
|
|
1567
1676
|
if (`set` in options) {
|
|
@@ -1743,14 +1852,19 @@ var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1743
1852
|
function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
1744
1853
|
var _a;
|
|
1745
1854
|
store.logger.info(
|
|
1746
|
-
`\u{1F528}
|
|
1855
|
+
`\u{1F528}`,
|
|
1856
|
+
`atom`,
|
|
1857
|
+
options.key,
|
|
1858
|
+
`creating in store "${store.config.name}"`
|
|
1747
1859
|
);
|
|
1748
1860
|
const core = target(store);
|
|
1749
1861
|
const existing = core.atoms.get(options.key);
|
|
1750
1862
|
if (existing) {
|
|
1751
1863
|
store.logger.error(
|
|
1752
|
-
`\
|
|
1753
|
-
`
|
|
1864
|
+
`\u274C`,
|
|
1865
|
+
`atom`,
|
|
1866
|
+
options.key,
|
|
1867
|
+
`Tried to create atom, but it already exists in the store.`,
|
|
1754
1868
|
`(Ignore if you are in development using hot module replacement.)`
|
|
1755
1869
|
);
|
|
1756
1870
|
return deposit(existing);
|
|
@@ -1760,7 +1874,10 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1760
1874
|
type: `atom`,
|
|
1761
1875
|
install: (store2) => {
|
|
1762
1876
|
store2.logger.info(
|
|
1763
|
-
`\u{1F6E0}\uFE0F
|
|
1877
|
+
`\u{1F6E0}\uFE0F`,
|
|
1878
|
+
`atom`,
|
|
1879
|
+
options.key,
|
|
1880
|
+
`installing in store "${store2.config.name}"`
|
|
1764
1881
|
);
|
|
1765
1882
|
return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
|
|
1766
1883
|
},
|
|
@@ -1790,7 +1907,7 @@ function deleteAtom(atomToken, store = IMPLICIT.STORE) {
|
|
|
1790
1907
|
core.selectorAtoms.delete(key);
|
|
1791
1908
|
core.atomsThatAreDefault.delete(key);
|
|
1792
1909
|
core.timelineAtoms.delete(key);
|
|
1793
|
-
store.logger.info(`\u{1F525}
|
|
1910
|
+
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1794
1911
|
}
|
|
1795
1912
|
|
|
1796
1913
|
// src/subscribe/recall-state.ts
|
|
@@ -1798,7 +1915,10 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1798
1915
|
const core = target(store);
|
|
1799
1916
|
if (!core.operation.open) {
|
|
1800
1917
|
store.logger.warn(
|
|
1801
|
-
`\u{1F41E}
|
|
1918
|
+
`\u{1F41E}`,
|
|
1919
|
+
state.type,
|
|
1920
|
+
state.key,
|
|
1921
|
+
`recall called outside of an operation. This is probably a bug.`
|
|
1802
1922
|
);
|
|
1803
1923
|
return core.valueMap.get(state.key);
|
|
1804
1924
|
}
|
|
@@ -1818,20 +1938,26 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1818
1938
|
`${state.type}:${state.key}`,
|
|
1819
1939
|
(atomChange) => {
|
|
1820
1940
|
store.logger.info(
|
|
1821
|
-
`\u{1F4E2}
|
|
1941
|
+
`\u{1F4E2}`,
|
|
1942
|
+
state.type,
|
|
1943
|
+
state.key,
|
|
1944
|
+
`root`,
|
|
1945
|
+
atomKey,
|
|
1946
|
+
`went`,
|
|
1822
1947
|
atomChange.oldValue,
|
|
1823
1948
|
`->`,
|
|
1824
|
-
atomChange.newValue
|
|
1825
|
-
`)`
|
|
1949
|
+
atomChange.newValue
|
|
1826
1950
|
);
|
|
1827
1951
|
const oldValue = recallState(state, store);
|
|
1828
1952
|
const newValue = getState__INTERNAL(state, store);
|
|
1829
1953
|
store.logger.info(
|
|
1830
|
-
`\u2728
|
|
1954
|
+
`\u2728`,
|
|
1955
|
+
state.type,
|
|
1956
|
+
state.key,
|
|
1957
|
+
`went`,
|
|
1831
1958
|
oldValue,
|
|
1832
1959
|
`->`,
|
|
1833
|
-
newValue
|
|
1834
|
-
`)`
|
|
1960
|
+
newValue
|
|
1835
1961
|
);
|
|
1836
1962
|
state.subject.next({ newValue, oldValue });
|
|
1837
1963
|
}
|