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.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,17 +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
|
}
|
|
382
|
+
store.logger.info(
|
|
383
|
+
`\u{1FA82}`,
|
|
384
|
+
`transaction`,
|
|
385
|
+
store.transactionStatus.key,
|
|
386
|
+
`Aborting transaction`
|
|
387
|
+
);
|
|
386
388
|
store.transactionStatus = { phase: `idle` };
|
|
387
|
-
store.logger.info(`\u{1FA82}`, `transaction fail`);
|
|
388
389
|
};
|
|
389
390
|
var applyTransaction = (output, store) => {
|
|
390
391
|
if (store.transactionStatus.phase !== `building`) {
|
|
391
392
|
store.logger.warn(
|
|
392
|
-
`\u{1F41E}
|
|
393
|
+
`\u{1F41E}`,
|
|
394
|
+
`transaction`,
|
|
395
|
+
`???`,
|
|
396
|
+
`applyTransaction called outside of a transaction. This is probably a bug in AtomIO.`
|
|
393
397
|
);
|
|
394
398
|
return;
|
|
395
399
|
}
|
|
@@ -397,9 +401,12 @@ var applyTransaction = (output, store) => {
|
|
|
397
401
|
store.transactionStatus.output = output;
|
|
398
402
|
const { atomUpdates } = store.transactionStatus;
|
|
399
403
|
store.logger.info(
|
|
400
|
-
`\u{
|
|
404
|
+
`\u{1F6C4}`,
|
|
405
|
+
`transaction`,
|
|
406
|
+
store.transactionStatus.key,
|
|
407
|
+
`Applying transaction with ${atomUpdates.length} updates:`,
|
|
408
|
+
atomUpdates
|
|
401
409
|
);
|
|
402
|
-
store.logger.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
403
410
|
for (const { key, newValue } of atomUpdates) {
|
|
404
411
|
const token = { key, type: `atom` };
|
|
405
412
|
if (!store.valueMap.has(token.key)) {
|
|
@@ -417,7 +424,12 @@ var applyTransaction = (output, store) => {
|
|
|
417
424
|
}
|
|
418
425
|
store.atoms.set(newAtom.key, newAtom);
|
|
419
426
|
store.valueMap.set(newAtom.key, newAtom.default);
|
|
420
|
-
store.logger.info(
|
|
427
|
+
store.logger.info(
|
|
428
|
+
`\u{1F528}`,
|
|
429
|
+
`transaction`,
|
|
430
|
+
store.transactionStatus.key,
|
|
431
|
+
`Adding atom "${newAtom.key}"`
|
|
432
|
+
);
|
|
421
433
|
}
|
|
422
434
|
}
|
|
423
435
|
atom_io.setState(token, newValue, store);
|
|
@@ -437,8 +449,13 @@ var applyTransaction = (output, store) => {
|
|
|
437
449
|
output,
|
|
438
450
|
params: store.transactionStatus.params
|
|
439
451
|
});
|
|
452
|
+
store.logger.info(
|
|
453
|
+
`\u{1F6EC}`,
|
|
454
|
+
`transaction`,
|
|
455
|
+
store.transactionStatus.key,
|
|
456
|
+
`Finished applying transaction.`
|
|
457
|
+
);
|
|
440
458
|
store.transactionStatus = { phase: `idle` };
|
|
441
|
-
store.logger.info(`\u{1F6EC} transaction "${myTransaction.key}" applied`);
|
|
442
459
|
};
|
|
443
460
|
|
|
444
461
|
// src/transaction/build-transaction.ts
|
|
@@ -469,7 +486,11 @@ var buildTransaction = (key, params, store) => {
|
|
|
469
486
|
output: void 0
|
|
470
487
|
};
|
|
471
488
|
store.logger.info(
|
|
472
|
-
`\u{1F6EB}
|
|
489
|
+
`\u{1F6EB}`,
|
|
490
|
+
`transaction`,
|
|
491
|
+
key,
|
|
492
|
+
`Building transaction with params:`,
|
|
493
|
+
params
|
|
473
494
|
);
|
|
474
495
|
};
|
|
475
496
|
|
|
@@ -492,10 +513,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
492
513
|
return output;
|
|
493
514
|
} catch (thrown) {
|
|
494
515
|
abortTransaction(store);
|
|
495
|
-
store.logger.
|
|
496
|
-
`\u2757 Transaction "${options.key}" failed in store "${store.config.name}":`,
|
|
497
|
-
thrown
|
|
498
|
-
);
|
|
516
|
+
store.logger.warn(`\u{1F4A5}`, `transaction`, options.key, `caught:`, thrown);
|
|
499
517
|
throw thrown;
|
|
500
518
|
}
|
|
501
519
|
},
|
|
@@ -510,7 +528,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
510
528
|
}
|
|
511
529
|
var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
|
|
512
530
|
var redoTransactionUpdate = (update, store) => {
|
|
513
|
-
store.logger.info(
|
|
531
|
+
store.logger.info(`\u23ED\uFE0F`, `transaction`, update.key, `Redo`);
|
|
514
532
|
for (const { key, newValue } of update.atomUpdates) {
|
|
515
533
|
const token = { key, type: `atom` };
|
|
516
534
|
const state = withdraw(token, store);
|
|
@@ -523,7 +541,13 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
523
541
|
}
|
|
524
542
|
};
|
|
525
543
|
var undoTransactionUpdate = (update, store) => {
|
|
526
|
-
store.logger.info(
|
|
544
|
+
store.logger.info(
|
|
545
|
+
`\u23EE\uFE0F`,
|
|
546
|
+
`transaction`,
|
|
547
|
+
update.key,
|
|
548
|
+
`Undoing transaction update`,
|
|
549
|
+
update
|
|
550
|
+
);
|
|
527
551
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
528
552
|
const token = { key, type: `atom` };
|
|
529
553
|
const state = withdraw(token, store);
|
|
@@ -554,11 +578,16 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
554
578
|
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
555
579
|
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
556
580
|
store.logger.info(
|
|
557
|
-
`\u23F3
|
|
581
|
+
`\u23F3`,
|
|
582
|
+
`timeline`,
|
|
583
|
+
tl.key,
|
|
584
|
+
`atom`,
|
|
585
|
+
atomToken.key,
|
|
586
|
+
`went`,
|
|
558
587
|
update.oldValue,
|
|
559
588
|
`->`,
|
|
560
589
|
update.newValue,
|
|
561
|
-
currentTransactionKey ? `
|
|
590
|
+
currentTransactionKey ? `in transaction "${currentTransactionKey}"` : currentSelectorKey ? `in selector "${currentSelectorKey}"` : ``
|
|
562
591
|
);
|
|
563
592
|
if (tl.timeTraveling === null) {
|
|
564
593
|
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
@@ -582,7 +611,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
582
611
|
if (tl.transactionKey !== currentTransactionKey) {
|
|
583
612
|
if (tl.transactionKey) {
|
|
584
613
|
store.logger.error(
|
|
585
|
-
`\u{1F41E}
|
|
614
|
+
`\u{1F41E}`,
|
|
615
|
+
`timeline`,
|
|
616
|
+
tl.key,
|
|
617
|
+
`unable to resolve transaction "${tl.transactionKey}. This is probably a bug in AtomIO.`
|
|
586
618
|
);
|
|
587
619
|
}
|
|
588
620
|
tl.transactionKey = currentTransactionKey;
|
|
@@ -622,7 +654,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
622
654
|
}
|
|
623
655
|
tl.transactionKey = null;
|
|
624
656
|
store.logger.info(
|
|
625
|
-
`\u231B
|
|
657
|
+
`\u231B`,
|
|
658
|
+
`timeline`,
|
|
659
|
+
tl.key,
|
|
660
|
+
`got a transaction_update "${update2.key}"`
|
|
626
661
|
);
|
|
627
662
|
}
|
|
628
663
|
);
|
|
@@ -645,7 +680,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
645
680
|
}
|
|
646
681
|
tl.history.push(latestUpdate);
|
|
647
682
|
store.logger.info(
|
|
648
|
-
`\u231B
|
|
683
|
+
`\u231B`,
|
|
684
|
+
`timeline`,
|
|
685
|
+
tl.key,
|
|
686
|
+
`got a selector_update "${currentSelectorKey}" with`,
|
|
649
687
|
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
650
688
|
);
|
|
651
689
|
tl.at = tl.history.length;
|
|
@@ -657,7 +695,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
657
695
|
type: `atom_update`
|
|
658
696
|
}, update));
|
|
659
697
|
store.logger.info(
|
|
660
|
-
`\u231B
|
|
698
|
+
`\u231B`,
|
|
699
|
+
`timeline`,
|
|
700
|
+
tl.key,
|
|
701
|
+
`set selector_update "${currentSelectorKey}" to`,
|
|
661
702
|
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
662
703
|
);
|
|
663
704
|
}
|
|
@@ -689,7 +730,10 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
689
730
|
}
|
|
690
731
|
const willCapture = (_d = (_c = tl.shouldCapture) == null ? void 0 : _c.call(tl, atomUpdate, tl)) != null ? _d : true;
|
|
691
732
|
store.logger.info(
|
|
692
|
-
`\u231B
|
|
733
|
+
`\u231B`,
|
|
734
|
+
`timeline`,
|
|
735
|
+
tl.key,
|
|
736
|
+
`got an atom_update to "${atom.key}"`
|
|
693
737
|
);
|
|
694
738
|
if (willCapture) {
|
|
695
739
|
tl.history.push(atomUpdate);
|
|
@@ -701,17 +745,23 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
701
745
|
});
|
|
702
746
|
};
|
|
703
747
|
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
704
|
-
store.logger.info(`\u23E9
|
|
748
|
+
store.logger.info(`\u23E9`, `timeline`, token.key, `redo`);
|
|
705
749
|
const timelineData = store.timelines.get(token.key);
|
|
706
750
|
if (!timelineData) {
|
|
707
751
|
store.logger.error(
|
|
708
|
-
`\u{1F41E}
|
|
752
|
+
`\u{1F41E}`,
|
|
753
|
+
`timeline`,
|
|
754
|
+
token.key,
|
|
755
|
+
`Failed to redo. This timeline has not been initialized.`
|
|
709
756
|
);
|
|
710
757
|
return;
|
|
711
758
|
}
|
|
712
759
|
if (timelineData.at === timelineData.history.length) {
|
|
713
760
|
store.logger.warn(
|
|
714
|
-
`\
|
|
761
|
+
`\u{1F481}`,
|
|
762
|
+
`timeline`,
|
|
763
|
+
token.key,
|
|
764
|
+
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
715
765
|
);
|
|
716
766
|
return;
|
|
717
767
|
}
|
|
@@ -736,21 +786,30 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
736
786
|
timelineData.subject.next(`redo`);
|
|
737
787
|
timelineData.timeTraveling = null;
|
|
738
788
|
store.logger.info(
|
|
739
|
-
`\u23F9\uFE0F
|
|
789
|
+
`\u23F9\uFE0F`,
|
|
790
|
+
`timeline`,
|
|
791
|
+
token.key,
|
|
792
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
740
793
|
);
|
|
741
794
|
};
|
|
742
795
|
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
743
|
-
store.logger.info(`\u23EA
|
|
796
|
+
store.logger.info(`\u23EA`, `timeline`, token.key, `undo`);
|
|
744
797
|
const timelineData = store.timelines.get(token.key);
|
|
745
798
|
if (!timelineData) {
|
|
746
799
|
store.logger.error(
|
|
747
|
-
`\u{1F41E}
|
|
800
|
+
`\u{1F41E}`,
|
|
801
|
+
`timeline`,
|
|
802
|
+
token.key,
|
|
803
|
+
`Failed to undo. This timeline has not been initialized.`
|
|
748
804
|
);
|
|
749
805
|
return;
|
|
750
806
|
}
|
|
751
807
|
if (timelineData.at === 0) {
|
|
752
808
|
store.logger.warn(
|
|
753
|
-
`\
|
|
809
|
+
`\u{1F481}`,
|
|
810
|
+
`timeline`,
|
|
811
|
+
token.key,
|
|
812
|
+
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
754
813
|
);
|
|
755
814
|
return;
|
|
756
815
|
}
|
|
@@ -775,7 +834,10 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
775
834
|
timelineData.subject.next(`undo`);
|
|
776
835
|
timelineData.timeTraveling = null;
|
|
777
836
|
store.logger.info(
|
|
778
|
-
`\u23F9\uFE0F
|
|
837
|
+
`\u23F9\uFE0F`,
|
|
838
|
+
`timeline`,
|
|
839
|
+
token.key,
|
|
840
|
+
`"${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
779
841
|
);
|
|
780
842
|
};
|
|
781
843
|
|
|
@@ -802,7 +864,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
802
864
|
const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
|
|
803
865
|
if (timelineKey) {
|
|
804
866
|
store.logger.error(
|
|
805
|
-
`\u274C
|
|
867
|
+
`\u274C`,
|
|
868
|
+
`timeline`,
|
|
869
|
+
options.key,
|
|
870
|
+
`Failed to add atom "${tokenOrFamily.key}" because it already belongs to timeline "${timelineKey}"`
|
|
806
871
|
);
|
|
807
872
|
continue;
|
|
808
873
|
}
|
|
@@ -824,7 +889,10 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
|
824
889
|
);
|
|
825
890
|
if (familyTimelineKey) {
|
|
826
891
|
store.logger.error(
|
|
827
|
-
`\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}"`
|
|
828
896
|
);
|
|
829
897
|
continue;
|
|
830
898
|
}
|
|
@@ -857,7 +925,12 @@ function withdraw(token, store) {
|
|
|
857
925
|
core = store.transactionStatus.core;
|
|
858
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);
|
|
859
927
|
if (state) {
|
|
860
|
-
store.logger.info(
|
|
928
|
+
store.logger.info(
|
|
929
|
+
`\u{1F6E0}\uFE0F`,
|
|
930
|
+
token.type,
|
|
931
|
+
token.key,
|
|
932
|
+
`add ${token.type} "${token.key}"`
|
|
933
|
+
);
|
|
861
934
|
switch (state.type) {
|
|
862
935
|
case `atom`: {
|
|
863
936
|
store.atoms.set(token.key, state);
|
|
@@ -896,7 +969,10 @@ function withdraw(token, store) {
|
|
|
896
969
|
// src/store/withdraw-new-family-member.ts
|
|
897
970
|
function withdrawNewFamilyMember(token, store) {
|
|
898
971
|
store.logger.info(
|
|
899
|
-
`\u{1F46A}
|
|
972
|
+
`\u{1F46A}`,
|
|
973
|
+
token.type,
|
|
974
|
+
token.key,
|
|
975
|
+
`creating new family member in store "${store.config.name}"`
|
|
900
976
|
);
|
|
901
977
|
if (token.family) {
|
|
902
978
|
const core = target(store);
|
|
@@ -926,9 +1002,9 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
926
1002
|
}
|
|
927
1003
|
cacheValue(key, value2, subject, store);
|
|
928
1004
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
929
|
-
}).catch((
|
|
930
|
-
if (
|
|
931
|
-
store.logger.error(`\u{
|
|
1005
|
+
}).catch((thrown) => {
|
|
1006
|
+
if (thrown !== `canceled`) {
|
|
1007
|
+
store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
932
1008
|
}
|
|
933
1009
|
});
|
|
934
1010
|
} else {
|
|
@@ -947,7 +1023,7 @@ var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
|
947
1023
|
core.operation.prev.set(key, currentValue);
|
|
948
1024
|
}
|
|
949
1025
|
core.valueMap.delete(key);
|
|
950
|
-
store.logger.info(`\u{1F5D1}
|
|
1026
|
+
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
951
1027
|
};
|
|
952
1028
|
var Tracker = class {
|
|
953
1029
|
constructor(mutableState, store = IMPLICIT.STORE) {
|
|
@@ -1068,7 +1144,10 @@ var Tracker = class {
|
|
|
1068
1144
|
// src/mutable/create-mutable-atom.ts
|
|
1069
1145
|
function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
1070
1146
|
store.logger.info(
|
|
1071
|
-
`\u{1F527}
|
|
1147
|
+
`\u{1F527}`,
|
|
1148
|
+
`atom`,
|
|
1149
|
+
options.key,
|
|
1150
|
+
`creating in store "${store.config.name}"`
|
|
1072
1151
|
);
|
|
1073
1152
|
const coreState = createAtom(options, void 0, store);
|
|
1074
1153
|
new Tracker(coreState, store);
|
|
@@ -1076,10 +1155,6 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1076
1155
|
atom_io.subscribe(
|
|
1077
1156
|
jsonState,
|
|
1078
1157
|
() => {
|
|
1079
|
-
store.logger.info(
|
|
1080
|
-
`\u{1F50D} tracker-initializer:${store == null ? void 0 : store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
1081
|
-
`Initializing tracker for ${coreState.key}`
|
|
1082
|
-
);
|
|
1083
1158
|
const trackerHasBeenInitialized = target(store).trackers.has(coreState.key);
|
|
1084
1159
|
if (!trackerHasBeenInitialized) {
|
|
1085
1160
|
new Tracker(coreState, store);
|
|
@@ -1139,16 +1214,14 @@ var getSelectorDependencyKeys = (key, store) => {
|
|
|
1139
1214
|
// src/get-state-internal.ts
|
|
1140
1215
|
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
1141
1216
|
if (isValueCached(state.key, store)) {
|
|
1142
|
-
store.logger.info(`\u{1F4D6}
|
|
1217
|
+
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
1143
1218
|
return readCachedValue(state.key, store);
|
|
1144
1219
|
}
|
|
1145
1220
|
if (state.type !== `atom`) {
|
|
1146
|
-
store.logger.info(`\u{1F9EE}
|
|
1221
|
+
store.logger.info(`\u{1F9EE}`, state.type, state.key, `calculating value`);
|
|
1147
1222
|
return state.get();
|
|
1148
1223
|
}
|
|
1149
|
-
store.logger.error(
|
|
1150
|
-
`\u{1F41E} Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
1151
|
-
);
|
|
1224
|
+
store.logger.error(`\u{1F41E}`, `atom`, state.key, `could not find cached value`);
|
|
1152
1225
|
return state.default;
|
|
1153
1226
|
};
|
|
1154
1227
|
|
|
@@ -1162,7 +1235,10 @@ var openOperation = (token, store) => {
|
|
|
1162
1235
|
const core = target(store);
|
|
1163
1236
|
if (core.operation.open) {
|
|
1164
1237
|
store.logger.error(
|
|
1165
|
-
`\u274C
|
|
1238
|
+
`\u274C`,
|
|
1239
|
+
token.type,
|
|
1240
|
+
token.key,
|
|
1241
|
+
`failed to setState during a setState for "${core.operation.token.key}"`
|
|
1166
1242
|
);
|
|
1167
1243
|
return `rejection`;
|
|
1168
1244
|
}
|
|
@@ -1174,19 +1250,32 @@ var openOperation = (token, store) => {
|
|
|
1174
1250
|
token
|
|
1175
1251
|
};
|
|
1176
1252
|
store.logger.info(
|
|
1177
|
-
`\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}"`}`
|
|
1178
1257
|
);
|
|
1179
1258
|
};
|
|
1180
1259
|
var closeOperation = (store) => {
|
|
1181
1260
|
const core = target(store);
|
|
1261
|
+
if (core.operation.open) {
|
|
1262
|
+
store.logger.info(
|
|
1263
|
+
`\u{1F534}`,
|
|
1264
|
+
core.operation.token.type,
|
|
1265
|
+
core.operation.token.key,
|
|
1266
|
+
`operation done in store "${store.config.name}"`
|
|
1267
|
+
);
|
|
1268
|
+
}
|
|
1182
1269
|
core.operation = { open: false };
|
|
1183
|
-
store.logger.info(`\u{1F534} operation done`);
|
|
1184
1270
|
store.subject.operationStatus.next(core.operation);
|
|
1185
1271
|
};
|
|
1186
1272
|
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
1187
1273
|
const core = target(store);
|
|
1188
1274
|
if (!core.operation.open) {
|
|
1189
1275
|
store.logger.warn(
|
|
1276
|
+
`\u{1F41E}`,
|
|
1277
|
+
`unknown`,
|
|
1278
|
+
key,
|
|
1190
1279
|
`isDone called outside of an operation. This is probably a bug.`
|
|
1191
1280
|
);
|
|
1192
1281
|
return true;
|
|
@@ -1197,7 +1286,10 @@ var markDone = (key, store = IMPLICIT.STORE) => {
|
|
|
1197
1286
|
const core = target(store);
|
|
1198
1287
|
if (!core.operation.open) {
|
|
1199
1288
|
store.logger.warn(
|
|
1200
|
-
`\u{1F41E}
|
|
1289
|
+
`\u{1F41E}`,
|
|
1290
|
+
`unknown`,
|
|
1291
|
+
key,
|
|
1292
|
+
`markDone called outside of an operation. This is probably a bug.`
|
|
1201
1293
|
);
|
|
1202
1294
|
return;
|
|
1203
1295
|
}
|
|
@@ -1209,7 +1301,7 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1209
1301
|
const originValue = origin.valueMap.get(atom.key);
|
|
1210
1302
|
const targetValue = target2.valueMap.get(atom.key);
|
|
1211
1303
|
if (originValue === targetValue) {
|
|
1212
|
-
origin.logger.info(`\u{1F4C3}
|
|
1304
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
1213
1305
|
const copiedValue = transform.fromJson(transform.toJson(originValue));
|
|
1214
1306
|
target2.valueMap.set(atom.key, copiedValue);
|
|
1215
1307
|
new Tracker(atom, origin);
|
|
@@ -1222,9 +1314,6 @@ function copyMutableIfNeeded(atom, transform, origin, target2) {
|
|
|
1222
1314
|
function copyMutableIfWithinTransaction(atom, store) {
|
|
1223
1315
|
if (store.transactionStatus.phase === `building` || store.transactionStatus.phase === `applying`) {
|
|
1224
1316
|
if (`toJson` in atom && `fromJson` in atom) {
|
|
1225
|
-
store.logger.info(
|
|
1226
|
-
`\u{1F4C4} copyMutableIfWithinTransaction: ${atom.key} is mutable`
|
|
1227
|
-
);
|
|
1228
1317
|
const copiedValue = copyMutableIfNeeded(
|
|
1229
1318
|
atom,
|
|
1230
1319
|
atom,
|
|
@@ -1260,43 +1349,46 @@ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target2)
|
|
|
1260
1349
|
|
|
1261
1350
|
// src/set-state/emit-update.ts
|
|
1262
1351
|
var emitUpdate = (state, update, store) => {
|
|
1263
|
-
const { key } = state;
|
|
1264
1352
|
const { logger } = store;
|
|
1265
1353
|
logger.info(
|
|
1266
|
-
`\u{1F4E2}
|
|
1354
|
+
`\u{1F4E2}`,
|
|
1355
|
+
state.type,
|
|
1356
|
+
state.key,
|
|
1357
|
+
`went (`,
|
|
1267
1358
|
update.oldValue,
|
|
1268
1359
|
`->`,
|
|
1269
1360
|
update.newValue,
|
|
1270
|
-
`)
|
|
1361
|
+
`) subscribers:`,
|
|
1362
|
+
state.subject.subscribers
|
|
1271
1363
|
);
|
|
1272
|
-
logger.info(`\u{1F4E2} notifying subscribers:`, state.subject.subscribers);
|
|
1273
1364
|
state.subject.next(update);
|
|
1274
1365
|
};
|
|
1275
1366
|
|
|
1276
1367
|
// src/set-state/evict-downstream.ts
|
|
1277
|
-
var evictDownStream = (
|
|
1368
|
+
var evictDownStream = (atom, store = IMPLICIT.STORE) => {
|
|
1278
1369
|
var _a;
|
|
1279
1370
|
const core = target(store);
|
|
1280
|
-
const downstreamKeys = core.selectorAtoms.getRelatedKeys(
|
|
1371
|
+
const downstreamKeys = core.selectorAtoms.getRelatedKeys(atom.key);
|
|
1281
1372
|
store.logger.info(
|
|
1282
|
-
`\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:`,
|
|
1283
1377
|
downstreamKeys
|
|
1284
1378
|
);
|
|
1285
|
-
if (
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1379
|
+
if (downstreamKeys !== void 0) {
|
|
1380
|
+
if (core.operation.open) {
|
|
1381
|
+
store.logger.info(
|
|
1382
|
+
`\u{1F9F9}`,
|
|
1383
|
+
atom.type,
|
|
1384
|
+
atom.key,
|
|
1385
|
+
`[ ${[...core.operation.done].join(`, `)} ] already done`
|
|
1386
|
+
);
|
|
1387
|
+
}
|
|
1289
1388
|
for (const key of downstreamKeys) {
|
|
1290
1389
|
if (isDone(key, store)) {
|
|
1291
1390
|
continue;
|
|
1292
1391
|
}
|
|
1293
|
-
const state2 = (_a = core.selectors.get(key)) != null ? _a : core.readonlySelectors.get(key);
|
|
1294
|
-
if (!state2) {
|
|
1295
|
-
store.logger.error(
|
|
1296
|
-
`\u{1F41E} "${key}" was not found in selectors or readonlySelectors`
|
|
1297
|
-
);
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
1392
|
evictCachedValue(key, store);
|
|
1301
1393
|
markDone(key, store);
|
|
1302
1394
|
}
|
|
@@ -1316,8 +1408,11 @@ function shouldUpdateBeStowed(key, update) {
|
|
|
1316
1408
|
var stowUpdate = (state, update, store) => {
|
|
1317
1409
|
const { key } = state;
|
|
1318
1410
|
if (store.transactionStatus.phase !== `building`) {
|
|
1319
|
-
store.logger.
|
|
1320
|
-
`\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.`
|
|
1321
1416
|
);
|
|
1322
1417
|
return;
|
|
1323
1418
|
}
|
|
@@ -1331,7 +1426,10 @@ var stowUpdate = (state, update, store) => {
|
|
|
1331
1426
|
}
|
|
1332
1427
|
store.transactionStatus.atomUpdates.push(atomUpdate);
|
|
1333
1428
|
store.logger.info(
|
|
1334
|
-
`\u{1F4C1}
|
|
1429
|
+
`\u{1F4C1}`,
|
|
1430
|
+
`atom`,
|
|
1431
|
+
key,
|
|
1432
|
+
`stowed (`,
|
|
1335
1433
|
update.oldValue,
|
|
1336
1434
|
`->`,
|
|
1337
1435
|
update.newValue,
|
|
@@ -1344,7 +1442,7 @@ var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1344
1442
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1345
1443
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
1346
1444
|
newValue = become(next)(newValue);
|
|
1347
|
-
store.logger.info(`\u{1F4DD}
|
|
1445
|
+
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
1348
1446
|
cacheValue(atom.key, newValue, atom.subject, store);
|
|
1349
1447
|
if (isAtomDefault(atom.key, store)) {
|
|
1350
1448
|
markAtomAsNotDefault(atom.key, store);
|
|
@@ -1410,13 +1508,18 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1410
1508
|
atomKey: dependency.key
|
|
1411
1509
|
});
|
|
1412
1510
|
store.logger.info(
|
|
1413
|
-
`\u{1F50D}
|
|
1511
|
+
`\u{1F50D}`,
|
|
1512
|
+
`selector`,
|
|
1513
|
+
selectorKey,
|
|
1514
|
+
`discovers root atom "${dependency.key}"`
|
|
1414
1515
|
);
|
|
1415
1516
|
} else {
|
|
1416
1517
|
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1417
1518
|
store.logger.info(
|
|
1418
|
-
`\u{1F50D}
|
|
1419
|
-
|
|
1519
|
+
`\u{1F50D}`,
|
|
1520
|
+
`selector`,
|
|
1521
|
+
selectorKey,
|
|
1522
|
+
`discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
|
|
1420
1523
|
);
|
|
1421
1524
|
for (const atomKey of rootKeys) {
|
|
1422
1525
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
@@ -1440,7 +1543,12 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1440
1543
|
}
|
|
1441
1544
|
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1442
1545
|
store.logger.info(
|
|
1443
|
-
`\u{1F50C}
|
|
1546
|
+
`\u{1F50C}`,
|
|
1547
|
+
`selector`,
|
|
1548
|
+
selectorKey,
|
|
1549
|
+
`registers dependency ( "${dependency.key}" =`,
|
|
1550
|
+
dependencyValue,
|
|
1551
|
+
`)`
|
|
1444
1552
|
);
|
|
1445
1553
|
if (!alreadyRegistered) {
|
|
1446
1554
|
core.selectorGraph = core.selectorGraph.set(
|
|
@@ -1479,7 +1587,16 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1479
1587
|
const setSelf = (next) => {
|
|
1480
1588
|
const oldValue = getSelf();
|
|
1481
1589
|
const newValue = become(next)(oldValue);
|
|
1482
|
-
store.logger.info(
|
|
1590
|
+
store.logger.info(
|
|
1591
|
+
`\u{1F4DD}`,
|
|
1592
|
+
`selector`,
|
|
1593
|
+
options.key,
|
|
1594
|
+
`set (`,
|
|
1595
|
+
oldValue,
|
|
1596
|
+
`->`,
|
|
1597
|
+
newValue,
|
|
1598
|
+
`)`
|
|
1599
|
+
);
|
|
1483
1600
|
cacheValue(options.key, newValue, subject, store);
|
|
1484
1601
|
markDone(options.key, store);
|
|
1485
1602
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1496,7 +1613,7 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1496
1613
|
}), family && { family });
|
|
1497
1614
|
core.selectors.set(options.key, mySelector);
|
|
1498
1615
|
const initialValue = getSelf();
|
|
1499
|
-
store.logger.info(`\u2728
|
|
1616
|
+
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1500
1617
|
const token = {
|
|
1501
1618
|
key: options.key,
|
|
1502
1619
|
type: `selector`
|
|
@@ -1525,7 +1642,13 @@ var createReadonlySelector = (options, family, store, core) => {
|
|
|
1525
1642
|
}), family && { family });
|
|
1526
1643
|
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1527
1644
|
const initialValue = getSelf();
|
|
1528
|
-
store.logger.info(
|
|
1645
|
+
store.logger.info(
|
|
1646
|
+
`\u2728`,
|
|
1647
|
+
readonlySelector.type,
|
|
1648
|
+
readonlySelector.key,
|
|
1649
|
+
`=`,
|
|
1650
|
+
initialValue
|
|
1651
|
+
);
|
|
1529
1652
|
const token = {
|
|
1530
1653
|
key: options.key,
|
|
1531
1654
|
type: `readonly_selector`
|
|
@@ -1544,9 +1667,10 @@ function createSelector(options, family, store = IMPLICIT.STORE) {
|
|
|
1544
1667
|
const existingReadonly = core.readonlySelectors.get(options.key);
|
|
1545
1668
|
if (existingWritable || existingReadonly) {
|
|
1546
1669
|
store.logger.error(
|
|
1547
|
-
`\
|
|
1548
|
-
|
|
1549
|
-
|
|
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.)`
|
|
1550
1674
|
);
|
|
1551
1675
|
}
|
|
1552
1676
|
if (`set` in options) {
|
|
@@ -1728,14 +1852,19 @@ var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1728
1852
|
function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
1729
1853
|
var _a;
|
|
1730
1854
|
store.logger.info(
|
|
1731
|
-
`\u{1F528}
|
|
1855
|
+
`\u{1F528}`,
|
|
1856
|
+
`atom`,
|
|
1857
|
+
options.key,
|
|
1858
|
+
`creating in store "${store.config.name}"`
|
|
1732
1859
|
);
|
|
1733
1860
|
const core = target(store);
|
|
1734
1861
|
const existing = core.atoms.get(options.key);
|
|
1735
1862
|
if (existing) {
|
|
1736
1863
|
store.logger.error(
|
|
1737
|
-
`\
|
|
1738
|
-
`
|
|
1864
|
+
`\u274C`,
|
|
1865
|
+
`atom`,
|
|
1866
|
+
options.key,
|
|
1867
|
+
`Tried to create atom, but it already exists in the store.`,
|
|
1739
1868
|
`(Ignore if you are in development using hot module replacement.)`
|
|
1740
1869
|
);
|
|
1741
1870
|
return deposit(existing);
|
|
@@ -1745,7 +1874,10 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1745
1874
|
type: `atom`,
|
|
1746
1875
|
install: (store2) => {
|
|
1747
1876
|
store2.logger.info(
|
|
1748
|
-
`\u{1F6E0}\uFE0F
|
|
1877
|
+
`\u{1F6E0}\uFE0F`,
|
|
1878
|
+
`atom`,
|
|
1879
|
+
options.key,
|
|
1880
|
+
`installing in store "${store2.config.name}"`
|
|
1749
1881
|
);
|
|
1750
1882
|
return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
|
|
1751
1883
|
},
|
|
@@ -1775,7 +1907,7 @@ function deleteAtom(atomToken, store = IMPLICIT.STORE) {
|
|
|
1775
1907
|
core.selectorAtoms.delete(key);
|
|
1776
1908
|
core.atomsThatAreDefault.delete(key);
|
|
1777
1909
|
core.timelineAtoms.delete(key);
|
|
1778
|
-
store.logger.info(`\u{1F525}
|
|
1910
|
+
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1779
1911
|
}
|
|
1780
1912
|
|
|
1781
1913
|
// src/subscribe/recall-state.ts
|
|
@@ -1783,7 +1915,10 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1783
1915
|
const core = target(store);
|
|
1784
1916
|
if (!core.operation.open) {
|
|
1785
1917
|
store.logger.warn(
|
|
1786
|
-
`\u{1F41E}
|
|
1918
|
+
`\u{1F41E}`,
|
|
1919
|
+
state.type,
|
|
1920
|
+
state.key,
|
|
1921
|
+
`recall called outside of an operation. This is probably a bug.`
|
|
1787
1922
|
);
|
|
1788
1923
|
return core.valueMap.get(state.key);
|
|
1789
1924
|
}
|
|
@@ -1803,20 +1938,26 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1803
1938
|
`${state.type}:${state.key}`,
|
|
1804
1939
|
(atomChange) => {
|
|
1805
1940
|
store.logger.info(
|
|
1806
|
-
`\u{1F4E2}
|
|
1941
|
+
`\u{1F4E2}`,
|
|
1942
|
+
state.type,
|
|
1943
|
+
state.key,
|
|
1944
|
+
`root`,
|
|
1945
|
+
atomKey,
|
|
1946
|
+
`went`,
|
|
1807
1947
|
atomChange.oldValue,
|
|
1808
1948
|
`->`,
|
|
1809
|
-
atomChange.newValue
|
|
1810
|
-
`)`
|
|
1949
|
+
atomChange.newValue
|
|
1811
1950
|
);
|
|
1812
1951
|
const oldValue = recallState(state, store);
|
|
1813
1952
|
const newValue = getState__INTERNAL(state, store);
|
|
1814
1953
|
store.logger.info(
|
|
1815
|
-
`\u2728
|
|
1954
|
+
`\u2728`,
|
|
1955
|
+
state.type,
|
|
1956
|
+
state.key,
|
|
1957
|
+
`went`,
|
|
1816
1958
|
oldValue,
|
|
1817
1959
|
`->`,
|
|
1818
|
-
newValue
|
|
1819
|
-
`)`
|
|
1960
|
+
newValue
|
|
1820
1961
|
);
|
|
1821
1962
|
state.subject.next({ newValue, oldValue });
|
|
1822
1963
|
}
|