atom.io 0.34.2 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eslint-plugin/index.d.ts +2 -18
- package/dist/eslint-plugin/index.d.ts.map +1 -1
- package/dist/eslint-plugin/index.js +4 -141
- package/dist/eslint-plugin/index.js.map +1 -1
- package/dist/internal/index.d.ts +74 -77
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +197 -202
- package/dist/internal/index.js.map +1 -1
- package/dist/json/index.d.ts +9 -17
- package/dist/json/index.d.ts.map +1 -1
- package/dist/json/index.js +3 -33
- package/dist/json/index.js.map +1 -1
- package/dist/main/index.d.ts +689 -795
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +55 -23
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js +10 -10
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime/index.d.ts +4 -4
- package/dist/realtime/index.d.ts.map +1 -1
- package/dist/realtime/index.js +5 -11
- package/dist/realtime/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +2 -2
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +10 -10
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +2 -2
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +18 -18
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js +13 -19
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +1 -1
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +7 -7
- package/src/eslint-plugin/index.ts +0 -1
- package/src/eslint-plugin/rules/explicit-state-types.ts +8 -1
- package/src/eslint-plugin/rules/index.ts +0 -1
- package/src/internal/atom/create-regular-atom.ts +1 -0
- package/src/internal/atom/dispose-atom.ts +1 -0
- package/src/internal/atom/index.ts +0 -1
- package/src/internal/families/find-in-store.ts +4 -5
- package/src/internal/families/get-family-of-token.ts +4 -5
- package/src/internal/families/index.ts +0 -1
- package/src/internal/families/init-family-member.ts +3 -4
- package/src/internal/families/seek-in-store.ts +4 -5
- package/src/internal/get-state/read-or-compute-value.ts +14 -2
- package/src/internal/index.ts +116 -96
- package/src/internal/ingest-updates/ingest-creation-disposal.ts +18 -15
- package/src/internal/ingest-updates/ingest-selector-update.ts +9 -5
- package/src/internal/join/get-internal-relations-from-store.ts +2 -2
- package/src/internal/join/join-internal.ts +6 -18
- package/src/internal/molecule.ts +1 -0
- package/src/internal/mutable/create-mutable-atom-family.ts +37 -21
- package/src/internal/mutable/create-mutable-atom.ts +17 -13
- package/src/internal/mutable/get-json-family.ts +7 -6
- package/src/internal/mutable/get-json-token.ts +6 -13
- package/src/internal/mutable/get-update-family.ts +7 -8
- package/src/internal/mutable/get-update-token.ts +5 -9
- package/src/internal/mutable/tracker-family.ts +10 -13
- package/src/internal/mutable/tracker.ts +66 -90
- package/src/internal/mutable/transceiver.ts +35 -8
- package/src/internal/selector/dispose-selector.ts +9 -9
- package/src/internal/selector/register-selector.ts +2 -2
- package/src/internal/set-state/copy-mutable-if-needed.ts +8 -6
- package/src/internal/set-state/reset-atom-or-selector.ts +11 -4
- package/src/internal/set-state/set-atom.ts +1 -1
- package/src/internal/store/counterfeit.ts +3 -4
- package/src/internal/store/deposit.ts +7 -9
- package/src/internal/store/store.ts +2 -2
- package/src/internal/store/withdraw.ts +7 -11
- package/src/json/entries.ts +7 -7
- package/src/json/index.ts +0 -2
- package/src/main/atom.ts +68 -127
- package/src/main/dispose-state.ts +4 -6
- package/src/main/find-state.ts +6 -13
- package/src/main/get-state.ts +0 -2
- package/src/main/index.ts +1 -176
- package/src/main/join.ts +2 -9
- package/src/main/logger.ts +7 -7
- package/src/main/reset-state.ts +0 -2
- package/src/main/selector.ts +5 -72
- package/src/main/set-state.ts +1 -4
- package/src/main/silo.ts +14 -5
- package/src/main/subscribe.ts +0 -7
- package/src/main/timeline.ts +1 -18
- package/src/main/tokens.ts +245 -0
- package/src/main/transaction.ts +28 -60
- package/src/main/validators.ts +2 -2
- package/src/react/use-json.ts +15 -25
- package/src/react-devtools/store.ts +61 -45
- package/src/realtime/shared-room-store.ts +12 -25
- package/src/realtime-client/pull-mutable-atom-family-member.ts +5 -9
- package/src/realtime-client/pull-mutable-atom.ts +5 -9
- package/src/realtime-react/use-pull-mutable-atom.ts +3 -5
- package/src/realtime-react/use-pull-mutable-family-member.ts +3 -4
- package/src/realtime-server/realtime-mutable-family-provider.ts +3 -4
- package/src/realtime-server/realtime-mutable-provider.ts +2 -3
- package/src/realtime-server/realtime-server-stores/server-room-external-actions.ts +6 -5
- package/src/realtime-server/realtime-server-stores/server-user-store.ts +9 -18
- package/src/transceivers/set-rtx/set-rtx.ts +1 -1
- package/src/eslint-plugin/rules/synchronous-selector-dependencies.ts +0 -140
- package/src/eslint-plugin/walk.ts +0 -81
- package/src/internal/atom/create-standalone-atom.ts +0 -39
- package/src/internal/families/create-atom-family.ts +0 -38
- package/src/json/select-json-family.ts +0 -55
- package/src/json/select-json.ts +0 -19
package/dist/internal/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Join as Join$1, arbitrary as arbitrary$1, subscribeToState as subscribeToState$1, subscribeToTimeline as subscribeToTimeline$1, subscribeToTransaction as subscribeToTransaction$1 } from "atom.io/internal";
|
|
2
|
-
import { parseJson,
|
|
2
|
+
import { parseJson, stringifyJson } from "atom.io/json";
|
|
3
3
|
import { Anarchy, AtomIOLogger } from "atom.io";
|
|
4
4
|
import { SetRTX } from "atom.io/transceivers/set-rtx";
|
|
5
5
|
|
|
@@ -456,16 +456,16 @@ var Future = class extends Promise {
|
|
|
456
456
|
|
|
457
457
|
//#endregion
|
|
458
458
|
//#region src/internal/set-state/copy-mutable-if-needed.ts
|
|
459
|
-
function copyMutableIfNeeded(target, atom
|
|
460
|
-
const originValue = origin.valueMap.get(atom
|
|
461
|
-
const targetValue = target.valueMap.get(atom
|
|
459
|
+
function copyMutableIfNeeded(target, atom, origin) {
|
|
460
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
461
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
462
462
|
if (originValue !== targetValue) return targetValue;
|
|
463
|
-
if (originValue === void 0) return atom
|
|
464
|
-
origin.logger.info(`📃`, `atom`, atom
|
|
465
|
-
const jsonValue =
|
|
466
|
-
const copiedValue = atom
|
|
467
|
-
target.valueMap.set(atom
|
|
468
|
-
new Tracker(atom
|
|
463
|
+
if (originValue === void 0) return new atom.class();
|
|
464
|
+
origin.logger.info(`📃`, `atom`, atom.key, `copying`);
|
|
465
|
+
const jsonValue = originValue.toJSON();
|
|
466
|
+
const copiedValue = atom.class.fromJSON(jsonValue);
|
|
467
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
468
|
+
new Tracker(atom, origin);
|
|
469
469
|
return copiedValue;
|
|
470
470
|
}
|
|
471
471
|
|
|
@@ -517,12 +517,12 @@ const markDone = (store, key) => {
|
|
|
517
517
|
|
|
518
518
|
//#endregion
|
|
519
519
|
//#region src/internal/set-state/evict-downstream.ts
|
|
520
|
-
function evictDownStream(store, atom
|
|
520
|
+
function evictDownStream(store, atom) {
|
|
521
521
|
const target = newest(store);
|
|
522
|
-
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom
|
|
523
|
-
target.logger.info(`🧹`, atom
|
|
522
|
+
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
|
|
523
|
+
target.logger.info(`🧹`, atom.type, atom.key, downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`, downstreamKeys ?? `to evict`);
|
|
524
524
|
if (downstreamKeys) {
|
|
525
|
-
if (target.operation.open) target.logger.info(`🧹`, atom
|
|
525
|
+
if (target.operation.open) target.logger.info(`🧹`, atom.type, atom.key, `[ ${[...target.operation.done].join(`, `)} ] already done`);
|
|
526
526
|
for (const key of downstreamKeys) {
|
|
527
527
|
if (isDone(target, key)) continue;
|
|
528
528
|
evictCachedValue(target, key);
|
|
@@ -560,10 +560,10 @@ function cacheValue(target, key, value, subject) {
|
|
|
560
560
|
const current = target.valueMap.get(key);
|
|
561
561
|
if (current === future) {
|
|
562
562
|
cacheValue(target, key, resolved, subject);
|
|
563
|
-
const atom
|
|
564
|
-
if (atom
|
|
565
|
-
openOperation(target, atom
|
|
566
|
-
evictDownStream(target, atom
|
|
563
|
+
const atom = target.atoms.get(key);
|
|
564
|
+
if (atom) {
|
|
565
|
+
openOperation(target, atom);
|
|
566
|
+
evictDownStream(target, atom);
|
|
567
567
|
closeOperation(target);
|
|
568
568
|
} else {
|
|
569
569
|
const selector = target.writableSelectors.get(key) ?? target.readonlySelectors.get(key);
|
|
@@ -619,8 +619,7 @@ const readOrComputeValue = (target, state) => {
|
|
|
619
619
|
case `writable_pure_selector`:
|
|
620
620
|
target.logger.info(`🧮`, state.type, state.key, `computing value`);
|
|
621
621
|
return state.get();
|
|
622
|
-
case `atom`:
|
|
623
|
-
case `mutable_atom`: {
|
|
622
|
+
case `atom`: {
|
|
624
623
|
const def = state.default;
|
|
625
624
|
let defaultValue;
|
|
626
625
|
if (def instanceof Function) defaultValue = def();
|
|
@@ -629,14 +628,21 @@ const readOrComputeValue = (target, state) => {
|
|
|
629
628
|
target.logger.info(`💁`, `atom`, state.key, `could not find cached value; using default`, defaultValue);
|
|
630
629
|
return cachedValue;
|
|
631
630
|
}
|
|
631
|
+
case `mutable_atom`: {
|
|
632
|
+
const Ctor = state.class;
|
|
633
|
+
const instance = new Ctor();
|
|
634
|
+
const cachedValue = cacheValue(target, state.key, instance, state.subject);
|
|
635
|
+
target.logger.info(`💁`, `mutable_atom`, state.key, `could not find cached value; using default`, instance);
|
|
636
|
+
return cachedValue;
|
|
637
|
+
}
|
|
632
638
|
}
|
|
633
639
|
};
|
|
634
640
|
|
|
635
641
|
//#endregion
|
|
636
642
|
//#region src/internal/subscribe/subscribe-to-root-atoms.ts
|
|
637
|
-
const subscribeToRootDependency = (target, selector, atom
|
|
638
|
-
return atom
|
|
639
|
-
target.logger.info(`📢`, selector.type, selector.key, `root`, atom
|
|
643
|
+
const subscribeToRootDependency = (target, selector, atom) => {
|
|
644
|
+
return atom.subject.subscribe(`${selector.type}:${selector.key}`, (atomChange) => {
|
|
645
|
+
target.logger.info(`📢`, selector.type, selector.key, `root`, atom.key, `went`, atomChange.oldValue, `->`, atomChange.newValue);
|
|
640
646
|
const oldValue = recallState(target, selector);
|
|
641
647
|
const newValue = readOrComputeValue(target, selector);
|
|
642
648
|
target.logger.info(`✨`, selector.type, selector.key, `went`, oldValue, `->`, newValue);
|
|
@@ -647,55 +653,6 @@ const subscribeToRootDependency = (target, selector, atom$1) => {
|
|
|
647
653
|
});
|
|
648
654
|
};
|
|
649
655
|
|
|
650
|
-
//#endregion
|
|
651
|
-
//#region src/internal/families/create-regular-atom-family.ts
|
|
652
|
-
function createRegularAtomFamily(store, options, internalRoles) {
|
|
653
|
-
const familyToken = {
|
|
654
|
-
key: options.key,
|
|
655
|
-
type: `atom_family`
|
|
656
|
-
};
|
|
657
|
-
const existing = store.families.get(options.key);
|
|
658
|
-
if (existing) store.logger.error(`❗`, `atom_family`, options.key, `Overwriting an existing ${prettyPrintTokenType(existing)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);
|
|
659
|
-
const subject = new Subject();
|
|
660
|
-
const familyFunction = (key) => {
|
|
661
|
-
const subKey = stringifyJson(key);
|
|
662
|
-
const family = {
|
|
663
|
-
key: options.key,
|
|
664
|
-
subKey
|
|
665
|
-
};
|
|
666
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
667
|
-
const target = newest(store);
|
|
668
|
-
const def = options.default;
|
|
669
|
-
const individualOptions = {
|
|
670
|
-
key: fullKey,
|
|
671
|
-
default: def instanceof Function ? () => def(key) : def
|
|
672
|
-
};
|
|
673
|
-
if (options.effects) individualOptions.effects = options.effects(key);
|
|
674
|
-
const token = createRegularAtom(target, individualOptions, family);
|
|
675
|
-
subject.next({
|
|
676
|
-
type: `state_creation`,
|
|
677
|
-
token
|
|
678
|
-
});
|
|
679
|
-
return token;
|
|
680
|
-
};
|
|
681
|
-
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
682
|
-
subject,
|
|
683
|
-
install: (s) => createRegularAtomFamily(s, options),
|
|
684
|
-
internalRoles
|
|
685
|
-
});
|
|
686
|
-
store.families.set(options.key, atomFamily$1);
|
|
687
|
-
store.defaults.set(options.key, options.default);
|
|
688
|
-
return familyToken;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
//#endregion
|
|
692
|
-
//#region src/internal/families/create-atom-family.ts
|
|
693
|
-
function createAtomFamily(store, options) {
|
|
694
|
-
const isMutable = `mutable` in options;
|
|
695
|
-
if (isMutable) return createMutableAtomFamily(store, options);
|
|
696
|
-
return createRegularAtomFamily(store, options);
|
|
697
|
-
}
|
|
698
|
-
|
|
699
656
|
//#endregion
|
|
700
657
|
//#region src/internal/set-state/become.ts
|
|
701
658
|
const become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(originalThing) : nextVersionOfThing;
|
|
@@ -718,58 +675,65 @@ const emitUpdate = (store, state, update) => {
|
|
|
718
675
|
|
|
719
676
|
//#endregion
|
|
720
677
|
//#region src/internal/set-state/set-atom.ts
|
|
721
|
-
const setAtom = (target, atom
|
|
722
|
-
const oldValue = readOrComputeValue(target, atom
|
|
678
|
+
const setAtom = (target, atom, next) => {
|
|
679
|
+
const oldValue = readOrComputeValue(target, atom);
|
|
723
680
|
let newValue = oldValue;
|
|
724
|
-
if (atom
|
|
681
|
+
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
725
682
|
const { parent } = target;
|
|
726
|
-
const copiedValue = copyMutableIfNeeded(target, atom
|
|
683
|
+
const copiedValue = copyMutableIfNeeded(target, atom, parent);
|
|
727
684
|
newValue = copiedValue;
|
|
728
685
|
}
|
|
729
686
|
newValue = become(next)(newValue);
|
|
730
|
-
target.logger.info(`📝`, `atom`, atom
|
|
731
|
-
newValue = cacheValue(target, atom
|
|
732
|
-
markDone(target, atom
|
|
733
|
-
evictDownStream(target, atom
|
|
687
|
+
target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue);
|
|
688
|
+
newValue = cacheValue(target, atom.key, newValue, atom.subject);
|
|
689
|
+
markDone(target, atom.key);
|
|
690
|
+
evictDownStream(target, atom);
|
|
734
691
|
const update = {
|
|
735
692
|
oldValue,
|
|
736
693
|
newValue
|
|
737
694
|
};
|
|
738
695
|
if (!isChildStore(target)) {
|
|
739
|
-
emitUpdate(target, atom
|
|
696
|
+
emitUpdate(target, atom, update);
|
|
740
697
|
return;
|
|
741
698
|
}
|
|
742
699
|
if (target.on.transactionApplying.state === null) {
|
|
743
|
-
const { key } = atom
|
|
700
|
+
const { key } = atom;
|
|
744
701
|
if (isTransceiver(update.newValue)) return;
|
|
745
702
|
const atomUpdate = {
|
|
746
703
|
type: `atom_update`,
|
|
747
704
|
key,
|
|
748
705
|
...update
|
|
749
706
|
};
|
|
750
|
-
if (atom
|
|
707
|
+
if (atom.family) atomUpdate.family = atom.family;
|
|
751
708
|
target.transactionMeta.update.updates.push(atomUpdate);
|
|
752
709
|
target.logger.info(`📁`, `atom`, key, `stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
753
|
-
} else if (atom
|
|
754
|
-
const mutableKey = atom
|
|
755
|
-
const mutableAtom = target.atoms.get(mutableKey);
|
|
710
|
+
} else if (atom.key.startsWith(`*`)) {
|
|
711
|
+
const mutableKey = atom.key.slice(1);
|
|
712
|
+
const mutableAtom$1 = target.atoms.get(mutableKey);
|
|
756
713
|
let transceiver = target.valueMap.get(mutableKey);
|
|
757
|
-
if (mutableAtom.type === `mutable_atom` && isChildStore(target)) {
|
|
714
|
+
if (mutableAtom$1.type === `mutable_atom` && isChildStore(target)) {
|
|
758
715
|
const { parent } = target;
|
|
759
|
-
const copiedValue = copyMutableIfNeeded(target, mutableAtom, parent);
|
|
716
|
+
const copiedValue = copyMutableIfNeeded(target, mutableAtom$1, parent);
|
|
760
717
|
transceiver = copiedValue;
|
|
761
718
|
}
|
|
762
719
|
const accepted = transceiver.do(update.newValue) === null;
|
|
763
|
-
if (accepted) evictDownStream(target, mutableAtom);
|
|
720
|
+
if (accepted) evictDownStream(target, mutableAtom$1);
|
|
764
721
|
}
|
|
765
722
|
};
|
|
766
723
|
|
|
767
724
|
//#endregion
|
|
768
725
|
//#region src/internal/set-state/reset-atom-or-selector.ts
|
|
769
726
|
function resetAtom(store, state) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
727
|
+
switch (state.type) {
|
|
728
|
+
case `mutable_atom`:
|
|
729
|
+
setAtom(store, state, new state.class());
|
|
730
|
+
return;
|
|
731
|
+
case `atom`: {
|
|
732
|
+
let def = state.default;
|
|
733
|
+
if (def instanceof Function) def = def();
|
|
734
|
+
setAtom(store, state, def);
|
|
735
|
+
}
|
|
736
|
+
}
|
|
773
737
|
}
|
|
774
738
|
function resetAtomOrSelector(store, state) {
|
|
775
739
|
switch (state.type) {
|
|
@@ -781,7 +745,7 @@ function resetAtomOrSelector(store, state) {
|
|
|
781
745
|
case `writable_held_selector`:
|
|
782
746
|
{
|
|
783
747
|
const atoms = traceRootSelectorAtoms(store, state.key);
|
|
784
|
-
for (const atom
|
|
748
|
+
for (const atom of atoms.values()) resetAtom(store, atom);
|
|
785
749
|
}
|
|
786
750
|
break;
|
|
787
751
|
}
|
|
@@ -914,8 +878,8 @@ const traceRootSelectorAtoms = (store, selectorKey, covered = /* @__PURE__ */ ne
|
|
|
914
878
|
if (covered.has(dependencyKey)) continue;
|
|
915
879
|
covered.add(dependencyKey);
|
|
916
880
|
if (isAtomKey(store, dependencyKey)) {
|
|
917
|
-
const atom
|
|
918
|
-
roots.set(atom
|
|
881
|
+
const atom = store.atoms.get(dependencyKey);
|
|
882
|
+
roots.set(atom.key, atom);
|
|
919
883
|
} else dependencies.push(...getSelectorDependencyKeys(store, dependencyKey));
|
|
920
884
|
}
|
|
921
885
|
return roots;
|
|
@@ -1259,6 +1223,7 @@ function claimWithinStore(store, newProvenance, claim, exclusive) {
|
|
|
1259
1223
|
const transferEvent = {
|
|
1260
1224
|
type: `molecule_transfer`,
|
|
1261
1225
|
key: molecule.key,
|
|
1226
|
+
exclusive: Boolean(exclusive),
|
|
1262
1227
|
from: priorProvenance,
|
|
1263
1228
|
to: [newProvenanceMolecule.key]
|
|
1264
1229
|
};
|
|
@@ -1331,15 +1296,15 @@ function ingestMoleculeDisposalEvent(update, applying, store) {
|
|
|
1331
1296
|
function ingestMoleculeTransferEvent(update, applying, store) {
|
|
1332
1297
|
switch (applying) {
|
|
1333
1298
|
case `newValue`:
|
|
1334
|
-
|
|
1335
|
-
const provenance = update.to.length === 1 ? update.to[0] : update.to;
|
|
1336
|
-
claimWithinStore(store, provenance, update.key, `exclusive`);
|
|
1337
|
-
}
|
|
1299
|
+
for (const newOwner of update.to) claimWithinStore(store, newOwner, update.key, update.exclusive ? `exclusive` : void 0);
|
|
1338
1300
|
break;
|
|
1339
1301
|
case `oldValue`:
|
|
1340
1302
|
{
|
|
1341
|
-
|
|
1342
|
-
|
|
1303
|
+
let exclusivity = `exclusive`;
|
|
1304
|
+
for (const previousOwner of update.from) {
|
|
1305
|
+
claimWithinStore(store, previousOwner, update.key, exclusivity);
|
|
1306
|
+
exclusivity = void 0;
|
|
1307
|
+
}
|
|
1343
1308
|
}
|
|
1344
1309
|
break;
|
|
1345
1310
|
}
|
|
@@ -1348,7 +1313,9 @@ function ingestMoleculeTransferEvent(update, applying, store) {
|
|
|
1348
1313
|
//#endregion
|
|
1349
1314
|
//#region src/internal/ingest-updates/ingest-selector-update.ts
|
|
1350
1315
|
function ingestSelectorUpdate(applying, selectorUpdate, store) {
|
|
1351
|
-
|
|
1316
|
+
let updates;
|
|
1317
|
+
if (applying === `newValue`) updates = selectorUpdate.atomUpdates;
|
|
1318
|
+
else updates = selectorUpdate.atomUpdates.toReversed();
|
|
1352
1319
|
for (const atomUpdate of updates) ingestAtomUpdate(applying, atomUpdate, store);
|
|
1353
1320
|
}
|
|
1354
1321
|
|
|
@@ -1742,19 +1709,18 @@ function createStandaloneSelector(store, options) {
|
|
|
1742
1709
|
//#region src/internal/selector/dispose-selector.ts
|
|
1743
1710
|
function disposeSelector(store, selectorToken) {
|
|
1744
1711
|
const target = newest(store);
|
|
1745
|
-
const { key, type } = selectorToken;
|
|
1746
|
-
|
|
1747
|
-
if (!selector.family) store.logger.error(`❌`, type, key, `Standalone selectors cannot be disposed.`);
|
|
1712
|
+
const { key, type, family: familyMeta } = selectorToken;
|
|
1713
|
+
if (!familyMeta) store.logger.error(`❌`, type, key, `Standalone selectors cannot be disposed.`);
|
|
1748
1714
|
else {
|
|
1749
|
-
const molecule = target.molecules.get(
|
|
1750
|
-
if (molecule) target.moleculeData.delete(
|
|
1715
|
+
const molecule = target.molecules.get(familyMeta.subKey);
|
|
1716
|
+
if (molecule) target.moleculeData.delete(familyMeta.subKey, familyMeta.key);
|
|
1751
1717
|
let familyToken;
|
|
1752
1718
|
switch (selectorToken.type) {
|
|
1753
1719
|
case `writable_held_selector`:
|
|
1754
1720
|
{
|
|
1755
1721
|
target.writableSelectors.delete(key);
|
|
1756
1722
|
familyToken = {
|
|
1757
|
-
key:
|
|
1723
|
+
key: familyMeta.key,
|
|
1758
1724
|
type: `writable_held_selector_family`
|
|
1759
1725
|
};
|
|
1760
1726
|
const family = withdraw(store, familyToken);
|
|
@@ -1769,7 +1735,7 @@ function disposeSelector(store, selectorToken) {
|
|
|
1769
1735
|
{
|
|
1770
1736
|
target.writableSelectors.delete(key);
|
|
1771
1737
|
familyToken = {
|
|
1772
|
-
key:
|
|
1738
|
+
key: familyMeta.key,
|
|
1773
1739
|
type: `writable_pure_selector_family`
|
|
1774
1740
|
};
|
|
1775
1741
|
const family = withdraw(store, familyToken);
|
|
@@ -1784,7 +1750,7 @@ function disposeSelector(store, selectorToken) {
|
|
|
1784
1750
|
{
|
|
1785
1751
|
target.readonlySelectors.delete(key);
|
|
1786
1752
|
familyToken = {
|
|
1787
|
-
key:
|
|
1753
|
+
key: familyMeta.key,
|
|
1788
1754
|
type: `readonly_held_selector_family`
|
|
1789
1755
|
};
|
|
1790
1756
|
const family = withdraw(store, familyToken);
|
|
@@ -1799,7 +1765,7 @@ function disposeSelector(store, selectorToken) {
|
|
|
1799
1765
|
{
|
|
1800
1766
|
target.readonlySelectors.delete(key);
|
|
1801
1767
|
familyToken = {
|
|
1802
|
-
key:
|
|
1768
|
+
key: familyMeta.key,
|
|
1803
1769
|
type: `readonly_pure_selector_family`
|
|
1804
1770
|
};
|
|
1805
1771
|
const family = withdraw(store, familyToken);
|
|
@@ -1814,6 +1780,7 @@ function disposeSelector(store, selectorToken) {
|
|
|
1814
1780
|
target.valueMap.delete(key);
|
|
1815
1781
|
target.selectorAtoms.delete(key);
|
|
1816
1782
|
target.selectorGraph.delete(key);
|
|
1783
|
+
target.moleculeData.delete(familyMeta.key, familyMeta.subKey);
|
|
1817
1784
|
store.logger.info(`🔥`, selectorToken.type, key, `deleted`);
|
|
1818
1785
|
if (isChildStore(target) && target.transactionMeta.phase === `building`) target.transactionMeta.update.updates.push({
|
|
1819
1786
|
type: `state_disposal`,
|
|
@@ -1871,6 +1838,47 @@ function createReadonlyPureSelectorFamily(store, options, internalRoles) {
|
|
|
1871
1838
|
return familyToken;
|
|
1872
1839
|
}
|
|
1873
1840
|
|
|
1841
|
+
//#endregion
|
|
1842
|
+
//#region src/internal/families/create-regular-atom-family.ts
|
|
1843
|
+
function createRegularAtomFamily(store, options, internalRoles) {
|
|
1844
|
+
const familyToken = {
|
|
1845
|
+
key: options.key,
|
|
1846
|
+
type: `atom_family`
|
|
1847
|
+
};
|
|
1848
|
+
const existing = store.families.get(options.key);
|
|
1849
|
+
if (existing) store.logger.error(`❗`, `atom_family`, options.key, `Overwriting an existing ${prettyPrintTokenType(existing)} "${existing.key}" in store "${store.config.name}". You can safely ignore this warning if it is due to hot module replacement.`);
|
|
1850
|
+
const subject = new Subject();
|
|
1851
|
+
const familyFunction = (key) => {
|
|
1852
|
+
const subKey = stringifyJson(key);
|
|
1853
|
+
const family = {
|
|
1854
|
+
key: options.key,
|
|
1855
|
+
subKey
|
|
1856
|
+
};
|
|
1857
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
1858
|
+
const target = newest(store);
|
|
1859
|
+
const def = options.default;
|
|
1860
|
+
const individualOptions = {
|
|
1861
|
+
key: fullKey,
|
|
1862
|
+
default: def instanceof Function ? () => def(key) : def
|
|
1863
|
+
};
|
|
1864
|
+
if (options.effects) individualOptions.effects = options.effects(key);
|
|
1865
|
+
const token = createRegularAtom(target, individualOptions, family);
|
|
1866
|
+
subject.next({
|
|
1867
|
+
type: `state_creation`,
|
|
1868
|
+
token
|
|
1869
|
+
});
|
|
1870
|
+
return token;
|
|
1871
|
+
};
|
|
1872
|
+
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
1873
|
+
subject,
|
|
1874
|
+
install: (s) => createRegularAtomFamily(s, options),
|
|
1875
|
+
internalRoles
|
|
1876
|
+
});
|
|
1877
|
+
store.families.set(options.key, atomFamily$1);
|
|
1878
|
+
store.defaults.set(options.key, options.default);
|
|
1879
|
+
return familyToken;
|
|
1880
|
+
}
|
|
1881
|
+
|
|
1874
1882
|
//#endregion
|
|
1875
1883
|
//#region src/internal/families/create-readonly-held-selector-family.ts
|
|
1876
1884
|
function createReadonlyHeldSelectorFamily(store, options, internalRoles) {
|
|
@@ -2169,7 +2177,7 @@ function subscribeToState(store, token, key, handleUpdate) {
|
|
|
2169
2177
|
let updateHandler = safelyHandleUpdate;
|
|
2170
2178
|
if (isSelector) {
|
|
2171
2179
|
readOrComputeValue(store, state);
|
|
2172
|
-
for (const [atomKey, atom
|
|
2180
|
+
for (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) rootSubs.set(atomKey, subscribeToRootDependency(store, state, atom));
|
|
2173
2181
|
updateHandler = function updateRootsBeforeHandlingUpdate(update) {
|
|
2174
2182
|
const dependencies = traceRootSelectorAtoms(store, state.key);
|
|
2175
2183
|
for (const [previousRootKey, unsub] of rootSubs) {
|
|
@@ -2180,7 +2188,7 @@ function subscribeToState(store, token, key, handleUpdate) {
|
|
|
2180
2188
|
rootSubs.delete(previousRootKey);
|
|
2181
2189
|
}
|
|
2182
2190
|
}
|
|
2183
|
-
for (const [atomKey, atom
|
|
2191
|
+
for (const [atomKey, atom] of dependencies) rootSubs.set(atomKey, subscribeToRootDependency(store, state, atom));
|
|
2184
2192
|
safelyHandleUpdate(update);
|
|
2185
2193
|
};
|
|
2186
2194
|
}
|
|
@@ -2245,66 +2253,60 @@ var Tracker = class {
|
|
|
2245
2253
|
}
|
|
2246
2254
|
unsubscribeFromInnerValue;
|
|
2247
2255
|
unsubscribeFromState;
|
|
2248
|
-
|
|
2256
|
+
captureSignalsFromCore(mutableState, latestUpdateState, target) {
|
|
2249
2257
|
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
2250
|
-
const
|
|
2251
|
-
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(subscriptionKey, (update) => {
|
|
2258
|
+
const trackerCapturesOutboundSignal = (update) => {
|
|
2252
2259
|
setIntoStore(target, latestUpdateState, update);
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2260
|
+
};
|
|
2261
|
+
const originalInnerValue = getFromStore(target, mutableState);
|
|
2262
|
+
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(subscriptionKey, trackerCapturesOutboundSignal);
|
|
2263
|
+
this.unsubscribeFromState = subscribeToState(target, mutableState, subscriptionKey, function trackerLooksForNewReference(update) {
|
|
2255
2264
|
if (update.newValue !== update.oldValue) {
|
|
2256
2265
|
this.unsubscribeFromInnerValue();
|
|
2257
|
-
this.unsubscribeFromInnerValue = update.newValue.subscribe(subscriptionKey,
|
|
2258
|
-
setIntoStore(target, latestUpdateState, transceiverUpdate);
|
|
2259
|
-
});
|
|
2266
|
+
this.unsubscribeFromInnerValue = update.newValue.subscribe(subscriptionKey, trackerCapturesOutboundSignal);
|
|
2260
2267
|
}
|
|
2261
|
-
});
|
|
2268
|
+
}.bind(this));
|
|
2262
2269
|
}
|
|
2263
|
-
|
|
2270
|
+
supplySignalsToCore(mutableState, latestUpdateState, target) {
|
|
2264
2271
|
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
2265
|
-
subscribeToState(target, latestUpdateState, subscriptionKey, ({ newValue, oldValue })
|
|
2272
|
+
subscribeToState(target, latestUpdateState, subscriptionKey, function trackerCapturesInboundSignal({ newValue, oldValue }) {
|
|
2266
2273
|
const timelineId = target.timelineTopics.getRelatedKey(latestUpdateState.key);
|
|
2267
|
-
if (timelineId) {
|
|
2268
|
-
const
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
else if (update === `undo` && oldValue) transceiver.undo(oldValue);
|
|
2278
|
-
return transceiver;
|
|
2279
|
-
});
|
|
2274
|
+
if (timelineId && target.timelines.get(timelineId)?.timeTraveling) {
|
|
2275
|
+
const unsubscribe = subscribeToTimeline(target, {
|
|
2276
|
+
key: timelineId,
|
|
2277
|
+
type: `timeline`
|
|
2278
|
+
}, subscriptionKey, function trackerWaitsForTimeTravelToFinish(update) {
|
|
2279
|
+
unsubscribe();
|
|
2280
|
+
setIntoStore(target, mutableState, (transceiver) => {
|
|
2281
|
+
if (update === `redo` && newValue) transceiver.do(newValue);
|
|
2282
|
+
else if (update === `undo` && oldValue) transceiver.undo(oldValue);
|
|
2283
|
+
return transceiver;
|
|
2280
2284
|
});
|
|
2281
|
-
|
|
2282
|
-
|
|
2285
|
+
});
|
|
2286
|
+
return;
|
|
2283
2287
|
}
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
if (newValue && eventOffset === 1) setIntoStore(target, mutableState, (transceiver) => (transceiver.do(newValue), transceiver));
|
|
2290
|
-
else target.logger.info(`❌`, `mutable_atom`, mutableState.key, `could not be updated. Expected update number ${mutable.cacheUpdateNumber + 1}, but got ${updateNumber}`);
|
|
2291
|
-
});
|
|
2288
|
+
const mutable = getFromStore(target, mutableState);
|
|
2289
|
+
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
2290
|
+
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
2291
|
+
if (newValue && eventOffset === 1) setIntoStore(target, mutableState, (transceiver) => (transceiver.do(newValue), transceiver));
|
|
2292
|
+
else target.logger.info(`❌`, `mutable_atom`, mutableState.key, `could not be updated. Expected update number ${mutable.cacheUpdateNumber + 1}, but got ${updateNumber}`);
|
|
2292
2293
|
});
|
|
2293
2294
|
}
|
|
2294
|
-
|
|
2295
|
-
|
|
2295
|
+
mutableAtomToken;
|
|
2296
|
+
latestSignalToken;
|
|
2296
2297
|
[Symbol.dispose];
|
|
2297
|
-
constructor(
|
|
2298
|
-
this.mutableState = mutableState;
|
|
2298
|
+
constructor(mutableAtomToken, store) {
|
|
2299
2299
|
const target = newest(store);
|
|
2300
|
-
|
|
2301
|
-
this.
|
|
2302
|
-
this.
|
|
2303
|
-
|
|
2300
|
+
const latestSignalToken = this.initializeState(mutableAtomToken, target);
|
|
2301
|
+
this.mutableAtomToken = mutableAtomToken;
|
|
2302
|
+
this.latestSignalToken = latestSignalToken;
|
|
2303
|
+
this.captureSignalsFromCore(mutableAtomToken, latestSignalToken, target);
|
|
2304
|
+
this.supplySignalsToCore(mutableAtomToken, latestSignalToken, target);
|
|
2305
|
+
target.trackers.set(mutableAtomToken.key, this);
|
|
2304
2306
|
this[Symbol.dispose] = () => {
|
|
2305
2307
|
this.unsubscribeFromInnerValue();
|
|
2306
2308
|
this.unsubscribeFromState();
|
|
2307
|
-
target.trackers.delete(
|
|
2309
|
+
target.trackers.delete(mutableAtomToken.key);
|
|
2308
2310
|
};
|
|
2309
2311
|
}
|
|
2310
2312
|
};
|
|
@@ -2355,7 +2357,14 @@ function createMutableAtom(store, options, family) {
|
|
|
2355
2357
|
};
|
|
2356
2358
|
}
|
|
2357
2359
|
new Tracker(token, store);
|
|
2358
|
-
if (!family)
|
|
2360
|
+
if (!family) createStandaloneSelector(store, {
|
|
2361
|
+
key: `${key}:JSON`,
|
|
2362
|
+
get: ({ get }) => get(token).toJSON(),
|
|
2363
|
+
set: ({ set }, newValue) => {
|
|
2364
|
+
set(token, options.class.fromJSON(newValue));
|
|
2365
|
+
}
|
|
2366
|
+
});
|
|
2367
|
+
store.on.atomCreation.next(token);
|
|
2359
2368
|
return token;
|
|
2360
2369
|
}
|
|
2361
2370
|
|
|
@@ -2415,10 +2424,7 @@ function createMutableAtomFamily(store, options, internalRoles) {
|
|
|
2415
2424
|
const target = newest(store);
|
|
2416
2425
|
const individualOptions = {
|
|
2417
2426
|
key: fullKey,
|
|
2418
|
-
|
|
2419
|
-
toJson: options.toJson,
|
|
2420
|
-
fromJson: options.fromJson,
|
|
2421
|
-
mutable: true
|
|
2427
|
+
class: options.class
|
|
2422
2428
|
};
|
|
2423
2429
|
if (options.effects) individualOptions.effects = options.effects(key);
|
|
2424
2430
|
const token = createMutableAtom(target, individualOptions, family);
|
|
@@ -2431,12 +2437,16 @@ function createMutableAtomFamily(store, options, internalRoles) {
|
|
|
2431
2437
|
const atomFamily$1 = Object.assign(familyFunction, familyToken, {
|
|
2432
2438
|
subject,
|
|
2433
2439
|
install: (s) => createMutableAtomFamily(s, options),
|
|
2434
|
-
toJson: options.toJson,
|
|
2435
|
-
fromJson: options.fromJson,
|
|
2436
2440
|
internalRoles
|
|
2437
2441
|
});
|
|
2438
2442
|
store.families.set(options.key, atomFamily$1);
|
|
2439
|
-
|
|
2443
|
+
createWritablePureSelectorFamily(store, {
|
|
2444
|
+
key: `${options.key}:JSON`,
|
|
2445
|
+
get: (key) => ({ get }) => get(familyToken, key).toJSON(),
|
|
2446
|
+
set: (key) => ({ set }, newValue) => {
|
|
2447
|
+
set(familyToken, key, options.class.fromJSON(newValue));
|
|
2448
|
+
}
|
|
2449
|
+
}, [`mutable`, `json`]);
|
|
2440
2450
|
new FamilyTracker(atomFamily$1, store);
|
|
2441
2451
|
return familyToken;
|
|
2442
2452
|
}
|
|
@@ -2597,12 +2607,12 @@ var Store = class {
|
|
|
2597
2607
|
family.install(this);
|
|
2598
2608
|
}
|
|
2599
2609
|
const mutableHelpers = /* @__PURE__ */ new Set();
|
|
2600
|
-
for (const [, atom
|
|
2601
|
-
if (mutableHelpers.has(atom
|
|
2602
|
-
atom
|
|
2603
|
-
if (atom
|
|
2604
|
-
const originalJsonToken = getJsonToken(store, atom
|
|
2605
|
-
const originalUpdateToken = getUpdateToken(atom
|
|
2610
|
+
for (const [, atom] of store.atoms) {
|
|
2611
|
+
if (mutableHelpers.has(atom.key)) continue;
|
|
2612
|
+
atom.install(this);
|
|
2613
|
+
if (atom.type === `mutable_atom`) {
|
|
2614
|
+
const originalJsonToken = getJsonToken(store, atom);
|
|
2615
|
+
const originalUpdateToken = getUpdateToken(atom);
|
|
2606
2616
|
mutableHelpers.add(originalJsonToken.key);
|
|
2607
2617
|
mutableHelpers.add(originalUpdateToken.key);
|
|
2608
2618
|
}
|
|
@@ -2716,33 +2726,20 @@ function createRegularAtom(store, options, family) {
|
|
|
2716
2726
|
for (const cleanup of cleanupFunctions) cleanup();
|
|
2717
2727
|
};
|
|
2718
2728
|
}
|
|
2729
|
+
store.on.atomCreation.next(token);
|
|
2719
2730
|
return token;
|
|
2720
2731
|
}
|
|
2721
2732
|
|
|
2722
|
-
//#endregion
|
|
2723
|
-
//#region src/internal/atom/create-standalone-atom.ts
|
|
2724
|
-
function createStandaloneAtom(store, options) {
|
|
2725
|
-
const isMutable = `mutable` in options;
|
|
2726
|
-
if (isMutable) {
|
|
2727
|
-
const state$1 = createMutableAtom(store, options, void 0);
|
|
2728
|
-
store.on.atomCreation.next(state$1);
|
|
2729
|
-
return state$1;
|
|
2730
|
-
}
|
|
2731
|
-
const state = createRegularAtom(store, options, void 0);
|
|
2732
|
-
store.on.atomCreation.next(state);
|
|
2733
|
-
return state;
|
|
2734
|
-
}
|
|
2735
|
-
|
|
2736
2733
|
//#endregion
|
|
2737
2734
|
//#region src/internal/atom/dispose-atom.ts
|
|
2738
2735
|
function disposeAtom(store, atomToken) {
|
|
2739
2736
|
const target = newest(store);
|
|
2740
2737
|
const { key, family } = atomToken;
|
|
2741
|
-
const atom
|
|
2738
|
+
const atom = withdraw(target, atomToken);
|
|
2742
2739
|
if (!family) store.logger.error(`❌`, `atom`, key, `Standalone atoms cannot be disposed.`);
|
|
2743
2740
|
else {
|
|
2744
|
-
atom
|
|
2745
|
-
const lastValue = store.valueMap.get(atom
|
|
2741
|
+
atom.cleanup?.();
|
|
2742
|
+
const lastValue = store.valueMap.get(atom.key);
|
|
2746
2743
|
const atomFamily$1 = withdraw(store, {
|
|
2747
2744
|
key: family.key,
|
|
2748
2745
|
type: `atom_family`
|
|
@@ -2759,6 +2756,7 @@ function disposeAtom(store, atomToken) {
|
|
|
2759
2756
|
target.valueMap.delete(key);
|
|
2760
2757
|
target.selectorAtoms.delete(key);
|
|
2761
2758
|
target.atomsThatAreDefault.delete(key);
|
|
2759
|
+
target.moleculeData.delete(family.key, family.subKey);
|
|
2762
2760
|
store.timelineTopics.delete(key);
|
|
2763
2761
|
if (atomToken.type === `mutable_atom`) {
|
|
2764
2762
|
const updateToken = getUpdateToken(atomToken);
|
|
@@ -2769,7 +2767,7 @@ function disposeAtom(store, atomToken) {
|
|
|
2769
2767
|
if (isChild && target.transactionMeta.phase === `building`) {
|
|
2770
2768
|
const mostRecentUpdate = target.transactionMeta.update.updates.at(-1);
|
|
2771
2769
|
const wasMoleculeDisposal = mostRecentUpdate?.type === `molecule_disposal`;
|
|
2772
|
-
const updateAlreadyCaptured = wasMoleculeDisposal && mostRecentUpdate.values.some(([k]) => k === atom
|
|
2770
|
+
const updateAlreadyCaptured = wasMoleculeDisposal && mostRecentUpdate.values.some(([k]) => k === atom.family?.key);
|
|
2773
2771
|
if (!updateAlreadyCaptured) target.transactionMeta.update.updates.push(disposal);
|
|
2774
2772
|
} else store.on.atomDisposal.next(atomToken);
|
|
2775
2773
|
}
|
|
@@ -2854,10 +2852,7 @@ var Join = class {
|
|
|
2854
2852
|
const bSide = options.between[1];
|
|
2855
2853
|
const relatedKeysAtoms = createMutableAtomFamily(store, {
|
|
2856
2854
|
key: `${options.key}/relatedKeys`,
|
|
2857
|
-
|
|
2858
|
-
mutable: true,
|
|
2859
|
-
fromJson: (json) => SetRTX.fromJSON(json),
|
|
2860
|
-
toJson: (set) => set.toJSON()
|
|
2855
|
+
class: SetRTX
|
|
2861
2856
|
}, [`join`, `relations`]);
|
|
2862
2857
|
this.core = { relatedKeysAtoms };
|
|
2863
2858
|
const getRelatedKeys = ({ get }, key) => get(relatedKeysAtoms, key);
|
|
@@ -3340,12 +3335,12 @@ function addAtomToTimeline(store, atomToken, tl) {
|
|
|
3340
3335
|
const updateToken = getUpdateToken(maybeAtom);
|
|
3341
3336
|
maybeAtom = withdraw(store, updateToken);
|
|
3342
3337
|
}
|
|
3343
|
-
const atom
|
|
3338
|
+
const atom = maybeAtom;
|
|
3344
3339
|
store.timelineTopics.set({
|
|
3345
|
-
topicKey: atom
|
|
3340
|
+
topicKey: atom.key,
|
|
3346
3341
|
timelineKey: tl.key
|
|
3347
3342
|
}, { topicType: `atom` });
|
|
3348
|
-
tl.subscriptions.set(atom
|
|
3343
|
+
tl.subscriptions.set(atom.key, atom.subject.subscribe(`timeline`, function timelineCapturesAtomUpdate(update) {
|
|
3349
3344
|
const target = newest(store);
|
|
3350
3345
|
const currentSelectorKey = store.operation.open && store.operation.token.type === `writable_pure_selector` ? store.operation.token.key : null;
|
|
3351
3346
|
const currentSelectorTime = store.operation.open && store.operation.token.type === `writable_pure_selector` ? store.operation.time : null;
|
|
@@ -3362,7 +3357,7 @@ function addAtomToTimeline(store, atomToken, tl) {
|
|
|
3362
3357
|
atomUpdates: []
|
|
3363
3358
|
};
|
|
3364
3359
|
latestUpdate.atomUpdates.push({
|
|
3365
|
-
key: atom
|
|
3360
|
+
key: atom.key,
|
|
3366
3361
|
type: `atom_update`,
|
|
3367
3362
|
...update
|
|
3368
3363
|
});
|
|
@@ -3373,7 +3368,7 @@ function addAtomToTimeline(store, atomToken, tl) {
|
|
|
3373
3368
|
tl.selectorTime = currentSelectorTime;
|
|
3374
3369
|
} else if (latestUpdate?.type === `selector_update`) {
|
|
3375
3370
|
latestUpdate.atomUpdates.push({
|
|
3376
|
-
key: atom
|
|
3371
|
+
key: atom.key,
|
|
3377
3372
|
type: `atom_update`,
|
|
3378
3373
|
...update
|
|
3379
3374
|
});
|
|
@@ -3394,13 +3389,13 @@ function addAtomToTimeline(store, atomToken, tl) {
|
|
|
3394
3389
|
const atomUpdate = {
|
|
3395
3390
|
type: `atom_update`,
|
|
3396
3391
|
timestamp,
|
|
3397
|
-
key: atom
|
|
3392
|
+
key: atom.key,
|
|
3398
3393
|
oldValue: update.oldValue,
|
|
3399
3394
|
newValue: update.newValue
|
|
3400
3395
|
};
|
|
3401
|
-
if (atom
|
|
3396
|
+
if (atom.family) atomUpdate.family = atom.family;
|
|
3402
3397
|
const willCapture = tl.shouldCapture?.(atomUpdate, tl) ?? true;
|
|
3403
|
-
store.logger.info(`⌛`, `timeline`, tl.key, `got an atom_update to "${atom
|
|
3398
|
+
store.logger.info(`⌛`, `timeline`, tl.key, `got an atom_update to "${atom.key}"`);
|
|
3404
3399
|
if (willCapture) {
|
|
3405
3400
|
tl.history.push(atomUpdate);
|
|
3406
3401
|
tl.at = tl.history.length;
|
|
@@ -3418,7 +3413,7 @@ function addAtomFamilyToTimeline(store, atomFamilyToken, tl) {
|
|
|
3418
3413
|
tl.subscriptions.set(family.key, family.subject.subscribe(`timeline`, function timelineCapturesStateLifecycleEvent(creationOrDisposal) {
|
|
3419
3414
|
handleStateLifecycleEvent(store, creationOrDisposal, tl);
|
|
3420
3415
|
}));
|
|
3421
|
-
for (const atom
|
|
3416
|
+
for (const atom of store.atoms.values()) if (atom.family?.key === family.key) addAtomToTimeline(store, atom, tl);
|
|
3422
3417
|
}
|
|
3423
3418
|
function joinTransaction(store, tl, txUpdateInProgress) {
|
|
3424
3419
|
const currentTxKey = txUpdateInProgress.key;
|
|
@@ -3552,5 +3547,5 @@ const timeTravel = (store, action, token) => {
|
|
|
3552
3547
|
};
|
|
3553
3548
|
|
|
3554
3549
|
//#endregion
|
|
3555
|
-
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit,
|
|
3550
|
+
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, capitalize, claimWithinStore, clearStore, closeOperation, counterfeit, createJoin, createMutableAtom, createMutableAtomFamily, createReadonlyHeldSelector, createReadonlyPureSelector, createReadonlyPureSelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneSelector, createTimeline, createTransaction, createWritableHeldSelector, createWritablePureSelector, createWritablePureSelectorFamily, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, editRelationsInStore, evictCachedValue, findInStore, findRelationsInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getInternalRelationsFromStore, getJoin, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, installIntoStore, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, resetAtomOrSelector, resetInStore, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootDependency, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceRootSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
3556
3551
|
//# sourceMappingURL=index.js.map
|