atom.io 0.36.0 → 0.36.1
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/internal/index.d.ts +83 -67
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +98 -98
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +5 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +2 -3
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +27 -29
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +8 -9
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- 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.map +1 -1
- package/dist/realtime-client/index.d.ts +7 -8
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- 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 +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +9 -2
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +3 -0
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +3 -3
- package/src/internal/atom/create-regular-atom.ts +5 -5
- package/src/internal/atom/has-role.ts +12 -0
- package/src/internal/atom/index.ts +1 -0
- package/src/internal/caching.ts +38 -16
- package/src/internal/families/find-in-store.ts +1 -1
- package/src/internal/families/get-family-of-token.ts +1 -1
- package/src/internal/families/init-family-member.ts +1 -1
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/read-or-compute-value.ts +29 -20
- package/src/internal/index.ts +8 -8
- package/src/internal/join/join-internal.ts +7 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-json-token.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/get-update-token.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +27 -31
- package/src/internal/mutable/tracker.ts +29 -23
- package/src/internal/mutable/transceiver.ts +11 -10
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
- package/src/internal/selector/create-writable-held-selector.ts +3 -3
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/set-state/set-atom.ts +15 -22
- package/src/internal/set-state/set-into-store.ts +5 -4
- package/src/internal/store/counterfeit.ts +1 -1
- package/src/internal/store/deposit.ts +7 -8
- package/src/internal/store/store.ts +6 -6
- package/src/internal/store/withdraw.ts +8 -8
- package/src/internal/subscribe/subscribe-in-store.ts +2 -2
- package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +3 -3
- package/src/internal/transaction/act-upon-store.ts +2 -2
- package/src/internal/transaction/apply-transaction.ts +2 -2
- package/src/internal/transaction/build-transaction.ts +2 -2
- package/src/internal/transaction/create-transaction.ts +3 -3
- package/src/internal/transaction/index.ts +2 -2
- package/src/internal/transaction/is-root-store.ts +4 -2
- package/src/internal/utility-types.ts +1 -1
- package/src/introspection/attach-introspection-states.ts +3 -3
- package/src/introspection/attach-transaction-index.ts +4 -4
- package/src/introspection/attach-transaction-logs.ts +4 -4
- package/src/introspection/auditor.ts +3 -3
- package/src/main/atom.ts +4 -4
- package/src/main/dispose-state.ts +4 -3
- package/src/main/find-state.ts +1 -1
- package/src/main/get-state.ts +6 -5
- package/src/main/reset-state.ts +3 -3
- package/src/main/set-state.ts +3 -3
- package/src/main/subscribe.ts +3 -3
- package/src/main/tokens.ts +6 -10
- package/src/main/transaction.ts +13 -15
- package/src/react/use-json.ts +5 -5
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
- package/src/realtime-client/pull-mutable-atom.ts +5 -8
- package/src/realtime-client/push-state.ts +6 -5
- package/src/realtime-client/server-action.ts +5 -4
- package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
- package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
- package/src/realtime-react/use-server-action.ts +2 -2
- package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-provider.ts +1 -1
- package/src/transceivers/set-rtx/set-rtx.ts +14 -1
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
package/dist/internal/index.js
CHANGED
|
@@ -454,21 +454,6 @@ var Future = class extends Promise {
|
|
|
454
454
|
}
|
|
455
455
|
};
|
|
456
456
|
|
|
457
|
-
//#endregion
|
|
458
|
-
//#region src/internal/set-state/copy-mutable-if-needed.ts
|
|
459
|
-
function copyMutableIfNeeded(target, atom, origin) {
|
|
460
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
461
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
462
|
-
if (originValue !== targetValue) return targetValue;
|
|
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
|
-
return copiedValue;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
457
|
//#endregion
|
|
473
458
|
//#region src/internal/transaction/is-root-store.ts
|
|
474
459
|
function isRootStore(store) {
|
|
@@ -542,7 +527,7 @@ function evictDownStreamFromSelector(store, selector) {
|
|
|
542
527
|
|
|
543
528
|
//#endregion
|
|
544
529
|
//#region src/internal/caching.ts
|
|
545
|
-
function
|
|
530
|
+
function writeToCache(target, key, value, subject) {
|
|
546
531
|
const currentValue = target.valueMap.get(key);
|
|
547
532
|
if (currentValue instanceof Future && !currentValue.done) {
|
|
548
533
|
const future = currentValue;
|
|
@@ -559,7 +544,7 @@ function cacheValue(target, key, value, subject) {
|
|
|
559
544
|
future.then(function handleResolvedFuture(resolved) {
|
|
560
545
|
const current = target.valueMap.get(key);
|
|
561
546
|
if (current === future) {
|
|
562
|
-
|
|
547
|
+
writeToCache(target, key, resolved, subject);
|
|
563
548
|
const atom = target.atoms.get(key);
|
|
564
549
|
if (atom) {
|
|
565
550
|
openOperation(target, atom);
|
|
@@ -586,17 +571,31 @@ function cacheValue(target, key, value, subject) {
|
|
|
586
571
|
target.valueMap.set(key, value);
|
|
587
572
|
return value;
|
|
588
573
|
}
|
|
589
|
-
|
|
574
|
+
/**
|
|
575
|
+
* @param target - the newest layer of the store
|
|
576
|
+
* @param state - the state to read from cache
|
|
577
|
+
* @param mut - whether the value is intended to be mutable
|
|
578
|
+
* @returns the state's current value
|
|
579
|
+
*/
|
|
580
|
+
function readFromCache(target, state, mut) {
|
|
590
581
|
target.logger.info(`📖`, state.type, state.key, `reading cached value`);
|
|
591
582
|
let value = target.valueMap.get(state.key);
|
|
592
|
-
|
|
583
|
+
const mayNeedToBeCopied = mut === `mut` && state.type === `mutable_atom` && isChildStore(target);
|
|
584
|
+
if (mayNeedToBeCopied) {
|
|
585
|
+
const mutableAtom$1 = state;
|
|
593
586
|
const { parent } = target;
|
|
594
|
-
|
|
587
|
+
if (target.valueMap.hasOwn(mutableAtom$1.key)) return value;
|
|
588
|
+
const parentValue = parent.valueMap.get(mutableAtom$1.key);
|
|
589
|
+
target.logger.info(`📃`, `atom`, mutableAtom$1.key, `copying`);
|
|
590
|
+
const jsonValue = parentValue.toJSON();
|
|
591
|
+
const copiedValue = mutableAtom$1.class.fromJSON(jsonValue);
|
|
592
|
+
target.valueMap.set(mutableAtom$1.key, copiedValue);
|
|
593
|
+
new Tracker(mutableAtom$1, parent);
|
|
595
594
|
value = copiedValue;
|
|
596
595
|
}
|
|
597
596
|
return value;
|
|
598
|
-
}
|
|
599
|
-
|
|
597
|
+
}
|
|
598
|
+
function evictCachedValue(target, key) {
|
|
600
599
|
const currentValue = target.valueMap.get(key);
|
|
601
600
|
if (currentValue instanceof Future) {
|
|
602
601
|
const selector = target.writableSelectors.get(key) ?? target.readonlySelectors.get(key);
|
|
@@ -606,12 +605,12 @@ const evictCachedValue = (target, key) => {
|
|
|
606
605
|
if (target.operation.open) target.operation.prev.set(key, currentValue);
|
|
607
606
|
target.valueMap.delete(key);
|
|
608
607
|
target.logger.info(`🗑`, `state`, key, `evicted`);
|
|
609
|
-
}
|
|
608
|
+
}
|
|
610
609
|
|
|
611
610
|
//#endregion
|
|
612
611
|
//#region src/internal/get-state/read-or-compute-value.ts
|
|
613
|
-
|
|
614
|
-
if (target.valueMap.has(state.key)) return
|
|
612
|
+
function readOrComputeValue(target, state, mut) {
|
|
613
|
+
if (target.valueMap.has(state.key)) return readFromCache(target, state, mut);
|
|
615
614
|
switch (state.type) {
|
|
616
615
|
case `readonly_held_selector`:
|
|
617
616
|
case `readonly_pure_selector`:
|
|
@@ -620,23 +619,21 @@ const readOrComputeValue = (target, state) => {
|
|
|
620
619
|
target.logger.info(`🧮`, state.type, state.key, `computing value`);
|
|
621
620
|
return state.get();
|
|
622
621
|
case `atom`: {
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
target.logger.info(`💁`, `atom`, state.key, `could not find cached value; using default`, defaultValue);
|
|
622
|
+
let def;
|
|
623
|
+
if (state.default instanceof Function) def = state.default();
|
|
624
|
+
else def = state.default;
|
|
625
|
+
const cachedValue = writeToCache(target, state.key, def, state.subject);
|
|
626
|
+
target.logger.info(`💁`, `atom`, state.key, `could not find cached value; using default`, def);
|
|
629
627
|
return cachedValue;
|
|
630
628
|
}
|
|
631
629
|
case `mutable_atom`: {
|
|
632
|
-
const
|
|
633
|
-
const
|
|
634
|
-
const cachedValue = cacheValue(target, state.key, instance, state.subject);
|
|
630
|
+
const instance = new state.class();
|
|
631
|
+
const cachedValue = writeToCache(target, state.key, instance, state.subject);
|
|
635
632
|
target.logger.info(`💁`, `mutable_atom`, state.key, `could not find cached value; using default`, instance);
|
|
636
633
|
return cachedValue;
|
|
637
634
|
}
|
|
638
635
|
}
|
|
639
|
-
}
|
|
636
|
+
}
|
|
640
637
|
|
|
641
638
|
//#endregion
|
|
642
639
|
//#region src/internal/subscribe/subscribe-to-root-atoms.ts
|
|
@@ -657,6 +654,14 @@ const subscribeToRootDependency = (target, selector, atom) => {
|
|
|
657
654
|
//#region src/internal/set-state/become.ts
|
|
658
655
|
const become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(originalThing) : nextVersionOfThing;
|
|
659
656
|
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region src/internal/atom/has-role.ts
|
|
659
|
+
const INTERNAL_ROLES = [`tracker:signal`];
|
|
660
|
+
function hasRole(atom, role) {
|
|
661
|
+
if (`internalRoles` in atom === false) return false;
|
|
662
|
+
return atom.internalRoles.includes(role);
|
|
663
|
+
}
|
|
664
|
+
|
|
660
665
|
//#endregion
|
|
661
666
|
//#region src/internal/set-state/emit-update.ts
|
|
662
667
|
const emitUpdate = (store, state, update) => {
|
|
@@ -676,16 +681,10 @@ const emitUpdate = (store, state, update) => {
|
|
|
676
681
|
//#endregion
|
|
677
682
|
//#region src/internal/set-state/set-atom.ts
|
|
678
683
|
const setAtom = (target, atom, next) => {
|
|
679
|
-
const oldValue = readOrComputeValue(target, atom);
|
|
680
|
-
let newValue = oldValue;
|
|
681
|
-
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
682
|
-
const { parent } = target;
|
|
683
|
-
const copiedValue = copyMutableIfNeeded(target, atom, parent);
|
|
684
|
-
newValue = copiedValue;
|
|
685
|
-
}
|
|
686
|
-
newValue = become(next)(newValue);
|
|
684
|
+
const oldValue = readOrComputeValue(target, atom, `mut`);
|
|
685
|
+
let newValue = become(next)(oldValue);
|
|
687
686
|
target.logger.info(`📝`, `atom`, atom.key, `set to`, newValue);
|
|
688
|
-
newValue =
|
|
687
|
+
newValue = writeToCache(target, atom.key, newValue, atom.subject);
|
|
689
688
|
markDone(target, atom.key);
|
|
690
689
|
evictDownStream(target, atom);
|
|
691
690
|
const update = {
|
|
@@ -707,17 +706,12 @@ const setAtom = (target, atom, next) => {
|
|
|
707
706
|
if (atom.family) atomUpdate.family = atom.family;
|
|
708
707
|
target.transactionMeta.update.updates.push(atomUpdate);
|
|
709
708
|
target.logger.info(`📁`, `atom`, key, `stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
710
|
-
} else if (atom
|
|
711
|
-
const
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
if (mutableAtom$1.type === `mutable_atom` && isChildStore(target)) {
|
|
715
|
-
const { parent } = target;
|
|
716
|
-
const copiedValue = copyMutableIfNeeded(target, mutableAtom$1, parent);
|
|
717
|
-
transceiver = copiedValue;
|
|
718
|
-
}
|
|
709
|
+
} else if (hasRole(atom, `tracker:signal`)) {
|
|
710
|
+
const key = atom.key.slice(1);
|
|
711
|
+
const mutable = target.atoms.get(key);
|
|
712
|
+
const transceiver = readOrComputeValue(target, mutable, `mut`);
|
|
719
713
|
const accepted = transceiver.do(update.newValue) === null;
|
|
720
|
-
if (accepted) evictDownStream(target,
|
|
714
|
+
if (accepted === true) evictDownStream(target, mutable);
|
|
721
715
|
}
|
|
722
716
|
};
|
|
723
717
|
|
|
@@ -823,9 +817,9 @@ function setIntoStore(store, ...params) {
|
|
|
823
817
|
if (params.length === 2) {
|
|
824
818
|
token = params[0];
|
|
825
819
|
value = params[1];
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
key =
|
|
820
|
+
if (token.family) {
|
|
821
|
+
family = getFamilyOfToken(store, token);
|
|
822
|
+
key = parseJson(token.family.subKey);
|
|
829
823
|
token = findInStore(store, family, key);
|
|
830
824
|
}
|
|
831
825
|
} else {
|
|
@@ -842,7 +836,7 @@ function setIntoStore(store, ...params) {
|
|
|
842
836
|
}
|
|
843
837
|
const rejectionTime = openOperation(store, token);
|
|
844
838
|
if (rejectionTime) {
|
|
845
|
-
const unsubscribe = store.on.operationClose.subscribe(`waiting to set "${token.key}" at T-${rejectionTime}`, ()
|
|
839
|
+
const unsubscribe = store.on.operationClose.subscribe(`waiting to set "${token.key}" at T-${rejectionTime}`, function waitUntilOperationCloseToSetState() {
|
|
846
840
|
unsubscribe();
|
|
847
841
|
store.logger.info(`🟢`, token.type, token.key, `resuming deferred setState from T-${rejectionTime}`);
|
|
848
842
|
setIntoStore(store, token, value);
|
|
@@ -967,7 +961,7 @@ const createReadonlyHeldSelector = (store, options, family) => {
|
|
|
967
961
|
find,
|
|
968
962
|
json
|
|
969
963
|
}, constant);
|
|
970
|
-
|
|
964
|
+
writeToCache(newest(store), key, constant, subject);
|
|
971
965
|
covered.clear();
|
|
972
966
|
return constant;
|
|
973
967
|
};
|
|
@@ -1008,7 +1002,7 @@ const createReadonlyPureSelector = (store, options, family) => {
|
|
|
1008
1002
|
find,
|
|
1009
1003
|
json
|
|
1010
1004
|
});
|
|
1011
|
-
const cached =
|
|
1005
|
+
const cached = writeToCache(innerTarget, key, value, subject);
|
|
1012
1006
|
store.logger.info(`✨`, type, key, `=`, cached);
|
|
1013
1007
|
covered.clear();
|
|
1014
1008
|
return cached;
|
|
@@ -1586,7 +1580,7 @@ const createWritableHeldSelector = (store, options, family) => {
|
|
|
1586
1580
|
for (const [downstreamSelectorKey, { source }] of upstreamStates) if (source !== key) innerTarget.selectorGraph.delete(downstreamSelectorKey, key);
|
|
1587
1581
|
innerTarget.selectorAtoms.delete(key);
|
|
1588
1582
|
getFn(getterToolkit, constant);
|
|
1589
|
-
|
|
1583
|
+
writeToCache(innerTarget, key, constant, subject);
|
|
1590
1584
|
store.logger.info(`✨`, type, key, `=`, constant);
|
|
1591
1585
|
covered.clear();
|
|
1592
1586
|
return constant;
|
|
@@ -1596,7 +1590,7 @@ const createWritableHeldSelector = (store, options, family) => {
|
|
|
1596
1590
|
const oldValue = getSelf(options.get, innerTarget);
|
|
1597
1591
|
const newValue = become(next)(oldValue);
|
|
1598
1592
|
store.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`);
|
|
1599
|
-
|
|
1593
|
+
writeToCache(innerTarget, key, newValue, subject);
|
|
1600
1594
|
markDone(innerTarget, key);
|
|
1601
1595
|
if (isRootStore(innerTarget)) subject.next({
|
|
1602
1596
|
newValue,
|
|
@@ -1642,7 +1636,7 @@ const createWritablePureSelector = (store, options, family) => {
|
|
|
1642
1636
|
for (const [downstreamSelectorKey, { source }] of upstreamStates) if (source !== key) innerTarget.selectorGraph.delete(downstreamSelectorKey, key);
|
|
1643
1637
|
innerTarget.selectorAtoms.delete(key);
|
|
1644
1638
|
const value = getFn(getterToolkit);
|
|
1645
|
-
const cached =
|
|
1639
|
+
const cached = writeToCache(innerTarget, key, value, subject);
|
|
1646
1640
|
store.logger.info(`✨`, type, key, `=`, cached);
|
|
1647
1641
|
covered.clear();
|
|
1648
1642
|
return value;
|
|
@@ -1652,7 +1646,7 @@ const createWritablePureSelector = (store, options, family) => {
|
|
|
1652
1646
|
const oldValue = getSelf(options.get, innerTarget);
|
|
1653
1647
|
const newValue = become(next)(oldValue);
|
|
1654
1648
|
store.logger.info(`📝`, type, key, `set (`, oldValue, `->`, newValue, `)`);
|
|
1655
|
-
|
|
1649
|
+
writeToCache(innerTarget, options.key, newValue, subject);
|
|
1656
1650
|
markDone(innerTarget, options.key);
|
|
1657
1651
|
if (isRootStore(innerTarget)) subject.next({
|
|
1658
1652
|
newValue,
|
|
@@ -2233,30 +2227,33 @@ const subscribeToTransaction = (store, token, key, handleUpdate) => {
|
|
|
2233
2227
|
* the tracker will update its own state to reflect the change.
|
|
2234
2228
|
*/
|
|
2235
2229
|
var Tracker = class {
|
|
2236
|
-
|
|
2237
|
-
const
|
|
2238
|
-
store.atoms.delete(
|
|
2239
|
-
store.valueMap.delete(
|
|
2230
|
+
initializeSignalAtom(mutableState, store) {
|
|
2231
|
+
const latestSignalStateKey = `*${mutableState.key}`;
|
|
2232
|
+
store.atoms.delete(latestSignalStateKey);
|
|
2233
|
+
store.valueMap.delete(latestSignalStateKey);
|
|
2240
2234
|
const familyMetaData = mutableState.family ? {
|
|
2241
2235
|
key: `*${mutableState.family.key}`,
|
|
2242
2236
|
subKey: mutableState.family.subKey
|
|
2243
2237
|
} : void 0;
|
|
2244
|
-
const
|
|
2245
|
-
key:
|
|
2238
|
+
const latestSignalState = createRegularAtom(store, {
|
|
2239
|
+
key: latestSignalStateKey,
|
|
2246
2240
|
default: null
|
|
2247
|
-
}, familyMetaData);
|
|
2248
|
-
if (store.parent?.valueMap.has(
|
|
2249
|
-
const parentValue = store.parent.valueMap.get(
|
|
2250
|
-
store.valueMap.set(
|
|
2241
|
+
}, familyMetaData, [`tracker:signal`]);
|
|
2242
|
+
if (store.parent?.valueMap.has(latestSignalStateKey)) {
|
|
2243
|
+
const parentValue = store.parent.valueMap.get(latestSignalStateKey);
|
|
2244
|
+
store.valueMap.set(latestSignalStateKey, parentValue);
|
|
2251
2245
|
}
|
|
2252
|
-
return
|
|
2246
|
+
return latestSignalState;
|
|
2253
2247
|
}
|
|
2254
2248
|
unsubscribeFromInnerValue;
|
|
2255
2249
|
unsubscribeFromState;
|
|
2256
|
-
captureSignalsFromCore(mutableState,
|
|
2257
|
-
const
|
|
2250
|
+
captureSignalsFromCore(mutableState, latestSignalState, target) {
|
|
2251
|
+
const stateKey = mutableState.key;
|
|
2252
|
+
const storeName = target.config.name;
|
|
2253
|
+
const storeStatus = isChildStore(target) ? target.transactionMeta.update.key : `main`;
|
|
2254
|
+
const subscriptionKey = `tracker:${storeName}:${storeStatus}:${stateKey}`;
|
|
2258
2255
|
const trackerCapturesOutboundSignal = (update) => {
|
|
2259
|
-
setIntoStore(target,
|
|
2256
|
+
setIntoStore(target, latestSignalState, update);
|
|
2260
2257
|
};
|
|
2261
2258
|
const originalInnerValue = getFromStore(target, mutableState);
|
|
2262
2259
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(subscriptionKey, trackerCapturesOutboundSignal);
|
|
@@ -2267,10 +2264,10 @@ var Tracker = class {
|
|
|
2267
2264
|
}
|
|
2268
2265
|
}.bind(this));
|
|
2269
2266
|
}
|
|
2270
|
-
supplySignalsToCore(mutableState,
|
|
2267
|
+
supplySignalsToCore(mutableState, latestSignalState, target) {
|
|
2271
2268
|
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
2272
|
-
subscribeToState(target,
|
|
2273
|
-
const timelineId = target.timelineTopics.getRelatedKey(
|
|
2269
|
+
subscribeToState(target, latestSignalState, subscriptionKey, function trackerCapturesInboundSignal({ newValue, oldValue }) {
|
|
2270
|
+
const timelineId = target.timelineTopics.getRelatedKey(latestSignalState.key);
|
|
2274
2271
|
if (timelineId && target.timelines.get(timelineId)?.timeTraveling) {
|
|
2275
2272
|
const unsubscribe = subscribeToTimeline(target, {
|
|
2276
2273
|
key: timelineId,
|
|
@@ -2289,7 +2286,10 @@ var Tracker = class {
|
|
|
2289
2286
|
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
2290
2287
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
2291
2288
|
if (newValue && eventOffset === 1) setIntoStore(target, mutableState, (transceiver) => (transceiver.do(newValue), transceiver));
|
|
2292
|
-
else
|
|
2289
|
+
else {
|
|
2290
|
+
const expected = mutable.cacheUpdateNumber + 1;
|
|
2291
|
+
target.logger.info(`❌`, `mutable_atom`, mutableState.key, `could not be updated. Expected update number`, expected, `but got`, updateNumber);
|
|
2292
|
+
}
|
|
2293
2293
|
});
|
|
2294
2294
|
}
|
|
2295
2295
|
mutableAtomToken;
|
|
@@ -2297,7 +2297,7 @@ var Tracker = class {
|
|
|
2297
2297
|
[Symbol.dispose];
|
|
2298
2298
|
constructor(mutableAtomToken, store) {
|
|
2299
2299
|
const target = newest(store);
|
|
2300
|
-
const latestSignalToken = this.
|
|
2300
|
+
const latestSignalToken = this.initializeSignalAtom(mutableAtomToken, target);
|
|
2301
2301
|
this.mutableAtomToken = mutableAtomToken;
|
|
2302
2302
|
this.latestSignalToken = latestSignalToken;
|
|
2303
2303
|
this.captureSignalsFromCore(mutableAtomToken, latestSignalToken, target);
|
|
@@ -2372,16 +2372,16 @@ function createMutableAtom(store, options, family) {
|
|
|
2372
2372
|
//#region src/internal/mutable/tracker-family.ts
|
|
2373
2373
|
var FamilyTracker = class {
|
|
2374
2374
|
trackers = /* @__PURE__ */ new Map();
|
|
2375
|
-
|
|
2375
|
+
latestSignalAtoms;
|
|
2376
2376
|
mutableAtoms;
|
|
2377
2377
|
constructor(mutableAtoms, store) {
|
|
2378
|
-
const
|
|
2378
|
+
const latestSignalAtoms = createRegularAtomFamily(store, {
|
|
2379
2379
|
key: `*${mutableAtoms.key}`,
|
|
2380
2380
|
default: null
|
|
2381
2381
|
}, [`mutable`, `updates`]);
|
|
2382
|
-
this.
|
|
2382
|
+
this.latestSignalAtoms = withdraw(store, latestSignalAtoms);
|
|
2383
2383
|
this.mutableAtoms = mutableAtoms;
|
|
2384
|
-
|
|
2384
|
+
const trackerFamilyWatchesForCreationAndDisposalEvents = (event) => {
|
|
2385
2385
|
const { type, token } = event;
|
|
2386
2386
|
if (token.family) {
|
|
2387
2387
|
const key = parseJson(token.family.subKey);
|
|
@@ -2389,18 +2389,17 @@ var FamilyTracker = class {
|
|
|
2389
2389
|
case `state_creation`:
|
|
2390
2390
|
this.trackers.set(key, new Tracker(token, store));
|
|
2391
2391
|
break;
|
|
2392
|
-
case `state_disposal`:
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
this.trackers.delete(key);
|
|
2398
|
-
}
|
|
2392
|
+
case `state_disposal`: {
|
|
2393
|
+
const tracker = this.trackers.get(key);
|
|
2394
|
+
if (tracker) {
|
|
2395
|
+
tracker[Symbol.dispose]();
|
|
2396
|
+
this.trackers.delete(key);
|
|
2399
2397
|
}
|
|
2400
|
-
|
|
2398
|
+
}
|
|
2401
2399
|
}
|
|
2402
2400
|
}
|
|
2403
|
-
}
|
|
2401
|
+
};
|
|
2402
|
+
this.mutableAtoms.subject.subscribe(`store=${store.config.name}::tracker-atom-family`, trackerFamilyWatchesForCreationAndDisposalEvents);
|
|
2404
2403
|
}
|
|
2405
2404
|
};
|
|
2406
2405
|
|
|
@@ -2683,7 +2682,7 @@ function withdraw(store, token) {
|
|
|
2683
2682
|
|
|
2684
2683
|
//#endregion
|
|
2685
2684
|
//#region src/internal/atom/create-regular-atom.ts
|
|
2686
|
-
function createRegularAtom(store, options, family) {
|
|
2685
|
+
function createRegularAtom(store, options, family, internalRoles) {
|
|
2687
2686
|
const type = `atom`;
|
|
2688
2687
|
const { key } = options;
|
|
2689
2688
|
store.logger.info(`🔨`, `atom`, key, `creating in store "${store.config.name}"`);
|
|
@@ -2704,6 +2703,7 @@ function createRegularAtom(store, options, family) {
|
|
|
2704
2703
|
subject
|
|
2705
2704
|
};
|
|
2706
2705
|
if (family) newAtom.family = family;
|
|
2706
|
+
if (internalRoles) newAtom.internalRoles = internalRoles;
|
|
2707
2707
|
target.atoms.set(key, newAtom);
|
|
2708
2708
|
const token = deposit(newAtom);
|
|
2709
2709
|
if (options.effects) {
|
|
@@ -3547,5 +3547,5 @@ const timeTravel = (store, action, token) => {
|
|
|
3547
3547
|
};
|
|
3548
3548
|
|
|
3549
3549
|
//#endregion
|
|
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,
|
|
3550
|
+
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, INTERNAL_ROLES, Join, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, 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, hasRole, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, installIntoStore, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isReservedIntrospectionKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markDone, newest, openOperation, prettyPrintTokenType, readFromCache, readOrComputeValue, recallState, registerSelector, resetAtomOrSelector, resetInStore, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootDependency, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceRootSelectorAtoms, updateSelectorAtoms, withdraw, writeToCache };
|
|
3551
3551
|
//# sourceMappingURL=index.js.map
|