atom.io 0.16.2 → 0.16.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-H4Q5FTPZ.js +11 -0
- package/dist/chunk-H4Q5FTPZ.js.map +1 -0
- package/dist/index.cjs +1 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +2 -11
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +225 -183
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +30 -9
- package/internal/dist/index.js +218 -184
- package/internal/dist/index.js.map +1 -1
- package/internal/src/families/find-in-store.ts +74 -0
- package/internal/src/families/index.ts +1 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +1 -0
- package/internal/src/mutable/tracker.ts +28 -25
- package/internal/src/mutable/transceiver.ts +1 -1
- package/internal/src/not-found-error.ts +14 -3
- package/internal/src/operation.ts +2 -1
- package/internal/src/selector/create-writable-selector.ts +2 -1
- package/internal/src/selector/register-selector.ts +5 -4
- package/internal/src/set-state/set-atom.ts +16 -2
- package/internal/src/set-state/stow-update.ts +2 -4
- package/internal/src/store/store.ts +13 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +5 -5
- package/internal/src/transaction/abort-transaction.ts +2 -1
- package/internal/src/transaction/apply-transaction.ts +5 -3
- package/internal/src/transaction/build-transaction.ts +16 -9
- package/internal/src/transaction/create-transaction.ts +2 -3
- package/internal/src/transaction/index.ts +3 -2
- package/internal/src/transaction/is-root-store.ts +23 -0
- package/package.json +10 -10
- package/react/dist/index.cjs +27 -21
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +8 -2
- package/react/dist/index.js +27 -21
- package/react/dist/index.js.map +1 -1
- package/react/src/index.ts +4 -1
- package/react/src/use-i.ts +36 -0
- package/react/src/use-json.ts +38 -0
- package/react/src/use-o.ts +34 -0
- package/react/src/use-tl.ts +45 -0
- package/realtime-client/dist/index.cjs +163 -63
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +10 -6
- package/realtime-client/dist/index.js +153 -61
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +2 -1
- package/realtime-client/src/pull-state.ts +4 -3
- package/realtime-client/src/{realtime-client-store.ts → realtime-client-stores/client-main-store.ts} +0 -8
- package/realtime-client/src/realtime-client-stores/client-sync-store.ts +15 -0
- package/realtime-client/src/realtime-client-stores/index.ts +2 -0
- package/realtime-client/src/sync-server-action.ts +131 -40
- package/realtime-client/src/sync-state.ts +19 -0
- package/realtime-react/dist/index.cjs +43 -26
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +3 -1
- package/realtime-react/dist/index.js +41 -25
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/index.ts +1 -0
- package/realtime-react/src/on-mount.ts +3 -21
- package/realtime-react/src/use-realtime-service.ts +1 -1
- package/realtime-react/src/use-single-effect.ts +29 -0
- package/realtime-react/src/use-sync-server-action.ts +4 -7
- package/realtime-react/src/use-sync.ts +17 -0
- package/realtime-server/dist/index.cjs +223 -40
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +140 -9
- package/realtime-server/dist/index.js +213 -43
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/index.ts +2 -0
- package/realtime-server/src/realtime-action-synchronizer.ts +87 -12
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -1
- package/realtime-server/src/realtime-server-stores/index.ts +2 -0
- package/realtime-server/src/realtime-server-stores/server-sync-store.ts +115 -0
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +45 -0
- package/realtime-server/src/realtime-state-provider.ts +15 -8
- package/realtime-server/src/realtime-state-synchronizer.ts +23 -0
- package/realtime-testing/dist/index.cjs +65 -26
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.ts +11 -7
- package/realtime-testing/dist/index.js +64 -26
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +83 -43
- package/src/find-state.ts +8 -16
- package/src/logger.ts +1 -0
- package/src/transaction.ts +3 -3
- package/react/src/store-hooks.ts +0 -87
- package/realtime-server/src/realtime-server-store.ts +0 -39
package/internal/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Junction } from '../../dist/chunk-NYTGCPHB.js';
|
|
2
|
+
import { isChildStore, isRootStore } from '../../dist/chunk-H4Q5FTPZ.js';
|
|
2
3
|
import { __spreadValues, __spreadProps } from '../../dist/chunk-PZLG2HP3.js';
|
|
3
|
-
import { AtomIOLogger,
|
|
4
|
-
import {
|
|
4
|
+
import { AtomIOLogger, getState, setState, runTransaction } from 'atom.io';
|
|
5
|
+
import { stringifyJson, selectJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
5
6
|
import { withdraw as withdraw$1 } from 'atom.io/internal';
|
|
6
7
|
|
|
7
8
|
// internal/src/lineage.ts
|
|
@@ -91,11 +92,15 @@ var Store = class {
|
|
|
91
92
|
selectorCreation: new Subject(),
|
|
92
93
|
transactionCreation: new Subject(),
|
|
93
94
|
timelineCreation: new Subject(),
|
|
94
|
-
transactionApplying: new StatefulSubject(
|
|
95
|
+
transactionApplying: new StatefulSubject(
|
|
96
|
+
null
|
|
97
|
+
),
|
|
95
98
|
operationClose: new Subject()
|
|
96
99
|
};
|
|
97
100
|
this.operation = { open: false };
|
|
98
|
-
this.transactionMeta =
|
|
101
|
+
this.transactionMeta = {
|
|
102
|
+
epoch: -1
|
|
103
|
+
};
|
|
99
104
|
this.config = {
|
|
100
105
|
name: `IMPLICIT_STORE`
|
|
101
106
|
};
|
|
@@ -119,7 +124,7 @@ var Store = class {
|
|
|
119
124
|
if (store !== null) {
|
|
120
125
|
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
121
126
|
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
122
|
-
this.transactionMeta = null;
|
|
127
|
+
this.transactionMeta = __spreadValues({}, store == null ? void 0 : store.transactionMeta);
|
|
123
128
|
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
124
129
|
name
|
|
125
130
|
});
|
|
@@ -332,6 +337,150 @@ var readOrComputeValue = (state, target) => {
|
|
|
332
337
|
);
|
|
333
338
|
return state.default instanceof Function ? state.default() : state.default;
|
|
334
339
|
};
|
|
340
|
+
function createRegularAtomFamily(options, store) {
|
|
341
|
+
const subject = new Subject();
|
|
342
|
+
const atomFamily = Object.assign(
|
|
343
|
+
(key) => {
|
|
344
|
+
const subKey = stringifyJson(key);
|
|
345
|
+
const family = { key: options.key, subKey };
|
|
346
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
347
|
+
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
348
|
+
let token;
|
|
349
|
+
if (existing) {
|
|
350
|
+
token = deposit(existing);
|
|
351
|
+
} else {
|
|
352
|
+
const individualOptions = {
|
|
353
|
+
key: fullKey,
|
|
354
|
+
default: options.default instanceof Function ? options.default(key) : options.default
|
|
355
|
+
};
|
|
356
|
+
if (options.effects) {
|
|
357
|
+
individualOptions.effects = options.effects(key);
|
|
358
|
+
}
|
|
359
|
+
token = createRegularAtom(individualOptions, family, store);
|
|
360
|
+
subject.next(token);
|
|
361
|
+
}
|
|
362
|
+
return token;
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
key: options.key,
|
|
366
|
+
type: `atom_family`,
|
|
367
|
+
subject,
|
|
368
|
+
install: (store2) => createRegularAtomFamily(options, store2)
|
|
369
|
+
}
|
|
370
|
+
);
|
|
371
|
+
const target = newest(store);
|
|
372
|
+
target.families.set(options.key, atomFamily);
|
|
373
|
+
return atomFamily;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// internal/src/families/create-atom-family.ts
|
|
377
|
+
function createAtomFamily(options, store) {
|
|
378
|
+
const isMutable2 = `mutable` in options;
|
|
379
|
+
if (isMutable2) {
|
|
380
|
+
return createMutableAtomFamily(options, store);
|
|
381
|
+
}
|
|
382
|
+
return createRegularAtomFamily(options, store);
|
|
383
|
+
}
|
|
384
|
+
function createReadonlySelectorFamily(options, store) {
|
|
385
|
+
const subject = new Subject();
|
|
386
|
+
const readonlySelectorFamily = Object.assign(
|
|
387
|
+
(key) => {
|
|
388
|
+
const target = newest(store);
|
|
389
|
+
const subKey = stringifyJson(key);
|
|
390
|
+
const family = { key: options.key, subKey };
|
|
391
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
392
|
+
const existing = target.readonlySelectors.get(fullKey);
|
|
393
|
+
if (existing) {
|
|
394
|
+
return deposit(existing);
|
|
395
|
+
}
|
|
396
|
+
return createReadonlySelector(
|
|
397
|
+
{
|
|
398
|
+
key: fullKey,
|
|
399
|
+
get: options.get(key)
|
|
400
|
+
},
|
|
401
|
+
family,
|
|
402
|
+
store
|
|
403
|
+
);
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
key: options.key,
|
|
407
|
+
type: `readonly_selector_family`,
|
|
408
|
+
subject,
|
|
409
|
+
install: (store2) => createReadonlySelectorFamily(options, store2)
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
store.families.set(options.key, readonlySelectorFamily);
|
|
413
|
+
return readonlySelectorFamily;
|
|
414
|
+
}
|
|
415
|
+
function createWritableSelectorFamily(options, store) {
|
|
416
|
+
const subject = new Subject();
|
|
417
|
+
const selectorFamily = Object.assign(
|
|
418
|
+
(key) => {
|
|
419
|
+
const subKey = stringifyJson(key);
|
|
420
|
+
const family = { key: options.key, subKey };
|
|
421
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
422
|
+
const existing = store.selectors.get(fullKey);
|
|
423
|
+
if (existing) {
|
|
424
|
+
return deposit(existing);
|
|
425
|
+
}
|
|
426
|
+
const token = createWritableSelector(
|
|
427
|
+
{
|
|
428
|
+
key: fullKey,
|
|
429
|
+
get: options.get(key),
|
|
430
|
+
set: options.set(key)
|
|
431
|
+
},
|
|
432
|
+
family,
|
|
433
|
+
store
|
|
434
|
+
);
|
|
435
|
+
subject.next(token);
|
|
436
|
+
return token;
|
|
437
|
+
},
|
|
438
|
+
{
|
|
439
|
+
key: options.key,
|
|
440
|
+
type: `selector_family`,
|
|
441
|
+
subject,
|
|
442
|
+
install: (store2) => createWritableSelectorFamily(options, store2)
|
|
443
|
+
}
|
|
444
|
+
);
|
|
445
|
+
store.families.set(options.key, selectorFamily);
|
|
446
|
+
return selectorFamily;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// internal/src/families/create-selector-family.ts
|
|
450
|
+
function createSelectorFamily(options, store) {
|
|
451
|
+
const isWritable = `set` in options;
|
|
452
|
+
if (isWritable) {
|
|
453
|
+
return createWritableSelectorFamily(options, store);
|
|
454
|
+
}
|
|
455
|
+
return createReadonlySelectorFamily(options, store);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// internal/src/not-found-error.ts
|
|
459
|
+
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
460
|
+
function prettyPrintTokenType(token) {
|
|
461
|
+
if (token.type === `readonly_selector`) {
|
|
462
|
+
return `Readonly Selector`;
|
|
463
|
+
}
|
|
464
|
+
return capitalize(token.type);
|
|
465
|
+
}
|
|
466
|
+
var NotFoundError = class extends Error {
|
|
467
|
+
constructor(token, store) {
|
|
468
|
+
super(
|
|
469
|
+
`${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
// internal/src/families/find-in-store.ts
|
|
475
|
+
function findInStore(token, key, store) {
|
|
476
|
+
const familyKey = token.key;
|
|
477
|
+
const family = store.families.get(familyKey);
|
|
478
|
+
if (family === void 0) {
|
|
479
|
+
throw new NotFoundError(token, store);
|
|
480
|
+
}
|
|
481
|
+
const state = family(key);
|
|
482
|
+
return state;
|
|
483
|
+
}
|
|
335
484
|
|
|
336
485
|
// internal/src/set-state/become.ts
|
|
337
486
|
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
@@ -360,7 +509,7 @@ var openOperation = (token, store) => {
|
|
|
360
509
|
`\u2B55`,
|
|
361
510
|
token.type,
|
|
362
511
|
token.key,
|
|
363
|
-
`operation start in store "${store.config.name}"${store
|
|
512
|
+
`operation start in store "${store.config.name}"${!isChildStore(store) ? `` : ` ${store.transactionMeta.phase} "${store.transactionMeta.update.key}"`}`
|
|
364
513
|
);
|
|
365
514
|
};
|
|
366
515
|
var closeOperation = (store) => {
|
|
@@ -458,7 +607,7 @@ function shouldUpdateBeStowed(key, update) {
|
|
|
458
607
|
var stowUpdate = (state, update, store) => {
|
|
459
608
|
const { key } = state;
|
|
460
609
|
const target = newest(store);
|
|
461
|
-
if (target
|
|
610
|
+
if (!isChildStore(target) || target.transactionMeta.phase !== `building`) {
|
|
462
611
|
store.logger.error(
|
|
463
612
|
`\u{1F41E}`,
|
|
464
613
|
`atom`,
|
|
@@ -501,7 +650,7 @@ var setAtom = (atom, next, target) => {
|
|
|
501
650
|
markDone(atom.key, target);
|
|
502
651
|
evictDownStream(atom, target);
|
|
503
652
|
const update = { oldValue, newValue };
|
|
504
|
-
if (target
|
|
653
|
+
if (isRootStore(target)) {
|
|
505
654
|
emitUpdate(atom, update, target);
|
|
506
655
|
} else if (target.parent) {
|
|
507
656
|
if (target.on.transactionApplying.state === null) {
|
|
@@ -511,7 +660,16 @@ var setAtom = (atom, next, target) => {
|
|
|
511
660
|
const mutableAtom = target.atoms.get(mutableKey);
|
|
512
661
|
let mutable = target.valueMap.get(mutableKey);
|
|
513
662
|
mutable = copyMutableIfWithinTransaction(mutable, mutableAtom, target);
|
|
514
|
-
mutable.do(update.newValue);
|
|
663
|
+
const output = mutable.do(update.newValue);
|
|
664
|
+
if (output !== null) {
|
|
665
|
+
target.logger.warn(
|
|
666
|
+
`\u274C`,
|
|
667
|
+
`mutable_atom`,
|
|
668
|
+
mutableKey,
|
|
669
|
+
`could not be updated.`,
|
|
670
|
+
typeof output === `number` ? `Expected update number ${mutable.cacheUpdateNumber + 1}, but got ${output}` : output
|
|
671
|
+
);
|
|
672
|
+
}
|
|
515
673
|
}
|
|
516
674
|
}
|
|
517
675
|
};
|
|
@@ -609,11 +767,12 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
609
767
|
// internal/src/selector/register-selector.ts
|
|
610
768
|
var registerSelector = (selectorKey, store) => ({
|
|
611
769
|
get: (dependency) => {
|
|
770
|
+
var _a;
|
|
612
771
|
const target = newest(store);
|
|
613
|
-
const dependencyState = withdraw(dependency, store);
|
|
772
|
+
const dependencyState = (_a = withdraw(dependency, store)) != null ? _a : withdrawNewFamilyMember(dependency, store);
|
|
614
773
|
if (dependencyState === void 0) {
|
|
615
774
|
throw new Error(
|
|
616
|
-
`State "${dependency.key}" not found in
|
|
775
|
+
`State "${dependency.key}" not found in store "${store.config.name}".`
|
|
617
776
|
);
|
|
618
777
|
}
|
|
619
778
|
const dependencyValue = readOrComputeValue(dependencyState, store);
|
|
@@ -712,7 +871,7 @@ var createWritableSelector = (options, family, store) => {
|
|
|
712
871
|
);
|
|
713
872
|
cacheValue(options.key, newValue, subject, store);
|
|
714
873
|
markDone(options.key, store);
|
|
715
|
-
if (target
|
|
874
|
+
if (isRootStore(target)) {
|
|
716
875
|
subject.next({ newValue, oldValue });
|
|
717
876
|
}
|
|
718
877
|
options.set(transactors, newValue);
|
|
@@ -930,12 +1089,11 @@ var Tracker = class {
|
|
|
930
1089
|
}
|
|
931
1090
|
return latestUpdateState;
|
|
932
1091
|
}
|
|
933
|
-
observeCore(mutableState, latestUpdateState,
|
|
934
|
-
const subscriptionKey = `tracker:${
|
|
935
|
-
const originalInnerValue = getState(mutableState,
|
|
936
|
-
const target = newest(store);
|
|
1092
|
+
observeCore(mutableState, latestUpdateState, target) {
|
|
1093
|
+
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
1094
|
+
const originalInnerValue = getState(mutableState, target);
|
|
937
1095
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
938
|
-
|
|
1096
|
+
subscriptionKey,
|
|
939
1097
|
(update) => {
|
|
940
1098
|
if (target.operation.open) {
|
|
941
1099
|
const unsubscribe = target.on.operationClose.subscribe(
|
|
@@ -956,40 +1114,39 @@ var Tracker = class {
|
|
|
956
1114
|
(update) => {
|
|
957
1115
|
if (update.newValue !== update.oldValue) {
|
|
958
1116
|
this.unsubscribeFromInnerValue();
|
|
959
|
-
const target2 = newest(store);
|
|
960
1117
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
961
1118
|
subscriptionKey,
|
|
962
1119
|
(update2) => {
|
|
963
|
-
if (
|
|
964
|
-
const unsubscribe =
|
|
1120
|
+
if (target.operation.open) {
|
|
1121
|
+
const unsubscribe = target.on.operationClose.subscribe(
|
|
965
1122
|
subscriptionKey,
|
|
966
1123
|
() => {
|
|
967
1124
|
unsubscribe();
|
|
968
|
-
setState(latestUpdateState, update2,
|
|
1125
|
+
setState(latestUpdateState, update2, target);
|
|
969
1126
|
}
|
|
970
1127
|
);
|
|
971
1128
|
} else {
|
|
972
|
-
setState(mutableState, (current) => current,
|
|
973
|
-
setState(latestUpdateState, update2,
|
|
1129
|
+
setState(mutableState, (current) => current, target);
|
|
1130
|
+
setState(latestUpdateState, update2, target);
|
|
974
1131
|
}
|
|
975
1132
|
}
|
|
976
1133
|
);
|
|
977
1134
|
}
|
|
978
1135
|
},
|
|
979
1136
|
subscriptionKey,
|
|
980
|
-
|
|
1137
|
+
target
|
|
981
1138
|
);
|
|
982
1139
|
}
|
|
983
|
-
updateCore(mutableState, latestUpdateState,
|
|
984
|
-
const subscriptionKey = `tracker:${
|
|
1140
|
+
updateCore(mutableState, latestUpdateState, target) {
|
|
1141
|
+
const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.key : `main`}:${mutableState.key}`;
|
|
985
1142
|
subscribeToState(
|
|
986
1143
|
latestUpdateState,
|
|
987
1144
|
({ newValue, oldValue }) => {
|
|
988
|
-
const timelineId =
|
|
1145
|
+
const timelineId = target.timelineAtoms.getRelatedKey(
|
|
989
1146
|
latestUpdateState.key
|
|
990
1147
|
);
|
|
991
1148
|
if (timelineId) {
|
|
992
|
-
const timelineData =
|
|
1149
|
+
const timelineData = target.timelines.get(timelineId);
|
|
993
1150
|
if (timelineData == null ? void 0 : timelineData.timeTraveling) {
|
|
994
1151
|
const unsubscribe2 = subscribeToTimeline(
|
|
995
1152
|
{ key: timelineId, type: `timeline` },
|
|
@@ -1005,34 +1162,41 @@ var Tracker = class {
|
|
|
1005
1162
|
}
|
|
1006
1163
|
return transceiver;
|
|
1007
1164
|
},
|
|
1008
|
-
|
|
1165
|
+
target
|
|
1009
1166
|
);
|
|
1010
1167
|
},
|
|
1011
1168
|
subscriptionKey,
|
|
1012
|
-
|
|
1169
|
+
target
|
|
1013
1170
|
);
|
|
1014
1171
|
return;
|
|
1015
1172
|
}
|
|
1016
1173
|
}
|
|
1017
|
-
const unsubscribe =
|
|
1174
|
+
const unsubscribe = target.on.operationClose.subscribe(
|
|
1018
1175
|
subscriptionKey,
|
|
1019
1176
|
() => {
|
|
1020
1177
|
unsubscribe();
|
|
1021
|
-
const mutable = getState(mutableState,
|
|
1178
|
+
const mutable = getState(mutableState, target);
|
|
1022
1179
|
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1023
1180
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1024
1181
|
if (newValue && eventOffset === 1) {
|
|
1025
1182
|
setState(
|
|
1026
1183
|
mutableState,
|
|
1027
1184
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1028
|
-
|
|
1185
|
+
target
|
|
1186
|
+
);
|
|
1187
|
+
} else {
|
|
1188
|
+
target.logger.info(
|
|
1189
|
+
`\u274C`,
|
|
1190
|
+
`mutable_atom`,
|
|
1191
|
+
mutableState.key,
|
|
1192
|
+
`could not be updated. Expected update number ${mutable.cacheUpdateNumber + 1}, but got ${updateNumber}`
|
|
1029
1193
|
);
|
|
1030
1194
|
}
|
|
1031
1195
|
}
|
|
1032
1196
|
);
|
|
1033
1197
|
},
|
|
1034
1198
|
subscriptionKey,
|
|
1035
|
-
|
|
1199
|
+
target
|
|
1036
1200
|
);
|
|
1037
1201
|
}
|
|
1038
1202
|
constructor(mutableState, store) {
|
|
@@ -1115,125 +1279,6 @@ function createMutableAtom(options, family, store) {
|
|
|
1115
1279
|
store.on.atomCreation.next(token);
|
|
1116
1280
|
return token;
|
|
1117
1281
|
}
|
|
1118
|
-
function createRegularAtomFamily(options, store) {
|
|
1119
|
-
const subject = new Subject();
|
|
1120
|
-
const atomFamily = Object.assign(
|
|
1121
|
-
(key) => {
|
|
1122
|
-
const subKey = stringifyJson(key);
|
|
1123
|
-
const family = { key: options.key, subKey };
|
|
1124
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1125
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
1126
|
-
let token;
|
|
1127
|
-
if (existing) {
|
|
1128
|
-
token = deposit(existing);
|
|
1129
|
-
} else {
|
|
1130
|
-
const individualOptions = {
|
|
1131
|
-
key: fullKey,
|
|
1132
|
-
default: options.default instanceof Function ? options.default(key) : options.default
|
|
1133
|
-
};
|
|
1134
|
-
if (options.effects) {
|
|
1135
|
-
individualOptions.effects = options.effects(key);
|
|
1136
|
-
}
|
|
1137
|
-
token = createRegularAtom(individualOptions, family, store);
|
|
1138
|
-
subject.next(token);
|
|
1139
|
-
}
|
|
1140
|
-
return token;
|
|
1141
|
-
},
|
|
1142
|
-
{
|
|
1143
|
-
key: options.key,
|
|
1144
|
-
type: `atom_family`,
|
|
1145
|
-
subject,
|
|
1146
|
-
install: (store2) => createRegularAtomFamily(options, store2)
|
|
1147
|
-
}
|
|
1148
|
-
);
|
|
1149
|
-
const target = newest(store);
|
|
1150
|
-
target.families.set(options.key, atomFamily);
|
|
1151
|
-
return atomFamily;
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
// internal/src/families/create-atom-family.ts
|
|
1155
|
-
function createAtomFamily(options, store) {
|
|
1156
|
-
const isMutable2 = `mutable` in options;
|
|
1157
|
-
if (isMutable2) {
|
|
1158
|
-
return createMutableAtomFamily(options, store);
|
|
1159
|
-
}
|
|
1160
|
-
return createRegularAtomFamily(options, store);
|
|
1161
|
-
}
|
|
1162
|
-
function createReadonlySelectorFamily(options, store) {
|
|
1163
|
-
const subject = new Subject();
|
|
1164
|
-
const readonlySelectorFamily = Object.assign(
|
|
1165
|
-
(key) => {
|
|
1166
|
-
const target = newest(store);
|
|
1167
|
-
const subKey = stringifyJson(key);
|
|
1168
|
-
const family = { key: options.key, subKey };
|
|
1169
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1170
|
-
const existing = target.readonlySelectors.get(fullKey);
|
|
1171
|
-
if (existing) {
|
|
1172
|
-
return deposit(existing);
|
|
1173
|
-
}
|
|
1174
|
-
return createReadonlySelector(
|
|
1175
|
-
{
|
|
1176
|
-
key: fullKey,
|
|
1177
|
-
get: options.get(key)
|
|
1178
|
-
},
|
|
1179
|
-
family,
|
|
1180
|
-
store
|
|
1181
|
-
);
|
|
1182
|
-
},
|
|
1183
|
-
{
|
|
1184
|
-
key: options.key,
|
|
1185
|
-
type: `readonly_selector_family`,
|
|
1186
|
-
subject,
|
|
1187
|
-
install: (store2) => createReadonlySelectorFamily(options, store2)
|
|
1188
|
-
}
|
|
1189
|
-
);
|
|
1190
|
-
store.families.set(options.key, readonlySelectorFamily);
|
|
1191
|
-
return readonlySelectorFamily;
|
|
1192
|
-
}
|
|
1193
|
-
function createWritableSelectorFamily(options, store) {
|
|
1194
|
-
const subject = new Subject();
|
|
1195
|
-
const selectorFamily = Object.assign(
|
|
1196
|
-
(key) => {
|
|
1197
|
-
const subKey = stringifyJson(key);
|
|
1198
|
-
const family = { key: options.key, subKey };
|
|
1199
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1200
|
-
const existing = store.selectors.get(fullKey);
|
|
1201
|
-
if (existing) {
|
|
1202
|
-
return deposit(existing);
|
|
1203
|
-
}
|
|
1204
|
-
const token = createWritableSelector(
|
|
1205
|
-
{
|
|
1206
|
-
key: fullKey,
|
|
1207
|
-
get: options.get(key),
|
|
1208
|
-
set: options.set(key)
|
|
1209
|
-
},
|
|
1210
|
-
family,
|
|
1211
|
-
store
|
|
1212
|
-
);
|
|
1213
|
-
subject.next(token);
|
|
1214
|
-
return token;
|
|
1215
|
-
},
|
|
1216
|
-
{
|
|
1217
|
-
key: options.key,
|
|
1218
|
-
type: `selector_family`,
|
|
1219
|
-
subject,
|
|
1220
|
-
install: (store2) => createWritableSelectorFamily(options, store2)
|
|
1221
|
-
}
|
|
1222
|
-
);
|
|
1223
|
-
store.families.set(options.key, selectorFamily);
|
|
1224
|
-
return selectorFamily;
|
|
1225
|
-
}
|
|
1226
|
-
|
|
1227
|
-
// internal/src/families/create-selector-family.ts
|
|
1228
|
-
function createSelectorFamily(options, store) {
|
|
1229
|
-
const isWritable = `set` in options;
|
|
1230
|
-
if (isWritable) {
|
|
1231
|
-
return createWritableSelectorFamily(options, store);
|
|
1232
|
-
}
|
|
1233
|
-
return createReadonlySelectorFamily(options, store);
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
// internal/src/mutable/tracker-family.ts
|
|
1237
1282
|
var FamilyTracker = class {
|
|
1238
1283
|
constructor(findMutableState, store) {
|
|
1239
1284
|
this.findLatestUpdateState = createRegularAtomFamily(
|
|
@@ -1548,22 +1593,6 @@ var LazyMap = class extends Map {
|
|
|
1548
1593
|
}
|
|
1549
1594
|
};
|
|
1550
1595
|
|
|
1551
|
-
// internal/src/not-found-error.ts
|
|
1552
|
-
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1553
|
-
function prettyPrintTokenType(token) {
|
|
1554
|
-
if (token.type === `readonly_selector`) {
|
|
1555
|
-
return `Readonly Selector`;
|
|
1556
|
-
}
|
|
1557
|
-
return capitalize(token.type);
|
|
1558
|
-
}
|
|
1559
|
-
var NotFoundError = class extends Error {
|
|
1560
|
-
constructor(token, store) {
|
|
1561
|
-
super(
|
|
1562
|
-
`${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
|
|
1563
|
-
);
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
|
|
1567
1596
|
// internal/src/timeline/add-atom-to-timeline.ts
|
|
1568
1597
|
var addAtomToTimeline = (atomToken, tl, store) => {
|
|
1569
1598
|
let maybeAtom = withdraw(atomToken, store);
|
|
@@ -1583,8 +1612,9 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1583
1612
|
const target = newest(store);
|
|
1584
1613
|
const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
1585
1614
|
const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
1586
|
-
const
|
|
1587
|
-
const
|
|
1615
|
+
const { transactionApplying } = target.on;
|
|
1616
|
+
const currentTransactionKey = (_a = transactionApplying.state) == null ? void 0 : _a.update.key;
|
|
1617
|
+
const currentTransactionInstanceId = (_b = transactionApplying.state) == null ? void 0 : _b.update.id;
|
|
1588
1618
|
store.logger.info(
|
|
1589
1619
|
`\u23F3`,
|
|
1590
1620
|
`timeline`,
|
|
@@ -1631,7 +1661,7 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1631
1661
|
(update2) => {
|
|
1632
1662
|
var _a2, _b2;
|
|
1633
1663
|
unsubscribe();
|
|
1634
|
-
if (tl.timeTraveling === null &&
|
|
1664
|
+
if (tl.timeTraveling === null && currentTransactionInstanceId) {
|
|
1635
1665
|
if (tl.at !== tl.history.length) {
|
|
1636
1666
|
tl.history.splice(tl.at);
|
|
1637
1667
|
}
|
|
@@ -1658,7 +1688,7 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1658
1688
|
const updates = filterUpdates(update2.updates);
|
|
1659
1689
|
const timelineTransactionUpdate = __spreadProps(__spreadValues({
|
|
1660
1690
|
type: `transaction_update`,
|
|
1661
|
-
timestamp:
|
|
1691
|
+
timestamp: Date.now()
|
|
1662
1692
|
}, update2), {
|
|
1663
1693
|
updates
|
|
1664
1694
|
});
|
|
@@ -1920,7 +1950,7 @@ var timeTravel = (action, token, store) => {
|
|
|
1920
1950
|
// internal/src/transaction/abort-transaction.ts
|
|
1921
1951
|
var abortTransaction = (store) => {
|
|
1922
1952
|
const target = newest(store);
|
|
1923
|
-
if (target
|
|
1953
|
+
if (!isChildStore(target)) {
|
|
1924
1954
|
store.logger.warn(
|
|
1925
1955
|
`\u{1F41E}`,
|
|
1926
1956
|
`transaction`,
|
|
@@ -1943,7 +1973,7 @@ var applyTransaction = (output, store) => {
|
|
|
1943
1973
|
var _a;
|
|
1944
1974
|
const child = newest(store);
|
|
1945
1975
|
const { parent } = child;
|
|
1946
|
-
if (parent === null || child
|
|
1976
|
+
if (parent === null || !isChildStore(child) || ((_a = child.transactionMeta) == null ? void 0 : _a.phase) !== `building`) {
|
|
1947
1977
|
store.logger.warn(
|
|
1948
1978
|
`\u{1F41E}`,
|
|
1949
1979
|
`transaction`,
|
|
@@ -1985,7 +2015,8 @@ var applyTransaction = (output, store) => {
|
|
|
1985
2015
|
}
|
|
1986
2016
|
}
|
|
1987
2017
|
ingestTransactionUpdate(`newValue`, child.transactionMeta.update, parent);
|
|
1988
|
-
if (parent
|
|
2018
|
+
if (isRootStore(parent)) {
|
|
2019
|
+
parent.transactionMeta.epoch = child.transactionMeta.update.epoch;
|
|
1989
2020
|
const myTransaction = withdraw(
|
|
1990
2021
|
{ key: child.transactionMeta.update.key, type: `transaction` },
|
|
1991
2022
|
store
|
|
@@ -1997,21 +2028,20 @@ var applyTransaction = (output, store) => {
|
|
|
1997
2028
|
child.transactionMeta.update.key,
|
|
1998
2029
|
`Finished applying transaction.`
|
|
1999
2030
|
);
|
|
2000
|
-
} else {
|
|
2031
|
+
} else if (isChildStore(parent)) {
|
|
2001
2032
|
parent.transactionMeta.update.updates.push(child.transactionMeta.update);
|
|
2002
2033
|
}
|
|
2003
2034
|
parent.on.transactionApplying.next(null);
|
|
2004
2035
|
};
|
|
2005
2036
|
var buildTransaction = (key, params, store, id) => {
|
|
2006
2037
|
const parent = newest(store);
|
|
2007
|
-
const
|
|
2038
|
+
const childBase = {
|
|
2008
2039
|
parent,
|
|
2009
2040
|
child: null,
|
|
2010
2041
|
on: parent.on,
|
|
2011
2042
|
loggers: parent.loggers,
|
|
2012
2043
|
logger: parent.logger,
|
|
2013
2044
|
config: parent.config,
|
|
2014
|
-
transactionMeta: null,
|
|
2015
2045
|
atoms: new LazyMap(parent.atoms),
|
|
2016
2046
|
atomsThatAreDefault: new Set(parent.atomsThatAreDefault),
|
|
2017
2047
|
families: new LazyMap(parent.families),
|
|
@@ -2028,12 +2058,12 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2028
2058
|
selectors: new LazyMap(parent.selectors),
|
|
2029
2059
|
valueMap: new LazyMap(parent.valueMap)
|
|
2030
2060
|
};
|
|
2031
|
-
|
|
2061
|
+
const transactionMeta = {
|
|
2032
2062
|
phase: `building`,
|
|
2033
|
-
time: Date.now(),
|
|
2034
2063
|
update: {
|
|
2035
2064
|
key,
|
|
2036
2065
|
id: id != null ? id : Math.random().toString(36).slice(2),
|
|
2066
|
+
epoch: isRootStore(parent) ? parent.transactionMeta.epoch + 1 : NaN,
|
|
2037
2067
|
updates: [],
|
|
2038
2068
|
params,
|
|
2039
2069
|
output: void 0
|
|
@@ -2046,6 +2076,9 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2046
2076
|
env: () => getEnvironmentData(child)
|
|
2047
2077
|
}
|
|
2048
2078
|
};
|
|
2079
|
+
const child = Object.assign(childBase, {
|
|
2080
|
+
transactionMeta
|
|
2081
|
+
});
|
|
2049
2082
|
parent.child = child;
|
|
2050
2083
|
store.logger.info(
|
|
2051
2084
|
`\u{1F6EB}`,
|
|
@@ -2054,6 +2087,7 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2054
2087
|
`Building transaction with params:`,
|
|
2055
2088
|
params
|
|
2056
2089
|
);
|
|
2090
|
+
return child;
|
|
2057
2091
|
};
|
|
2058
2092
|
|
|
2059
2093
|
// internal/src/transaction/create-transaction.ts
|
|
@@ -2062,10 +2096,10 @@ function createTransaction(options, store) {
|
|
|
2062
2096
|
key: options.key,
|
|
2063
2097
|
type: `transaction`,
|
|
2064
2098
|
run: (params, id) => {
|
|
2065
|
-
buildTransaction(options.key, params, store, id);
|
|
2099
|
+
const childStore = buildTransaction(options.key, params, store, id);
|
|
2066
2100
|
try {
|
|
2067
2101
|
const target2 = newest(store);
|
|
2068
|
-
const { transactors } =
|
|
2102
|
+
const { transactors } = childStore.transactionMeta;
|
|
2069
2103
|
const output = options.do(transactors, ...params);
|
|
2070
2104
|
applyTransaction(output, target2);
|
|
2071
2105
|
return output;
|
|
@@ -2088,6 +2122,6 @@ function createTransaction(options, store) {
|
|
|
2088
2122
|
// internal/src/transaction/index.ts
|
|
2089
2123
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2090
2124
|
|
|
2091
|
-
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deleteAtom, deleteSelector, deposit, evictCachedValue, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isMutable, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
2125
|
+
export { FamilyTracker, Future, IMPLICIT, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deleteAtom, deleteSelector, deposit, evictCachedValue, findInStore, getEnvironmentData, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, ingestAtomUpdate, ingestSelectorUpdate, ingestTransactionUpdate, isAtomDefault, isAtomKey, isDone, isMutable, isReadonlySelectorKey, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, setAtomOrSelector, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
2092
2126
|
//# sourceMappingURL=out.js.map
|
|
2093
2127
|
//# sourceMappingURL=index.js.map
|