atom.io 0.24.8 → 0.25.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/data/dist/index.cjs +40 -62
- package/data/dist/index.d.ts +3 -3
- package/data/dist/index.js +41 -63
- package/data/src/join.ts +47 -64
- package/dist/index.cjs +26 -8
- package/dist/index.d.ts +37 -15
- package/dist/index.js +27 -9
- package/internal/dist/index.cjs +223 -111
- package/internal/dist/index.d.ts +12 -6
- package/internal/dist/index.js +224 -113
- package/internal/src/families/dispose-from-store.ts +56 -3
- package/internal/src/get-state/get-from-store.ts +58 -25
- package/internal/src/lineage.ts +7 -0
- package/internal/src/molecule/make-molecule-in-store.ts +75 -31
- package/internal/src/not-found-error.ts +29 -6
- package/internal/src/selector/create-writable-selector.ts +5 -5
- package/internal/src/selector/register-selector.ts +58 -9
- package/internal/src/set-state/set-into-store.ts +48 -1
- package/internal/src/store/store.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +10 -9
- package/internal/src/transaction/create-transaction.ts +2 -2
- package/internal/src/transaction/index.ts +2 -2
- package/package.json +5 -5
- package/react/dist/index.cjs +4 -1
- package/react/dist/index.js +5 -2
- package/react/src/use-o.ts +11 -3
- package/realtime/dist/index.cjs +0 -1
- package/realtime/dist/index.js +0 -1
- package/realtime/src/realtime-continuity.ts +0 -1
- package/realtime-server/dist/index.cjs +7 -7
- package/realtime-server/dist/index.js +7 -7
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +7 -7
- package/src/dispose-state.ts +32 -3
- package/src/get-state.ts +37 -4
- package/src/molecule.ts +20 -7
- package/src/set-state.ts +19 -2
- package/src/silo.ts +11 -4
- package/src/transaction.ts +9 -17
package/internal/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Junction } from '../../dist/chunk-HYXKCFVY.js';
|
|
|
2
2
|
import { __spreadValues, __spreadProps } from '../../dist/chunk-S4N6XNPH.js';
|
|
3
3
|
import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
|
|
4
4
|
import { AtomIOLogger } from 'atom.io';
|
|
5
|
-
import { getJoin } from 'atom.io/data';
|
|
5
|
+
import { getJoin, findRelations } from 'atom.io/data';
|
|
6
6
|
|
|
7
7
|
// internal/src/arbitrary.ts
|
|
8
8
|
function arbitrary(random = Math.random) {
|
|
@@ -58,6 +58,12 @@ function newest(scion) {
|
|
|
58
58
|
}
|
|
59
59
|
return scion;
|
|
60
60
|
}
|
|
61
|
+
function eldest(scion) {
|
|
62
|
+
while (scion.parent !== null) {
|
|
63
|
+
scion = scion.parent;
|
|
64
|
+
}
|
|
65
|
+
return scion;
|
|
66
|
+
}
|
|
61
67
|
|
|
62
68
|
// internal/src/store/deposit.ts
|
|
63
69
|
function deposit(state) {
|
|
@@ -132,8 +138,6 @@ var abortTransaction = (store) => {
|
|
|
132
138
|
);
|
|
133
139
|
target.parent.child = null;
|
|
134
140
|
};
|
|
135
|
-
|
|
136
|
-
// internal/src/not-found-error.ts
|
|
137
141
|
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
138
142
|
function prettyPrintTokenType(token) {
|
|
139
143
|
switch (token.type) {
|
|
@@ -152,10 +156,19 @@ function prettyPrintTokenType(token) {
|
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
var NotFoundError = class extends Error {
|
|
155
|
-
constructor(
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
)
|
|
159
|
+
constructor(...params) {
|
|
160
|
+
const token = params[0];
|
|
161
|
+
const store = params.length === 2 ? params[1] : params[2];
|
|
162
|
+
if (params.length === 2) {
|
|
163
|
+
super(
|
|
164
|
+
`${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store "${store.config.name}".`
|
|
165
|
+
);
|
|
166
|
+
} else {
|
|
167
|
+
const key = params[1];
|
|
168
|
+
super(
|
|
169
|
+
`${prettyPrintTokenType(token)} "${token.key}" member ${stringifyJson(key)} not found in store "${store.config.name}".`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
159
172
|
}
|
|
160
173
|
};
|
|
161
174
|
|
|
@@ -415,41 +428,6 @@ var setAtomOrSelector = (state, value, store) => {
|
|
|
415
428
|
break;
|
|
416
429
|
}
|
|
417
430
|
};
|
|
418
|
-
|
|
419
|
-
// internal/src/set-state/set-into-store.ts
|
|
420
|
-
function setIntoStore(token, value, store) {
|
|
421
|
-
const rejectionTime = openOperation(token, store);
|
|
422
|
-
if (rejectionTime) {
|
|
423
|
-
const unsubscribe = store.on.operationClose.subscribe(
|
|
424
|
-
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
425
|
-
() => {
|
|
426
|
-
unsubscribe();
|
|
427
|
-
store.logger.info(
|
|
428
|
-
`\u{1F7E2}`,
|
|
429
|
-
token.type,
|
|
430
|
-
token.key,
|
|
431
|
-
`resuming deferred setState from T-${rejectionTime}`
|
|
432
|
-
);
|
|
433
|
-
setIntoStore(token, value, store);
|
|
434
|
-
}
|
|
435
|
-
);
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
const state = withdraw(token, store);
|
|
439
|
-
setAtomOrSelector(state, value, store);
|
|
440
|
-
closeOperation(store);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
// internal/src/ingest-updates/ingest-atom-update.ts
|
|
444
|
-
function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
445
|
-
const { key, newValue, oldValue } = atomUpdate;
|
|
446
|
-
const value = applying === `newValue` ? newValue : oldValue;
|
|
447
|
-
const token = { key, type: `atom` };
|
|
448
|
-
if (atomUpdate.family) {
|
|
449
|
-
Object.assign(token, { family: atomUpdate.family });
|
|
450
|
-
}
|
|
451
|
-
setIntoStore(token, value, store);
|
|
452
|
-
}
|
|
453
431
|
function createRegularAtomFamily(options, store) {
|
|
454
432
|
const subject = new Subject();
|
|
455
433
|
const atomFamily = Object.assign(
|
|
@@ -491,17 +469,31 @@ function createAtomFamily(options, store) {
|
|
|
491
469
|
}
|
|
492
470
|
|
|
493
471
|
// internal/src/get-state/get-from-store.ts
|
|
494
|
-
function getFromStore(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
472
|
+
function getFromStore(...params) {
|
|
473
|
+
let token;
|
|
474
|
+
let store;
|
|
475
|
+
if (params.length === 2) {
|
|
476
|
+
token = params[0];
|
|
477
|
+
store = params[1];
|
|
478
|
+
} else {
|
|
479
|
+
const family = params[0];
|
|
480
|
+
const key = params[1];
|
|
481
|
+
store = params[2];
|
|
482
|
+
const maybeToken = family.type === `molecule_family` ? seekInStore(family, key, store) : store.config.lifespan === `immortal` ? seekInStore(family, key, store) : findInStore(family, key, store);
|
|
483
|
+
if (!maybeToken) {
|
|
484
|
+
throw new NotFoundError(family, key, store);
|
|
501
485
|
}
|
|
486
|
+
token = maybeToken;
|
|
487
|
+
}
|
|
488
|
+
switch (token.type) {
|
|
489
|
+
case `atom`:
|
|
490
|
+
case `mutable_atom`:
|
|
491
|
+
case `selector`:
|
|
492
|
+
case `readonly_selector`:
|
|
493
|
+
return readOrComputeValue(withdraw(token, store), store);
|
|
494
|
+
case `molecule`:
|
|
495
|
+
return withdraw(token, store).instance;
|
|
502
496
|
}
|
|
503
|
-
const state = withdraw(token, store);
|
|
504
|
-
return readOrComputeValue(state, store);
|
|
505
497
|
}
|
|
506
498
|
|
|
507
499
|
// internal/src/keys.ts
|
|
@@ -582,8 +574,16 @@ var updateSelectorAtoms = (selectorKey, dependency, covered, store) => {
|
|
|
582
574
|
|
|
583
575
|
// internal/src/selector/register-selector.ts
|
|
584
576
|
var registerSelector = (selectorKey, covered, store) => ({
|
|
585
|
-
get: (dependency) => {
|
|
577
|
+
get: (dependency, key) => {
|
|
586
578
|
const target = newest(store);
|
|
579
|
+
if (key) {
|
|
580
|
+
switch (dependency.type) {
|
|
581
|
+
case `molecule_family`:
|
|
582
|
+
return getFromStore(dependency, key, store);
|
|
583
|
+
case `atom_family`:
|
|
584
|
+
dependency = seekInStore(dependency, key, store);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
587
|
if (dependency.type === `molecule`) {
|
|
588
588
|
return getFromStore(dependency, store);
|
|
589
589
|
}
|
|
@@ -609,10 +609,25 @@ var registerSelector = (selectorKey, covered, store) => ({
|
|
|
609
609
|
updateSelectorAtoms(selectorKey, dependency, covered, store);
|
|
610
610
|
return dependencyValue;
|
|
611
611
|
},
|
|
612
|
-
set: (
|
|
612
|
+
set: (...params) => {
|
|
613
|
+
let token;
|
|
614
|
+
let value;
|
|
615
|
+
if (params.length === 2) {
|
|
616
|
+
token = params[0];
|
|
617
|
+
value = params[1];
|
|
618
|
+
} else {
|
|
619
|
+
const family = params[0];
|
|
620
|
+
const key = params[1];
|
|
621
|
+
value = params[2];
|
|
622
|
+
const maybeToken = store.config.lifespan === `ephemeral` ? findInStore(family, key, store) : seekInStore(family, key, store);
|
|
623
|
+
if (!maybeToken) {
|
|
624
|
+
throw new NotFoundError(family, key, store);
|
|
625
|
+
}
|
|
626
|
+
token = maybeToken;
|
|
627
|
+
}
|
|
613
628
|
const target = newest(store);
|
|
614
|
-
const state = withdraw(
|
|
615
|
-
setAtomOrSelector(state,
|
|
629
|
+
const state = withdraw(token, target);
|
|
630
|
+
setAtomOrSelector(state, value, target);
|
|
616
631
|
},
|
|
617
632
|
find: (token, key) => findInStore(token, key, store),
|
|
618
633
|
seek: (token, key) => seekInStore(token, key, store),
|
|
@@ -665,11 +680,11 @@ var createWritableSelector = (options, family, store) => {
|
|
|
665
680
|
const target = newest(store);
|
|
666
681
|
const subject = new Subject();
|
|
667
682
|
const covered = /* @__PURE__ */ new Set();
|
|
668
|
-
const
|
|
669
|
-
const { find, get, seek, json } =
|
|
670
|
-
const
|
|
683
|
+
const toolkit = registerSelector(options.key, covered, target);
|
|
684
|
+
const { find, get, seek, json } = toolkit;
|
|
685
|
+
const getterToolkit = { find, get, seek, json };
|
|
671
686
|
const getSelf = (innerTarget = newest(store)) => {
|
|
672
|
-
const value = options.get(
|
|
687
|
+
const value = options.get(getterToolkit);
|
|
673
688
|
cacheValue(options.key, value, subject, innerTarget);
|
|
674
689
|
covered.clear();
|
|
675
690
|
return value;
|
|
@@ -693,7 +708,7 @@ var createWritableSelector = (options, family, store) => {
|
|
|
693
708
|
if (isRootStore(innerTarget)) {
|
|
694
709
|
subject.next({ newValue, oldValue });
|
|
695
710
|
}
|
|
696
|
-
options.set(
|
|
711
|
+
options.set(toolkit, newValue);
|
|
697
712
|
};
|
|
698
713
|
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
699
714
|
subject,
|
|
@@ -947,23 +962,6 @@ function disposeMolecule(token, store) {
|
|
|
947
962
|
}
|
|
948
963
|
}
|
|
949
964
|
|
|
950
|
-
// internal/src/families/dispose-from-store.ts
|
|
951
|
-
function disposeFromStore(token, store = IMPLICIT.STORE) {
|
|
952
|
-
switch (token.type) {
|
|
953
|
-
case `atom`:
|
|
954
|
-
case `mutable_atom`:
|
|
955
|
-
disposeAtom(token, store);
|
|
956
|
-
break;
|
|
957
|
-
case `selector`:
|
|
958
|
-
case `readonly_selector`:
|
|
959
|
-
disposeSelector(token, store);
|
|
960
|
-
break;
|
|
961
|
-
case `molecule`:
|
|
962
|
-
disposeMolecule(token, store);
|
|
963
|
-
break;
|
|
964
|
-
}
|
|
965
|
-
}
|
|
966
|
-
|
|
967
965
|
// internal/src/families/init-family-member.ts
|
|
968
966
|
function initFamilyMemberInStore(token, key, store) {
|
|
969
967
|
const familyKey = token.key;
|
|
@@ -1037,6 +1035,91 @@ function findInStore(token, key, store) {
|
|
|
1037
1035
|
return state;
|
|
1038
1036
|
}
|
|
1039
1037
|
|
|
1038
|
+
// internal/src/families/dispose-from-store.ts
|
|
1039
|
+
function disposeFromStore(...params) {
|
|
1040
|
+
let token;
|
|
1041
|
+
let store;
|
|
1042
|
+
if (params.length === 2) {
|
|
1043
|
+
token = params[0];
|
|
1044
|
+
store = params[1];
|
|
1045
|
+
} else {
|
|
1046
|
+
const family = params[0];
|
|
1047
|
+
const key = params[1];
|
|
1048
|
+
store = params[2];
|
|
1049
|
+
const maybeToken = family.type === `molecule_family` ? seekInStore(family, key, store) : store.config.lifespan === `immortal` ? seekInStore(family, key, store) : findInStore(family, key, store);
|
|
1050
|
+
if (!maybeToken) {
|
|
1051
|
+
throw new NotFoundError(family, key, store);
|
|
1052
|
+
}
|
|
1053
|
+
token = maybeToken;
|
|
1054
|
+
}
|
|
1055
|
+
switch (token.type) {
|
|
1056
|
+
case `atom`:
|
|
1057
|
+
case `mutable_atom`:
|
|
1058
|
+
disposeAtom(token, store);
|
|
1059
|
+
break;
|
|
1060
|
+
case `selector`:
|
|
1061
|
+
case `readonly_selector`:
|
|
1062
|
+
disposeSelector(token, store);
|
|
1063
|
+
break;
|
|
1064
|
+
case `molecule`:
|
|
1065
|
+
disposeMolecule(token, store);
|
|
1066
|
+
break;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
// internal/src/set-state/set-into-store.ts
|
|
1071
|
+
function setIntoStore(...params) {
|
|
1072
|
+
let token;
|
|
1073
|
+
let value;
|
|
1074
|
+
let store;
|
|
1075
|
+
if (params.length === 3) {
|
|
1076
|
+
token = params[0];
|
|
1077
|
+
value = params[1];
|
|
1078
|
+
store = params[2];
|
|
1079
|
+
} else {
|
|
1080
|
+
const family = params[0];
|
|
1081
|
+
const key = params[1];
|
|
1082
|
+
value = params[2];
|
|
1083
|
+
store = params[3];
|
|
1084
|
+
const maybeToken = store.config.lifespan === `ephemeral` ? findInStore(family, key, store) : seekInStore(family, key, store);
|
|
1085
|
+
if (!maybeToken) {
|
|
1086
|
+
throw new NotFoundError(family, key, store);
|
|
1087
|
+
}
|
|
1088
|
+
token = maybeToken;
|
|
1089
|
+
}
|
|
1090
|
+
const rejectionTime = openOperation(token, store);
|
|
1091
|
+
if (rejectionTime) {
|
|
1092
|
+
const unsubscribe = store.on.operationClose.subscribe(
|
|
1093
|
+
`waiting to set "${token.key}" at T-${rejectionTime}`,
|
|
1094
|
+
() => {
|
|
1095
|
+
unsubscribe();
|
|
1096
|
+
store.logger.info(
|
|
1097
|
+
`\u{1F7E2}`,
|
|
1098
|
+
token.type,
|
|
1099
|
+
token.key,
|
|
1100
|
+
`resuming deferred setState from T-${rejectionTime}`
|
|
1101
|
+
);
|
|
1102
|
+
setIntoStore(token, value, store);
|
|
1103
|
+
}
|
|
1104
|
+
);
|
|
1105
|
+
return;
|
|
1106
|
+
}
|
|
1107
|
+
const state = withdraw(token, store);
|
|
1108
|
+
setAtomOrSelector(state, value, store);
|
|
1109
|
+
closeOperation(store);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// internal/src/ingest-updates/ingest-atom-update.ts
|
|
1113
|
+
function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
1114
|
+
const { key, newValue, oldValue } = atomUpdate;
|
|
1115
|
+
const value = applying === `newValue` ? newValue : oldValue;
|
|
1116
|
+
const token = { key, type: `atom` };
|
|
1117
|
+
if (atomUpdate.family) {
|
|
1118
|
+
Object.assign(token, { family: atomUpdate.family });
|
|
1119
|
+
}
|
|
1120
|
+
setIntoStore(token, value, store);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1040
1123
|
// internal/src/molecule/create-molecule-family.ts
|
|
1041
1124
|
function createMoleculeFamily(options, store) {
|
|
1042
1125
|
var _a;
|
|
@@ -1098,46 +1181,80 @@ var Molecule = class {
|
|
|
1098
1181
|
};
|
|
1099
1182
|
|
|
1100
1183
|
// internal/src/molecule/make-molecule-in-store.ts
|
|
1184
|
+
function capitalize2(string) {
|
|
1185
|
+
return string[0].toUpperCase() + string.slice(1);
|
|
1186
|
+
}
|
|
1101
1187
|
function makeMoleculeInStore(store, context, familyToken, key, ...params) {
|
|
1188
|
+
const rootStore = eldest(store);
|
|
1102
1189
|
const target = newest(store);
|
|
1103
|
-
|
|
1190
|
+
const stringKey = stringifyJson(key);
|
|
1191
|
+
target.moleculeInProgress = stringKey;
|
|
1104
1192
|
const contextArray = Array.isArray(context) ? context : [context];
|
|
1105
1193
|
const owners = contextArray.map((ctx) => {
|
|
1106
1194
|
if (ctx instanceof Molecule) {
|
|
1107
1195
|
return ctx;
|
|
1108
1196
|
}
|
|
1109
|
-
const
|
|
1110
|
-
const molecule2 = store.molecules.get(
|
|
1197
|
+
const ctxStringKey = stringifyJson(ctx.key);
|
|
1198
|
+
const molecule2 = store.molecules.get(ctxStringKey);
|
|
1111
1199
|
if (!molecule2) {
|
|
1112
1200
|
throw new Error(
|
|
1113
|
-
`Molecule ${
|
|
1201
|
+
`Molecule ${ctxStringKey} not found in store "${store.config.name}"`
|
|
1114
1202
|
);
|
|
1115
1203
|
}
|
|
1116
1204
|
return molecule2;
|
|
1117
1205
|
});
|
|
1118
1206
|
const molecule = new Molecule(owners, key, familyToken);
|
|
1119
|
-
target.molecules.set(
|
|
1207
|
+
target.molecules.set(stringKey, molecule);
|
|
1120
1208
|
for (const owner of owners) {
|
|
1121
1209
|
owner.below.set(molecule.stringKey, molecule);
|
|
1122
1210
|
}
|
|
1123
|
-
const
|
|
1124
|
-
get: (
|
|
1125
|
-
set: (
|
|
1126
|
-
setIntoStore(
|
|
1211
|
+
const toolkit = {
|
|
1212
|
+
get: (...ps) => getFromStore(...ps, newest(rootStore)),
|
|
1213
|
+
set: (...ps) => {
|
|
1214
|
+
setIntoStore(...ps, newest(rootStore));
|
|
1127
1215
|
},
|
|
1128
|
-
seek: (t, k) => seekInStore(t, k, newest(
|
|
1129
|
-
json: (t) => getJsonToken(t, newest(
|
|
1216
|
+
seek: (t, k) => seekInStore(t, k, newest(rootStore)),
|
|
1217
|
+
json: (t) => getJsonToken(t, newest(rootStore)),
|
|
1130
1218
|
run: (t, i = arbitrary()) => actUponStore(t, i, newest(store)),
|
|
1131
|
-
make: (ctx, f, k, ...args) => makeMoleculeInStore(newest(
|
|
1219
|
+
make: (ctx, f, k, ...args) => makeMoleculeInStore(newest(rootStore), ctx, f, k, ...args),
|
|
1132
1220
|
dispose: (t) => {
|
|
1133
|
-
disposeFromStore(t, newest(
|
|
1221
|
+
disposeFromStore(t, newest(rootStore));
|
|
1222
|
+
},
|
|
1223
|
+
env: () => getEnvironmentData(newest(rootStore)),
|
|
1224
|
+
bond: (token2, maybeRole) => {
|
|
1225
|
+
if (token2.type === `join`) {
|
|
1226
|
+
const { as: role } = maybeRole;
|
|
1227
|
+
const join = getJoin(token2, rootStore);
|
|
1228
|
+
join.molecules.set(stringKey, molecule);
|
|
1229
|
+
molecule.joins.set(token2.key, join);
|
|
1230
|
+
const unsubFromFamily = family.subject.subscribe(
|
|
1231
|
+
`join:${token2.key}-${stringKey}`,
|
|
1232
|
+
(event) => {
|
|
1233
|
+
if (event.type === `molecule_disposal` && stringifyJson(event.token.key) === stringKey) {
|
|
1234
|
+
unsubFromFamily();
|
|
1235
|
+
join.molecules.delete(stringKey);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
);
|
|
1239
|
+
if (role === null) {
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
const otherRole = token2.a === role ? token2.b : token2.a;
|
|
1243
|
+
const relations = findRelations(token2, key);
|
|
1244
|
+
const relatedKeys = relations[`${otherRole}KeysOf${capitalize2(role)}`];
|
|
1245
|
+
const relatedEntries = relations[`${otherRole}EntriesOf${capitalize2(role)}`];
|
|
1246
|
+
let tokens = { relatedKeys };
|
|
1247
|
+
if (relatedEntries) {
|
|
1248
|
+
tokens = Object.assign(tokens, { relatedEntries });
|
|
1249
|
+
}
|
|
1250
|
+
return tokens;
|
|
1251
|
+
}
|
|
1252
|
+
return growMoleculeInStore(
|
|
1253
|
+
molecule,
|
|
1254
|
+
withdraw(token2, rootStore),
|
|
1255
|
+
newest(rootStore)
|
|
1256
|
+
);
|
|
1134
1257
|
},
|
|
1135
|
-
env: () => getEnvironmentData(newest(store)),
|
|
1136
|
-
bond: (f) => growMoleculeInStore(
|
|
1137
|
-
molecule,
|
|
1138
|
-
withdraw(f, store),
|
|
1139
|
-
newest(store)
|
|
1140
|
-
),
|
|
1141
1258
|
claim: (below, options) => {
|
|
1142
1259
|
const { exclusive } = options;
|
|
1143
1260
|
const belowMolecule = newest(store).molecules.get(stringifyJson(below.key));
|
|
@@ -1155,12 +1272,6 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
|
|
|
1155
1272
|
}
|
|
1156
1273
|
}
|
|
1157
1274
|
},
|
|
1158
|
-
join: (joinToken) => {
|
|
1159
|
-
const join = getJoin(joinToken, store);
|
|
1160
|
-
join.molecules.set(stringifyJson(key), molecule);
|
|
1161
|
-
molecule.joins.set(joinToken.key, join);
|
|
1162
|
-
return joinToken;
|
|
1163
|
-
},
|
|
1164
1275
|
spawn: (f, k, ...p) => makeMoleculeInStore(
|
|
1165
1276
|
newest(store),
|
|
1166
1277
|
[molecule],
|
|
@@ -1171,7 +1282,7 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
|
|
|
1171
1282
|
};
|
|
1172
1283
|
const family = withdraw(familyToken, store);
|
|
1173
1284
|
const Constructor = family.new;
|
|
1174
|
-
molecule.instance = new Constructor(
|
|
1285
|
+
molecule.instance = new Constructor(toolkit, key, ...params);
|
|
1175
1286
|
const token = {
|
|
1176
1287
|
type: `molecule`,
|
|
1177
1288
|
key,
|
|
@@ -1472,18 +1583,18 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
1472
1583
|
params,
|
|
1473
1584
|
output: void 0
|
|
1474
1585
|
},
|
|
1475
|
-
|
|
1476
|
-
get: (
|
|
1477
|
-
set: (
|
|
1478
|
-
setIntoStore(
|
|
1586
|
+
toolkit: {
|
|
1587
|
+
get: (...ps) => getFromStore(...ps, child),
|
|
1588
|
+
set: (...ps) => {
|
|
1589
|
+
setIntoStore(...ps, child);
|
|
1479
1590
|
},
|
|
1480
1591
|
run: (token, identifier = arbitrary()) => actUponStore(token, identifier, child),
|
|
1481
1592
|
find: (token, k) => findInStore(token, k, child),
|
|
1482
1593
|
seek: (token, k) => seekInStore(token, k, child),
|
|
1483
1594
|
json: (token) => getJsonToken(token, child),
|
|
1484
1595
|
make: (context, family, k, ...args) => makeMoleculeInStore(child, context, family, k, ...args),
|
|
1485
|
-
dispose: (
|
|
1486
|
-
disposeFromStore(
|
|
1596
|
+
dispose: (...ps) => {
|
|
1597
|
+
disposeFromStore(...ps, child);
|
|
1487
1598
|
},
|
|
1488
1599
|
env: () => getEnvironmentData(child)
|
|
1489
1600
|
}
|
|
@@ -1511,8 +1622,8 @@ function createTransaction(options, store) {
|
|
|
1511
1622
|
const childStore = buildTransaction(options.key, params, store, id);
|
|
1512
1623
|
try {
|
|
1513
1624
|
const target2 = newest(store);
|
|
1514
|
-
const {
|
|
1515
|
-
const output = options.do(
|
|
1625
|
+
const { toolkit } = childStore.transactionMeta;
|
|
1626
|
+
const output = options.do(toolkit, ...params);
|
|
1516
1627
|
applyTransaction(output, target2);
|
|
1517
1628
|
return output;
|
|
1518
1629
|
} catch (thrown) {
|
|
@@ -1628,6 +1739,7 @@ var Store = class {
|
|
|
1628
1739
|
for (const logger of this.loggers) logger.warn(...messages);
|
|
1629
1740
|
}
|
|
1630
1741
|
};
|
|
1742
|
+
this.config = __spreadValues(__spreadValues({}, store == null ? void 0 : store.config), config);
|
|
1631
1743
|
if (store !== null) {
|
|
1632
1744
|
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
1633
1745
|
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
@@ -1639,7 +1751,6 @@ var Store = class {
|
|
|
1639
1751
|
)
|
|
1640
1752
|
};
|
|
1641
1753
|
}
|
|
1642
|
-
this.config = __spreadValues(__spreadValues({}, store == null ? void 0 : store.config), config);
|
|
1643
1754
|
for (const [, family] of store.families) {
|
|
1644
1755
|
family.install(this);
|
|
1645
1756
|
}
|
|
@@ -2909,4 +3020,4 @@ var timeTravel = (action, token, store) => {
|
|
|
2909
3020
|
);
|
|
2910
3021
|
};
|
|
2911
3022
|
|
|
2912
|
-
export { FamilyTracker, Future, IMPLICIT, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isMutable, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
3023
|
+
export { FamilyTracker, Future, IMPLICIT, LazyMap, Molecule, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtomFamily, createMoleculeFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, deposit, disposeAtom, disposeFromStore, disposeMolecule, disposeSelector, eldest, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getUpdateToken, growMoleculeInStore, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isMutable, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, readCachedValue, readOrComputeValue, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeToRootAtoms, subscribeToState, subscribeToTimeline, subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
@@ -1,15 +1,68 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
MoleculeConstructor,
|
|
3
|
+
MoleculeFamilyToken,
|
|
4
|
+
MoleculeKey,
|
|
5
|
+
MoleculeToken,
|
|
6
|
+
ReadableFamilyToken,
|
|
7
|
+
ReadableToken,
|
|
8
|
+
} from "atom.io"
|
|
9
|
+
import type { Json } from "atom.io/json"
|
|
2
10
|
|
|
3
11
|
import { disposeAtom } from "../atom"
|
|
4
12
|
import { disposeMolecule } from "../molecule/dispose-molecule"
|
|
13
|
+
import { NotFoundError } from "../not-found-error"
|
|
5
14
|
import { disposeSelector } from "../selector"
|
|
6
15
|
import type { Store } from "../store"
|
|
7
|
-
import {
|
|
16
|
+
import { findInStore } from "./find-in-store"
|
|
17
|
+
import { seekInStore } from "./seek-in-store"
|
|
8
18
|
|
|
9
19
|
export function disposeFromStore(
|
|
10
20
|
token: MoleculeToken<any> | ReadableToken<any>,
|
|
11
|
-
store: Store
|
|
21
|
+
store: Store,
|
|
22
|
+
): void
|
|
23
|
+
|
|
24
|
+
export function disposeFromStore<K extends Json.Serializable>(
|
|
25
|
+
token: ReadableFamilyToken<any, K>,
|
|
26
|
+
key: K,
|
|
27
|
+
store: Store,
|
|
28
|
+
): void
|
|
29
|
+
|
|
30
|
+
export function disposeFromStore<M extends MoleculeConstructor>(
|
|
31
|
+
token: MoleculeFamilyToken<M>,
|
|
32
|
+
key: MoleculeKey<M>,
|
|
33
|
+
store: Store,
|
|
34
|
+
): void
|
|
35
|
+
|
|
36
|
+
export function disposeFromStore(
|
|
37
|
+
...params:
|
|
38
|
+
| [
|
|
39
|
+
token: ReadableFamilyToken<any, any>,
|
|
40
|
+
key: Json.Serializable,
|
|
41
|
+
store: Store,
|
|
42
|
+
]
|
|
43
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>, store: Store]
|
|
44
|
+
| [token: MoleculeToken<any> | ReadableToken<any>, store: Store]
|
|
12
45
|
): void {
|
|
46
|
+
let token: MoleculeToken<any> | ReadableToken<any>
|
|
47
|
+
let store: Store
|
|
48
|
+
if (params.length === 2) {
|
|
49
|
+
token = params[0]
|
|
50
|
+
store = params[1]
|
|
51
|
+
} else {
|
|
52
|
+
const family = params[0]
|
|
53
|
+
const key = params[1]
|
|
54
|
+
store = params[2]
|
|
55
|
+
const maybeToken =
|
|
56
|
+
family.type === `molecule_family`
|
|
57
|
+
? seekInStore(family, key, store)
|
|
58
|
+
: store.config.lifespan === `immortal`
|
|
59
|
+
? seekInStore(family, key, store)
|
|
60
|
+
: findInStore(family, key, store)
|
|
61
|
+
if (!maybeToken) {
|
|
62
|
+
throw new NotFoundError(family, key, store)
|
|
63
|
+
}
|
|
64
|
+
token = maybeToken
|
|
65
|
+
}
|
|
13
66
|
switch (token.type) {
|
|
14
67
|
case `atom`:
|
|
15
68
|
case `mutable_atom`:
|
|
@@ -1,39 +1,72 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
MoleculeConstructor,
|
|
3
|
+
MoleculeFamilyToken,
|
|
4
|
+
MoleculeKey,
|
|
5
|
+
MoleculeToken,
|
|
6
|
+
ReadableFamilyToken,
|
|
7
|
+
ReadableToken,
|
|
8
|
+
} from "atom.io"
|
|
9
|
+
import type { Json } from "atom.io/json"
|
|
2
10
|
|
|
11
|
+
import { findInStore, seekInStore } from "../families"
|
|
12
|
+
import { NotFoundError } from "../not-found-error"
|
|
3
13
|
import type { Store } from "../store"
|
|
4
14
|
import { withdraw } from "../store"
|
|
5
15
|
import { readOrComputeValue } from "./read-or-compute-value"
|
|
6
16
|
|
|
7
17
|
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T
|
|
18
|
+
|
|
8
19
|
export function getFromStore<M extends MoleculeConstructor>(
|
|
9
20
|
token: MoleculeToken<M>,
|
|
10
21
|
store: Store,
|
|
11
22
|
): InstanceType<M> | undefined
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
>(token: Token, store: Store): InstanceType<M> | T | undefined
|
|
17
|
-
export function getFromStore<
|
|
18
|
-
Token extends MoleculeToken<any> | ReadableToken<any>,
|
|
19
|
-
>(
|
|
20
|
-
token: Token,
|
|
23
|
+
|
|
24
|
+
export function getFromStore<T, K extends Json.Serializable>(
|
|
25
|
+
token: ReadableFamilyToken<T, K>,
|
|
26
|
+
key: K,
|
|
21
27
|
store: Store,
|
|
22
|
-
):
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
): T
|
|
29
|
+
|
|
30
|
+
export function getFromStore<M extends MoleculeConstructor>(
|
|
31
|
+
token: MoleculeFamilyToken<M>,
|
|
32
|
+
key: MoleculeKey<M>,
|
|
33
|
+
store: Store,
|
|
34
|
+
): InstanceType<M>
|
|
35
|
+
|
|
36
|
+
export function getFromStore<T>(
|
|
37
|
+
...params:
|
|
38
|
+
| [token: MoleculeFamilyToken<any>, key: MoleculeKey<any>, store: Store]
|
|
39
|
+
| [token: MoleculeToken<any>, store: Store]
|
|
40
|
+
| [token: ReadableFamilyToken<T, any>, key: Json.Serializable, store: Store]
|
|
41
|
+
| [token: ReadableToken<T>, store: Store]
|
|
42
|
+
): any {
|
|
43
|
+
let token: MoleculeToken<any> | ReadableToken<T>
|
|
44
|
+
let store: Store
|
|
45
|
+
if (params.length === 2) {
|
|
46
|
+
token = params[0]
|
|
47
|
+
store = params[1]
|
|
48
|
+
} else {
|
|
49
|
+
const family = params[0]
|
|
50
|
+
const key = params[1]
|
|
51
|
+
store = params[2]
|
|
52
|
+
const maybeToken =
|
|
53
|
+
family.type === `molecule_family`
|
|
54
|
+
? seekInStore(family, key, store)
|
|
55
|
+
: store.config.lifespan === `immortal`
|
|
56
|
+
? seekInStore(family, key, store)
|
|
57
|
+
: findInStore(family, key, store)
|
|
58
|
+
if (!maybeToken) {
|
|
59
|
+
throw new NotFoundError(family, key, store)
|
|
35
60
|
}
|
|
61
|
+
token = maybeToken
|
|
62
|
+
}
|
|
63
|
+
switch (token.type) {
|
|
64
|
+
case `atom`:
|
|
65
|
+
case `mutable_atom`:
|
|
66
|
+
case `selector`:
|
|
67
|
+
case `readonly_selector`:
|
|
68
|
+
return readOrComputeValue(withdraw(token, store), store)
|
|
69
|
+
case `molecule`:
|
|
70
|
+
return withdraw(token, store).instance
|
|
36
71
|
}
|
|
37
|
-
const state = withdraw(token, store)
|
|
38
|
-
return readOrComputeValue(state, store)
|
|
39
72
|
}
|
package/internal/src/lineage.ts
CHANGED