atom.io 0.16.3 → 0.18.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/data/dist/index.cjs +62 -40
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +8 -2
- package/data/dist/index.js +64 -42
- package/data/dist/index.js.map +1 -1
- package/data/src/dict.ts +8 -4
- package/data/src/join.ts +74 -33
- package/data/src/struct-family.ts +18 -17
- package/dist/chunk-OEVFAUPE.js +289 -0
- package/dist/chunk-OEVFAUPE.js.map +1 -0
- package/dist/index.cjs +36 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +64 -53
- package/dist/index.js +15 -36
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +211 -81
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +100 -72
- package/internal/dist/index.js +200 -75
- package/internal/dist/index.js.map +1 -1
- package/internal/src/arbitrary.ts +3 -0
- package/internal/src/atom/create-regular-atom.ts +2 -3
- package/internal/src/caching.ts +8 -6
- package/internal/src/families/find-in-store.ts +16 -0
- package/internal/src/get-environment-data.ts +4 -7
- package/internal/src/get-state/get-from-store.ts +14 -0
- package/internal/src/get-state/index.ts +2 -0
- package/internal/src/{read-or-compute-value.ts → get-state/read-or-compute-value.ts} +3 -3
- package/internal/src/index.ts +7 -6
- package/internal/src/ingest-updates/ingest-atom-update.ts +2 -2
- package/internal/src/ingest-updates/ingest-transaction-update.ts +0 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -4
- package/internal/src/mutable/tracker.ts +18 -13
- package/internal/src/selector/create-standalone-selector.ts +0 -2
- package/internal/src/selector/register-selector.ts +1 -1
- package/internal/src/set-state/index.ts +1 -0
- package/internal/src/set-state/set-atom.ts +15 -19
- package/internal/src/set-state/set-into-store.ts +24 -0
- package/internal/src/store/store.ts +14 -2
- package/internal/src/store/withdraw.ts +72 -2
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/subscribe/subscribe-to-timeline.ts +2 -2
- package/internal/src/subscribe/subscribe-to-transaction.ts +2 -2
- package/internal/src/timeline/create-timeline.ts +12 -1
- package/internal/src/transaction/act-upon-store.ts +19 -0
- package/internal/src/transaction/apply-transaction.ts +7 -1
- package/internal/src/transaction/assign-transaction-to-continuity.ts +18 -0
- package/internal/src/transaction/build-transaction.ts +11 -8
- package/internal/src/transaction/create-transaction.ts +1 -1
- package/internal/src/transaction/get-epoch-number.ts +40 -0
- package/internal/src/transaction/index.ts +10 -1
- package/internal/src/transaction/set-epoch-number.ts +31 -0
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-introspection-states.ts +6 -2
- package/introspection/src/attach-timeline-family.ts +5 -2
- package/introspection/src/attach-transaction-logs.ts +2 -2
- package/json/dist/index.d.ts +3 -1
- package/json/src/index.ts +6 -2
- package/package.json +24 -13
- package/react/dist/index.cjs +3 -3
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +1 -1
- package/react/dist/index.js +5 -5
- package/react/dist/index.js.map +1 -1
- package/react/src/use-i.ts +2 -3
- package/react/src/use-json.ts +1 -1
- package/react/src/use-o.ts +3 -4
- package/react-devtools/dist/index.cjs +131 -134
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.css +2 -2
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.ts +3 -3
- package/react-devtools/dist/index.js +103 -106
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +6 -6
- package/react-devtools/src/StateIndex.tsx +2 -5
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +9 -8
- package/react-devtools/src/Updates.tsx +1 -1
- package/react-devtools/src/index.ts +4 -4
- package/realtime/dist/index.cjs +72 -0
- package/realtime/dist/index.cjs.map +1 -0
- package/realtime/dist/index.d.ts +39 -0
- package/realtime/dist/index.js +68 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/package.json +16 -0
- package/realtime/src/index.ts +1 -0
- package/realtime/src/realtime-continuity.ts +152 -0
- package/realtime-client/dist/index.cjs +403 -59
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +16 -9
- package/realtime-client/dist/index.js +114 -48
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +8 -5
- package/realtime-client/src/{pull-family-member.ts → pull-atom-family-member.ts} +5 -5
- package/realtime-client/src/{pull-state.ts → pull-atom.ts} +5 -5
- package/realtime-client/src/{pull-mutable-family-member.ts → pull-mutable-atom-family-member.ts} +5 -5
- package/realtime-client/src/{pull-mutable.ts → pull-mutable-atom.ts} +5 -5
- package/realtime-client/src/pull-selector-family-member.ts +42 -0
- package/realtime-client/src/pull-selector.ts +38 -0
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +2 -2
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +7 -7
- package/realtime-client/src/sync-continuity.ts +321 -0
- package/realtime-client/src/sync-server-action.ts +22 -21
- package/realtime-client/src/sync-state.ts +3 -3
- package/realtime-react/dist/index.cjs +330 -15
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +26 -6
- package/realtime-react/dist/index.js +43 -12
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +6 -3
- package/realtime-react/src/use-pull-atom-family-member.ts +21 -0
- package/realtime-react/src/{use-pull.ts → use-pull-atom.ts} +6 -5
- package/realtime-react/src/{use-pull-mutable.ts → use-pull-mutable-atom.ts} +4 -3
- package/realtime-react/src/use-pull-mutable-family-member.ts +9 -4
- package/realtime-react/src/use-pull-selector-family-member.ts +21 -0
- package/realtime-react/src/{use-pull-family-member.ts → use-pull-selector.ts} +7 -5
- package/realtime-react/src/use-push.ts +3 -2
- package/realtime-react/src/use-server-action.ts +3 -2
- package/realtime-react/src/use-sync-continuity.ts +12 -0
- package/realtime-react/src/use-sync-server-action.ts +3 -2
- package/realtime-server/dist/index.cjs +582 -256
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +124 -49
- package/realtime-server/dist/index.js +566 -249
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +18 -2
- package/realtime-server/src/ipc-socket.ts +230 -0
- package/realtime-server/src/realtime-action-receiver.ts +8 -5
- package/realtime-server/src/realtime-action-synchronizer.ts +53 -35
- package/realtime-server/src/realtime-continuity-synchronizer.ts +247 -0
- package/realtime-server/src/realtime-family-provider.ts +37 -73
- package/realtime-server/src/realtime-mutable-family-provider.ts +26 -87
- package/realtime-server/src/realtime-mutable-provider.ts +3 -2
- package/realtime-server/src/realtime-server-stores/index.ts +3 -1
- package/realtime-server/src/realtime-server-stores/realtime-continuity-store.ts +90 -0
- package/realtime-server/src/realtime-server-stores/server-room-store.ts +97 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +2 -72
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +14 -29
- package/realtime-server/src/realtime-state-provider.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +2 -3
- package/realtime-server/src/realtime-state-synchronizer.ts +3 -3
- package/realtime-testing/dist/index.cjs +28 -28
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +28 -27
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +38 -28
- package/src/atom.ts +49 -31
- package/src/get-state.ts +2 -11
- package/src/logger.ts +10 -5
- package/src/selector.ts +44 -25
- package/src/set-state.ts +1 -13
- package/src/silo.ts +7 -3
- package/src/subscribe.ts +2 -1
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +13 -17
- package/src/validators.ts +15 -9
- package/dist/chunk-H4Q5FTPZ.js +0 -11
- package/dist/chunk-H4Q5FTPZ.js.map +0 -1
- package/internal/src/set-state/copy-mutable-in-transaction.ts +0 -19
package/internal/dist/index.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var atom_io = require('atom.io');
|
|
4
3
|
var json = require('atom.io/json');
|
|
5
|
-
var
|
|
4
|
+
var atom_io = require('atom.io');
|
|
6
5
|
|
|
7
6
|
var __defProp = Object.defineProperty;
|
|
8
7
|
var __defProps = Object.defineProperties;
|
|
@@ -333,6 +332,14 @@ var StatefulSubject = class extends Subject {
|
|
|
333
332
|
}
|
|
334
333
|
};
|
|
335
334
|
|
|
335
|
+
// internal/src/transaction/is-root-store.ts
|
|
336
|
+
function isRootStore(store) {
|
|
337
|
+
return `epoch` in store.transactionMeta;
|
|
338
|
+
}
|
|
339
|
+
function isChildStore(store) {
|
|
340
|
+
return `phase` in store.transactionMeta;
|
|
341
|
+
}
|
|
342
|
+
|
|
336
343
|
// internal/src/store/store.ts
|
|
337
344
|
var Store = class {
|
|
338
345
|
constructor(name, store = null) {
|
|
@@ -376,7 +383,11 @@ var Store = class {
|
|
|
376
383
|
};
|
|
377
384
|
this.operation = { open: false };
|
|
378
385
|
this.transactionMeta = {
|
|
379
|
-
epoch:
|
|
386
|
+
epoch: /* @__PURE__ */ new Map(),
|
|
387
|
+
actionContinuities: new Junction({
|
|
388
|
+
between: [`continuity`, `action`],
|
|
389
|
+
cardinality: `1:n`
|
|
390
|
+
})
|
|
380
391
|
};
|
|
381
392
|
this.config = {
|
|
382
393
|
name: `IMPLICIT_STORE`
|
|
@@ -401,7 +412,14 @@ var Store = class {
|
|
|
401
412
|
if (store !== null) {
|
|
402
413
|
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
403
414
|
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
404
|
-
|
|
415
|
+
if (isRootStore(store)) {
|
|
416
|
+
this.transactionMeta = {
|
|
417
|
+
epoch: new Map(store == null ? void 0 : store.transactionMeta.epoch),
|
|
418
|
+
actionContinuities: new Junction(
|
|
419
|
+
store == null ? void 0 : store.transactionMeta.actionContinuities.toJSON()
|
|
420
|
+
)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
405
423
|
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
406
424
|
name
|
|
407
425
|
});
|
|
@@ -468,6 +486,12 @@ function withdraw(token, store) {
|
|
|
468
486
|
case `readonly_selector`:
|
|
469
487
|
withdrawn = target.readonlySelectors.get(token.key);
|
|
470
488
|
break;
|
|
489
|
+
case `atom_family`:
|
|
490
|
+
case `mutable_atom_family`:
|
|
491
|
+
case `selector_family`:
|
|
492
|
+
case `readonly_selector_family`:
|
|
493
|
+
withdrawn = target.families.get(token.key);
|
|
494
|
+
break;
|
|
471
495
|
case `timeline`:
|
|
472
496
|
withdrawn = target.timelines.get(token.key);
|
|
473
497
|
break;
|
|
@@ -522,34 +546,6 @@ var Future = class extends Promise {
|
|
|
522
546
|
}
|
|
523
547
|
};
|
|
524
548
|
|
|
525
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
526
|
-
function copyMutableIfNeeded(atom, origin, target) {
|
|
527
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
528
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
529
|
-
if (originValue === targetValue) {
|
|
530
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
531
|
-
const jsonValue = atom.toJson(originValue);
|
|
532
|
-
const copiedValue = atom.fromJson(jsonValue);
|
|
533
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
534
|
-
new Tracker(atom, origin);
|
|
535
|
-
return copiedValue;
|
|
536
|
-
}
|
|
537
|
-
return targetValue;
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
541
|
-
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
542
|
-
const target = newest(store);
|
|
543
|
-
const parent = target.parent;
|
|
544
|
-
if (parent !== null) {
|
|
545
|
-
if (atom.type === `mutable_atom`) {
|
|
546
|
-
const copiedValue = copyMutableIfNeeded(atom, parent, target);
|
|
547
|
-
return copiedValue;
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
return oldValue;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
549
|
// internal/src/caching.ts
|
|
554
550
|
function cacheValue(key, value, subject, target) {
|
|
555
551
|
const currentValue = target.valueMap.get(key);
|
|
@@ -576,10 +572,7 @@ function cacheValue(key, value, subject, target) {
|
|
|
576
572
|
return value;
|
|
577
573
|
}
|
|
578
574
|
var readCachedValue = (token, target) => {
|
|
579
|
-
|
|
580
|
-
if (token.type === `atom`) {
|
|
581
|
-
value = copyMutableIfWithinTransaction(value, token, target);
|
|
582
|
-
}
|
|
575
|
+
const value = target.valueMap.get(token.key);
|
|
583
576
|
return value;
|
|
584
577
|
};
|
|
585
578
|
var evictCachedValue = (key, target) => {
|
|
@@ -594,7 +587,7 @@ var evictCachedValue = (key, target) => {
|
|
|
594
587
|
target.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
595
588
|
};
|
|
596
589
|
|
|
597
|
-
// internal/src/read-or-compute-value.ts
|
|
590
|
+
// internal/src/get-state/read-or-compute-value.ts
|
|
598
591
|
var readOrComputeValue = (state, target) => {
|
|
599
592
|
if (target.valueMap.has(state.key)) {
|
|
600
593
|
target.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
@@ -764,14 +757,6 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
|
|
|
764
757
|
originalThing instanceof Function ? originalThing() : originalThing
|
|
765
758
|
) : nextVersionOfThing;
|
|
766
759
|
|
|
767
|
-
// internal/src/transaction/is-root-store.ts
|
|
768
|
-
function isRootStore(store) {
|
|
769
|
-
return `epoch` in store.transactionMeta;
|
|
770
|
-
}
|
|
771
|
-
function isChildStore(store) {
|
|
772
|
-
return `phase` in store.transactionMeta;
|
|
773
|
-
}
|
|
774
|
-
|
|
775
760
|
// internal/src/operation.ts
|
|
776
761
|
var openOperation = (token, store) => {
|
|
777
762
|
if (store.operation.open) {
|
|
@@ -834,6 +819,21 @@ var markDone = (key, store) => {
|
|
|
834
819
|
store.operation.done.add(key);
|
|
835
820
|
};
|
|
836
821
|
|
|
822
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
823
|
+
function copyMutableIfNeeded(atom, origin, target) {
|
|
824
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
825
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
826
|
+
if (originValue === targetValue) {
|
|
827
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
828
|
+
const jsonValue = atom.toJson(originValue);
|
|
829
|
+
const copiedValue = atom.fromJson(jsonValue);
|
|
830
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
831
|
+
new Tracker(atom, origin);
|
|
832
|
+
return copiedValue;
|
|
833
|
+
}
|
|
834
|
+
return targetValue;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
837
|
// internal/src/set-state/emit-update.ts
|
|
838
838
|
var emitUpdate = (state, update, store) => {
|
|
839
839
|
store.logger.info(
|
|
@@ -925,7 +925,12 @@ var stowUpdate = (state, update, store) => {
|
|
|
925
925
|
// internal/src/set-state/set-atom.ts
|
|
926
926
|
var setAtom = (atom, next, target) => {
|
|
927
927
|
const oldValue = readOrComputeValue(atom, target);
|
|
928
|
-
let newValue =
|
|
928
|
+
let newValue = oldValue;
|
|
929
|
+
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
930
|
+
const { parent } = target;
|
|
931
|
+
const copiedValue = copyMutableIfNeeded(atom, parent, target);
|
|
932
|
+
newValue = copiedValue;
|
|
933
|
+
}
|
|
929
934
|
newValue = become(next)(newValue);
|
|
930
935
|
target.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
931
936
|
newValue = cacheValue(atom.key, newValue, atom.subject, target);
|
|
@@ -942,19 +947,14 @@ var setAtom = (atom, next, target) => {
|
|
|
942
947
|
stowUpdate(atom, update, target);
|
|
943
948
|
} else if (atom.key.startsWith(`*`)) {
|
|
944
949
|
const mutableKey = atom.key.slice(1);
|
|
945
|
-
|
|
946
|
-
let
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
`\u274C`,
|
|
952
|
-
`mutable_atom`,
|
|
953
|
-
mutableKey,
|
|
954
|
-
`could not be updated.`,
|
|
955
|
-
typeof output === `number` ? `Expected update number ${mutable.cacheUpdateNumber + 1}, but got ${output}` : output
|
|
956
|
-
);
|
|
950
|
+
target.atoms.get(mutableKey);
|
|
951
|
+
let transceiver = target.valueMap.get(mutableKey);
|
|
952
|
+
if (atom.type === `mutable_atom` && isChildStore(target)) {
|
|
953
|
+
const { parent } = target;
|
|
954
|
+
const copiedValue = copyMutableIfNeeded(atom, parent, target);
|
|
955
|
+
transceiver = copiedValue;
|
|
957
956
|
}
|
|
957
|
+
transceiver.do(update.newValue);
|
|
958
958
|
}
|
|
959
959
|
}
|
|
960
960
|
};
|
|
@@ -972,6 +972,21 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
972
972
|
}
|
|
973
973
|
};
|
|
974
974
|
|
|
975
|
+
// internal/src/set-state/set-into-store.ts
|
|
976
|
+
function setIntoStore(token, value, store) {
|
|
977
|
+
var _a;
|
|
978
|
+
const rejection = openOperation(token, store);
|
|
979
|
+
if (rejection) {
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
983
|
+
if (state === void 0) {
|
|
984
|
+
throw new NotFoundError(token, store);
|
|
985
|
+
}
|
|
986
|
+
setAtomOrSelector(state, value, store);
|
|
987
|
+
closeOperation(store);
|
|
988
|
+
}
|
|
989
|
+
|
|
975
990
|
// internal/src/keys.ts
|
|
976
991
|
var isAtomKey = (key, store) => newest(store).atoms.has(key);
|
|
977
992
|
var isSelectorKey = (key, store) => newest(store).selectors.has(key);
|
|
@@ -1307,8 +1322,10 @@ function subscribeToState(token, handleUpdate, key, store) {
|
|
|
1307
1322
|
};
|
|
1308
1323
|
return unsubscribe;
|
|
1309
1324
|
}
|
|
1325
|
+
|
|
1326
|
+
// internal/src/subscribe/subscribe-to-timeline.ts
|
|
1310
1327
|
var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
1311
|
-
const tl =
|
|
1328
|
+
const tl = withdraw(token, store);
|
|
1312
1329
|
if (tl === void 0) {
|
|
1313
1330
|
throw new Error(
|
|
1314
1331
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
@@ -1326,8 +1343,10 @@ var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
|
1326
1343
|
unsubscribe();
|
|
1327
1344
|
};
|
|
1328
1345
|
};
|
|
1346
|
+
|
|
1347
|
+
// internal/src/subscribe/subscribe-to-transaction.ts
|
|
1329
1348
|
var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
1330
|
-
const tx =
|
|
1349
|
+
const tx = withdraw(token, store);
|
|
1331
1350
|
if (tx === void 0) {
|
|
1332
1351
|
throw new Error(
|
|
1333
1352
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
@@ -1350,6 +1369,8 @@ var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
|
1350
1369
|
unsubscribe();
|
|
1351
1370
|
};
|
|
1352
1371
|
};
|
|
1372
|
+
|
|
1373
|
+
// internal/src/mutable/tracker.ts
|
|
1353
1374
|
var Tracker = class {
|
|
1354
1375
|
initializeState(mutableState, store) {
|
|
1355
1376
|
var _a;
|
|
@@ -1376,7 +1397,7 @@ var Tracker = class {
|
|
|
1376
1397
|
}
|
|
1377
1398
|
observeCore(mutableState, latestUpdateState, target) {
|
|
1378
1399
|
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
1379
|
-
const originalInnerValue =
|
|
1400
|
+
const originalInnerValue = getFromStore(mutableState, target);
|
|
1380
1401
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1381
1402
|
subscriptionKey,
|
|
1382
1403
|
(update) => {
|
|
@@ -1385,12 +1406,12 @@ var Tracker = class {
|
|
|
1385
1406
|
subscriptionKey,
|
|
1386
1407
|
() => {
|
|
1387
1408
|
unsubscribe();
|
|
1388
|
-
|
|
1409
|
+
setIntoStore(latestUpdateState, update, target);
|
|
1389
1410
|
}
|
|
1390
1411
|
);
|
|
1391
1412
|
} else {
|
|
1392
|
-
|
|
1393
|
-
|
|
1413
|
+
setIntoStore(mutableState, (current) => current, target);
|
|
1414
|
+
setIntoStore(latestUpdateState, update, target);
|
|
1394
1415
|
}
|
|
1395
1416
|
}
|
|
1396
1417
|
);
|
|
@@ -1407,12 +1428,12 @@ var Tracker = class {
|
|
|
1407
1428
|
subscriptionKey,
|
|
1408
1429
|
() => {
|
|
1409
1430
|
unsubscribe();
|
|
1410
|
-
|
|
1431
|
+
setIntoStore(latestUpdateState, update2, target);
|
|
1411
1432
|
}
|
|
1412
1433
|
);
|
|
1413
1434
|
} else {
|
|
1414
|
-
|
|
1415
|
-
|
|
1435
|
+
setIntoStore(mutableState, (current) => current, target);
|
|
1436
|
+
setIntoStore(latestUpdateState, update2, target);
|
|
1416
1437
|
}
|
|
1417
1438
|
}
|
|
1418
1439
|
);
|
|
@@ -1437,7 +1458,7 @@ var Tracker = class {
|
|
|
1437
1458
|
{ key: timelineId, type: `timeline` },
|
|
1438
1459
|
(update) => {
|
|
1439
1460
|
unsubscribe2();
|
|
1440
|
-
|
|
1461
|
+
setIntoStore(
|
|
1441
1462
|
mutableState,
|
|
1442
1463
|
(transceiver) => {
|
|
1443
1464
|
if (update === `redo` && newValue) {
|
|
@@ -1460,11 +1481,11 @@ var Tracker = class {
|
|
|
1460
1481
|
subscriptionKey,
|
|
1461
1482
|
() => {
|
|
1462
1483
|
unsubscribe();
|
|
1463
|
-
const mutable =
|
|
1484
|
+
const mutable = getFromStore(mutableState, target);
|
|
1464
1485
|
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1465
1486
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1466
1487
|
if (newValue && eventOffset === 1) {
|
|
1467
|
-
|
|
1488
|
+
setIntoStore(
|
|
1468
1489
|
mutableState,
|
|
1469
1490
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1470
1491
|
target
|
|
@@ -1545,7 +1566,7 @@ function createMutableAtom(options, family, store) {
|
|
|
1545
1566
|
const cleanupFunctions = [];
|
|
1546
1567
|
for (const effect of options.effects) {
|
|
1547
1568
|
const cleanup = effect({
|
|
1548
|
-
setSelf: (next) =>
|
|
1569
|
+
setSelf: (next) => setIntoStore(token, next, store),
|
|
1549
1570
|
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1550
1571
|
});
|
|
1551
1572
|
if (cleanup) {
|
|
@@ -1752,7 +1773,7 @@ function createRegularAtom(options, family, store) {
|
|
|
1752
1773
|
const cleanupFunctions = [];
|
|
1753
1774
|
for (const effect of options.effects) {
|
|
1754
1775
|
const cleanup = effect({
|
|
1755
|
-
setSelf: (next) =>
|
|
1776
|
+
setSelf: (next) => setIntoStore(token, next, store),
|
|
1756
1777
|
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1757
1778
|
});
|
|
1758
1779
|
if (cleanup) {
|
|
@@ -1811,17 +1832,35 @@ function deleteAtom(atomToken, store) {
|
|
|
1811
1832
|
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1812
1833
|
}
|
|
1813
1834
|
|
|
1835
|
+
// internal/src/arbitrary.ts
|
|
1836
|
+
function arbitrary(random = Math.random) {
|
|
1837
|
+
return random().toString(36).slice(2);
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1814
1840
|
// internal/src/get-environment-data.ts
|
|
1815
1841
|
function getEnvironmentData(store) {
|
|
1816
1842
|
return {
|
|
1817
|
-
|
|
1843
|
+
window: typeof window === `undefined` ? void 0 : window,
|
|
1844
|
+
global: typeof global === `undefined` ? void 0 : global,
|
|
1818
1845
|
store
|
|
1819
1846
|
};
|
|
1820
1847
|
}
|
|
1848
|
+
|
|
1849
|
+
// internal/src/get-state/get-from-store.ts
|
|
1850
|
+
function getFromStore(token, store) {
|
|
1851
|
+
var _a;
|
|
1852
|
+
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
1853
|
+
if (state === void 0) {
|
|
1854
|
+
throw new NotFoundError(token, store);
|
|
1855
|
+
}
|
|
1856
|
+
return readOrComputeValue(state, store);
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// internal/src/ingest-updates/ingest-atom-update.ts
|
|
1821
1860
|
function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
1822
1861
|
const { key, newValue, oldValue } = atomUpdate;
|
|
1823
1862
|
const value = applying === `newValue` ? newValue : oldValue;
|
|
1824
|
-
|
|
1863
|
+
setIntoStore({ key, type: `atom` }, value, store);
|
|
1825
1864
|
}
|
|
1826
1865
|
|
|
1827
1866
|
// internal/src/ingest-updates/ingest-selector-update.ts
|
|
@@ -2100,7 +2139,17 @@ function createTimeline(options, store, data) {
|
|
|
2100
2139
|
for (const tokenOrFamily of options.atoms) {
|
|
2101
2140
|
let atomKey = tokenOrFamily.key;
|
|
2102
2141
|
if (tokenOrFamily.type === `atom_family` || tokenOrFamily.type === `mutable_atom_family`) {
|
|
2103
|
-
const
|
|
2142
|
+
const familyToken = tokenOrFamily;
|
|
2143
|
+
const family = withdraw(familyToken, store);
|
|
2144
|
+
if (family === void 0) {
|
|
2145
|
+
store.logger.error(
|
|
2146
|
+
`\u274C`,
|
|
2147
|
+
`timeline`,
|
|
2148
|
+
options.key,
|
|
2149
|
+
`Failed to add family "${familyToken.key}" because it does not exist in the store`
|
|
2150
|
+
);
|
|
2151
|
+
continue;
|
|
2152
|
+
}
|
|
2104
2153
|
const familyKey = family.key;
|
|
2105
2154
|
target.timelineAtoms.set({ atomKey: familyKey, timelineKey });
|
|
2106
2155
|
family.subject.subscribe(`timeline:${options.key}`, (token2) => {
|
|
@@ -2253,6 +2302,36 @@ var abortTransaction = (store) => {
|
|
|
2253
2302
|
target.parent.child = null;
|
|
2254
2303
|
};
|
|
2255
2304
|
|
|
2305
|
+
// internal/src/transaction/act-upon-store.ts
|
|
2306
|
+
function actUponStore(token, id, store) {
|
|
2307
|
+
return (...parameters) => {
|
|
2308
|
+
const tx = withdraw(token, store);
|
|
2309
|
+
if (tx) {
|
|
2310
|
+
return tx.run(parameters, id);
|
|
2311
|
+
}
|
|
2312
|
+
throw new NotFoundError(token, store);
|
|
2313
|
+
};
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
// internal/src/transaction/set-epoch-number.ts
|
|
2317
|
+
function setEpochNumberOfContinuity(continuityKey, newEpoch, store) {
|
|
2318
|
+
const isRoot = isRootStore(store);
|
|
2319
|
+
if (isRoot && continuityKey) {
|
|
2320
|
+
store.transactionMeta.epoch.set(continuityKey, newEpoch);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
function setEpochNumberOfAction(transactionKey, newEpoch, store) {
|
|
2324
|
+
const isRoot = isRootStore(store);
|
|
2325
|
+
if (!isRoot) {
|
|
2326
|
+
return;
|
|
2327
|
+
}
|
|
2328
|
+
const continuityKey = store.transactionMeta.actionContinuities.getRelatedKey(transactionKey);
|
|
2329
|
+
if (continuityKey !== void 0) {
|
|
2330
|
+
store.transactionMeta.epoch.set(continuityKey, newEpoch);
|
|
2331
|
+
console.log(`epoch is now`, newEpoch);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2256
2335
|
// internal/src/transaction/apply-transaction.ts
|
|
2257
2336
|
var applyTransaction = (output, store) => {
|
|
2258
2337
|
var _a;
|
|
@@ -2301,7 +2380,12 @@ var applyTransaction = (output, store) => {
|
|
|
2301
2380
|
}
|
|
2302
2381
|
ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
|
|
2303
2382
|
if (isRootStore(parent)) {
|
|
2304
|
-
|
|
2383
|
+
console.log(child.transactionMeta.update);
|
|
2384
|
+
setEpochNumberOfAction(
|
|
2385
|
+
child.transactionMeta.update.key,
|
|
2386
|
+
child.transactionMeta.update.epoch,
|
|
2387
|
+
parent
|
|
2388
|
+
);
|
|
2305
2389
|
const myTransaction = withdraw(
|
|
2306
2390
|
{ key: child.transactionMeta.update.key, type: `transaction` },
|
|
2307
2391
|
store
|
|
@@ -2318,6 +2402,21 @@ var applyTransaction = (output, store) => {
|
|
|
2318
2402
|
}
|
|
2319
2403
|
parent.on.transactionApplying.next(null);
|
|
2320
2404
|
};
|
|
2405
|
+
|
|
2406
|
+
// internal/src/transaction/assign-transaction-to-continuity.ts
|
|
2407
|
+
function assignTransactionToContinuity(continuityKey, transactionKey, store) {
|
|
2408
|
+
const isRoot = isRootStore(store);
|
|
2409
|
+
if (!isRoot) {
|
|
2410
|
+
return;
|
|
2411
|
+
}
|
|
2412
|
+
const { epoch, actionContinuities } = store.transactionMeta;
|
|
2413
|
+
actionContinuities.set(continuityKey, transactionKey);
|
|
2414
|
+
if (!epoch.has(continuityKey)) {
|
|
2415
|
+
epoch.set(continuityKey, -1);
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// internal/src/transaction/build-transaction.ts
|
|
2321
2420
|
var buildTransaction = (key, params, store, id) => {
|
|
2322
2421
|
const parent = newest(store);
|
|
2323
2422
|
const childBase = {
|
|
@@ -2343,20 +2442,21 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2343
2442
|
selectors: new LazyMap(parent.selectors),
|
|
2344
2443
|
valueMap: new LazyMap(parent.valueMap)
|
|
2345
2444
|
};
|
|
2445
|
+
const epoch = getEpochNumberOfAction(key, store);
|
|
2346
2446
|
const transactionMeta = {
|
|
2347
2447
|
phase: `building`,
|
|
2348
2448
|
update: {
|
|
2349
2449
|
key,
|
|
2350
|
-
id
|
|
2351
|
-
epoch:
|
|
2450
|
+
id,
|
|
2451
|
+
epoch: epoch === void 0 ? NaN : epoch + 1,
|
|
2352
2452
|
updates: [],
|
|
2353
2453
|
params,
|
|
2354
2454
|
output: void 0
|
|
2355
2455
|
},
|
|
2356
2456
|
transactors: {
|
|
2357
|
-
get: (token) =>
|
|
2358
|
-
set: (token, value) =>
|
|
2359
|
-
run: (token, id2) =>
|
|
2457
|
+
get: (token) => getFromStore(token, child),
|
|
2458
|
+
set: (token, value) => setIntoStore(token, value, child),
|
|
2459
|
+
run: (token, id2 = arbitrary()) => actUponStore(token, id2, child),
|
|
2360
2460
|
find: (token, key2) => findInStore(token, key2, child),
|
|
2361
2461
|
env: () => getEnvironmentData(child)
|
|
2362
2462
|
}
|
|
@@ -2404,6 +2504,24 @@ function createTransaction(options, store) {
|
|
|
2404
2504
|
return token;
|
|
2405
2505
|
}
|
|
2406
2506
|
|
|
2507
|
+
// internal/src/transaction/get-epoch-number.ts
|
|
2508
|
+
function getContinuityKey(transactionKey, store) {
|
|
2509
|
+
const isRoot = isRootStore(store);
|
|
2510
|
+
const continuity = isRoot ? store.transactionMeta.actionContinuities.getRelatedKey(transactionKey) : void 0;
|
|
2511
|
+
return continuity;
|
|
2512
|
+
}
|
|
2513
|
+
function getEpochNumberOfContinuity(continuityKey, store) {
|
|
2514
|
+
const isRoot = isRootStore(store);
|
|
2515
|
+
const epoch = isRoot && continuityKey ? store.transactionMeta.epoch.get(continuityKey) : void 0;
|
|
2516
|
+
return epoch;
|
|
2517
|
+
}
|
|
2518
|
+
function getEpochNumberOfAction(transactionKey, store) {
|
|
2519
|
+
const isRoot = isRootStore(store);
|
|
2520
|
+
const continuity = isRoot ? store.transactionMeta.actionContinuities.getRelatedKey(transactionKey) : void 0;
|
|
2521
|
+
const epoch = isRoot && continuity !== void 0 ? store.transactionMeta.epoch.get(continuity) : void 0;
|
|
2522
|
+
return epoch;
|
|
2523
|
+
}
|
|
2524
|
+
|
|
2407
2525
|
// internal/src/transaction/index.ts
|
|
2408
2526
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2409
2527
|
|
|
@@ -2418,8 +2536,11 @@ exports.Subject = Subject;
|
|
|
2418
2536
|
exports.TRANSACTION_PHASES = TRANSACTION_PHASES;
|
|
2419
2537
|
exports.Tracker = Tracker;
|
|
2420
2538
|
exports.abortTransaction = abortTransaction;
|
|
2539
|
+
exports.actUponStore = actUponStore;
|
|
2421
2540
|
exports.addAtomToTimeline = addAtomToTimeline;
|
|
2422
2541
|
exports.applyTransaction = applyTransaction;
|
|
2542
|
+
exports.arbitrary = arbitrary;
|
|
2543
|
+
exports.assignTransactionToContinuity = assignTransactionToContinuity;
|
|
2423
2544
|
exports.become = become;
|
|
2424
2545
|
exports.buildTransaction = buildTransaction;
|
|
2425
2546
|
exports.cacheValue = cacheValue;
|
|
@@ -2443,7 +2564,11 @@ exports.deleteSelector = deleteSelector;
|
|
|
2443
2564
|
exports.deposit = deposit;
|
|
2444
2565
|
exports.evictCachedValue = evictCachedValue;
|
|
2445
2566
|
exports.findInStore = findInStore;
|
|
2567
|
+
exports.getContinuityKey = getContinuityKey;
|
|
2446
2568
|
exports.getEnvironmentData = getEnvironmentData;
|
|
2569
|
+
exports.getEpochNumberOfAction = getEpochNumberOfAction;
|
|
2570
|
+
exports.getEpochNumberOfContinuity = getEpochNumberOfContinuity;
|
|
2571
|
+
exports.getFromStore = getFromStore;
|
|
2447
2572
|
exports.getJsonFamily = getJsonFamily;
|
|
2448
2573
|
exports.getJsonToken = getJsonToken;
|
|
2449
2574
|
exports.getSelectorDependencyKeys = getSelectorDependencyKeys;
|
|
@@ -2453,9 +2578,11 @@ exports.ingestSelectorUpdate = ingestSelectorUpdate;
|
|
|
2453
2578
|
exports.ingestTransactionUpdate = ingestTransactionUpdate;
|
|
2454
2579
|
exports.isAtomDefault = isAtomDefault;
|
|
2455
2580
|
exports.isAtomKey = isAtomKey;
|
|
2581
|
+
exports.isChildStore = isChildStore;
|
|
2456
2582
|
exports.isDone = isDone;
|
|
2457
2583
|
exports.isMutable = isMutable;
|
|
2458
2584
|
exports.isReadonlySelectorKey = isReadonlySelectorKey;
|
|
2585
|
+
exports.isRootStore = isRootStore;
|
|
2459
2586
|
exports.isSelectorKey = isSelectorKey;
|
|
2460
2587
|
exports.isStateKey = isStateKey;
|
|
2461
2588
|
exports.isTransceiver = isTransceiver;
|
|
@@ -2468,6 +2595,9 @@ exports.readCachedValue = readCachedValue;
|
|
|
2468
2595
|
exports.readOrComputeValue = readOrComputeValue;
|
|
2469
2596
|
exports.registerSelector = registerSelector;
|
|
2470
2597
|
exports.setAtomOrSelector = setAtomOrSelector;
|
|
2598
|
+
exports.setEpochNumberOfAction = setEpochNumberOfAction;
|
|
2599
|
+
exports.setEpochNumberOfContinuity = setEpochNumberOfContinuity;
|
|
2600
|
+
exports.setIntoStore = setIntoStore;
|
|
2471
2601
|
exports.subscribeToRootAtoms = subscribeToRootAtoms;
|
|
2472
2602
|
exports.subscribeToState = subscribeToState;
|
|
2473
2603
|
exports.subscribeToTimeline = subscribeToTimeline;
|