atom.io 0.19.1 → 0.19.2
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 +99 -79
- package/data/dist/index.js +2 -2
- package/data/src/join.ts +67 -50
- package/dist/{chunk-YDOGCZ53.js → chunk-ATKDGVTV.js} +29 -29
- package/dist/{chunk-7VCCW45K.js → chunk-CC7IF7QF.js} +4 -3
- package/dist/{chunk-WX2NCOZR.js → chunk-FTONNX2R.js} +8 -8
- package/dist/{chunk-7ZR244C2.js → chunk-MSCJWACE.js} +92 -72
- package/dist/index.cjs +14 -7
- package/dist/index.d.ts +23 -35
- package/dist/index.js +14 -7
- package/internal/dist/index.cjs +55 -43
- package/internal/dist/index.d.ts +20 -20
- package/internal/dist/index.js +48 -36
- package/internal/src/atom/create-regular-atom.ts +7 -5
- package/internal/src/atom/delete-atom.ts +2 -2
- package/internal/src/families/create-readonly-selector-family.ts +2 -2
- package/internal/src/families/create-regular-atom-family.ts +1 -1
- package/internal/src/families/create-writable-selector-family.ts +1 -1
- package/internal/src/future.ts +4 -2
- package/internal/src/lineage.ts +1 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +7 -5
- package/internal/src/mutable/tracker.ts +3 -3
- package/internal/src/mutable/transceiver.ts +2 -2
- package/internal/src/selector/delete-selector.ts +1 -1
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +5 -5
- package/internal/src/store/withdraw.ts +4 -5
- package/internal/src/subject.ts +3 -1
- package/internal/src/subscribe/subscribe-to-transaction.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +13 -8
- package/internal/src/timeline/create-timeline.ts +3 -4
- package/internal/src/transaction/act-upon-store.ts +5 -5
- package/internal/src/transaction/apply-transaction.ts +4 -4
- package/internal/src/transaction/build-transaction.ts +9 -6
- package/internal/src/transaction/create-transaction.ts +10 -10
- package/internal/src/transaction/index.ts +3 -3
- package/internal/src/transaction/is-root-store.ts +2 -2
- package/introspection/dist/index.d.ts +3 -3
- package/introspection/src/attach-introspection-states.ts +3 -3
- package/introspection/src/attach-transaction-index.ts +4 -4
- package/introspection/src/attach-transaction-logs.ts +8 -4
- package/json/dist/index.cjs +6 -2
- package/json/dist/index.js +6 -2
- package/json/src/select-json-family.ts +3 -2
- package/json/src/select-json.ts +3 -1
- package/package.json +243 -241
- package/react/dist/index.cjs +9 -3
- package/react/dist/index.js +9 -3
- package/react/src/use-i.ts +3 -1
- package/react/src/use-tl.ts +6 -2
- package/react-devtools/dist/index.cjs +116 -53
- package/react-devtools/dist/index.d.ts +3 -5
- package/react-devtools/dist/index.js +113 -51
- package/react-devtools/src/AtomIODevtools.tsx +3 -1
- package/react-devtools/src/Button.tsx +3 -1
- package/react-devtools/src/StateIndex.tsx +6 -2
- package/react-devtools/src/TimelineIndex.tsx +6 -2
- package/react-devtools/src/TransactionIndex.tsx +3 -3
- package/react-devtools/src/Updates.tsx +14 -6
- package/realtime/dist/index.cjs +1 -0
- package/realtime/dist/index.d.ts +2 -2
- package/realtime/dist/index.js +1 -0
- package/realtime/src/realtime-continuity.ts +4 -3
- package/realtime-client/dist/index.cjs +29 -29
- package/realtime-client/dist/index.d.ts +2 -2
- package/realtime-client/dist/index.js +1 -1
- package/realtime-client/src/server-action.ts +2 -2
- package/realtime-client/src/sync-continuity.ts +23 -23
- package/realtime-react/dist/index.cjs +29 -29
- package/realtime-react/dist/index.d.ts +2 -2
- package/realtime-react/dist/index.js +1 -1
- package/realtime-react/src/use-server-action.ts +3 -3
- package/realtime-server/dist/index.cjs +54 -44
- package/realtime-server/dist/index.d.ts +5 -5
- package/realtime-server/dist/index.js +34 -24
- package/realtime-server/src/ipc-sockets/child-socket.ts +6 -6
- package/realtime-server/src/ipc-sockets/custom-socket.ts +4 -8
- package/realtime-server/src/ipc-sockets/parent-socket.ts +13 -7
- package/realtime-server/src/realtime-action-receiver.ts +7 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +3 -1
- package/realtime-testing/dist/index.cjs +15 -13
- package/realtime-testing/dist/index.js +9 -7
- package/realtime-testing/src/setup-realtime-test.tsx +6 -4
- package/src/atom.ts +4 -8
- package/src/dispose.ts +1 -0
- package/src/index.ts +2 -9
- package/src/selector.ts +4 -8
- package/src/silo.ts +9 -3
- package/src/subscribe.ts +6 -6
- package/src/timeline.ts +4 -4
- package/src/transaction.ts +24 -24
- package/transceivers/set-rtx/dist/index.cjs +11 -12
- package/transceivers/set-rtx/dist/index.js +11 -12
- package/transceivers/set-rtx/src/set-rtx.ts +10 -10
package/internal/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Junction } from '../../dist/chunk-
|
|
1
|
+
import { Junction } from '../../dist/chunk-FTONNX2R.js';
|
|
2
2
|
import { __spreadValues, __spreadProps } from '../../dist/chunk-U2IICNHQ.js';
|
|
3
3
|
import { stringifyJson, selectJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
4
4
|
import { AtomIOLogger } from 'atom.io';
|
|
@@ -30,7 +30,9 @@ var Subject = class {
|
|
|
30
30
|
}
|
|
31
31
|
subscribe(key, subscriber) {
|
|
32
32
|
this.subscribers.set(key, subscriber);
|
|
33
|
-
const unsubscribe = () =>
|
|
33
|
+
const unsubscribe = () => {
|
|
34
|
+
this.unsubscribe(key);
|
|
35
|
+
};
|
|
34
36
|
return unsubscribe;
|
|
35
37
|
}
|
|
36
38
|
unsubscribe(key) {
|
|
@@ -263,8 +265,12 @@ function withdrawOrCreate(token, store) {
|
|
|
263
265
|
var Future = class extends Promise {
|
|
264
266
|
constructor(executor) {
|
|
265
267
|
super((resolve, reject) => {
|
|
266
|
-
const pass = (value) =>
|
|
267
|
-
|
|
268
|
+
const pass = (value) => {
|
|
269
|
+
this.isCanceled ? reject(`canceled`) : resolve(value);
|
|
270
|
+
};
|
|
271
|
+
const fail = (reason) => {
|
|
272
|
+
this.isCanceled ? reject(`canceled`) : reject(reason);
|
|
273
|
+
};
|
|
268
274
|
if (typeof executor === `function`) {
|
|
269
275
|
executor(pass, fail);
|
|
270
276
|
} else {
|
|
@@ -286,7 +292,7 @@ function copyMutableIfNeeded(atom, origin, target) {
|
|
|
286
292
|
if (originValue === void 0) {
|
|
287
293
|
return typeof atom.default === `function` ? atom.default() : atom.default;
|
|
288
294
|
}
|
|
289
|
-
origin.logger.info(`\u{1F4C3}`, `atom`,
|
|
295
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, atom.key, `copying`);
|
|
290
296
|
const jsonValue = atom.toJson(originValue);
|
|
291
297
|
const copiedValue = atom.fromJson(jsonValue);
|
|
292
298
|
target.valueMap.set(atom.key, copiedValue);
|
|
@@ -391,7 +397,7 @@ function createRegularAtomFamily(options, store) {
|
|
|
391
397
|
key: options.key,
|
|
392
398
|
type: `atom_family`,
|
|
393
399
|
subject,
|
|
394
|
-
install: (
|
|
400
|
+
install: (s) => createRegularAtomFamily(options, s)
|
|
395
401
|
}
|
|
396
402
|
);
|
|
397
403
|
const target = newest(store);
|
|
@@ -432,7 +438,7 @@ function createReadonlySelectorFamily(options, store) {
|
|
|
432
438
|
key: options.key,
|
|
433
439
|
type: `readonly_selector_family`,
|
|
434
440
|
subject,
|
|
435
|
-
install: (
|
|
441
|
+
install: (s) => createReadonlySelectorFamily(options, s)
|
|
436
442
|
}
|
|
437
443
|
);
|
|
438
444
|
store.families.set(options.key, readonlySelectorFamily);
|
|
@@ -465,7 +471,7 @@ function createWritableSelectorFamily(options, store) {
|
|
|
465
471
|
key: options.key,
|
|
466
472
|
type: `selector_family`,
|
|
467
473
|
subject,
|
|
468
|
-
install: (
|
|
474
|
+
install: (s) => createWritableSelectorFamily(options, s)
|
|
469
475
|
}
|
|
470
476
|
);
|
|
471
477
|
store.families.set(options.key, selectorFamily);
|
|
@@ -974,7 +980,7 @@ function deleteSelector(selectorToken, store) {
|
|
|
974
980
|
}
|
|
975
981
|
}
|
|
976
982
|
target.selectorGraph.delete(key);
|
|
977
|
-
store.logger.info(`\u{1F525}`, selectorToken.type,
|
|
983
|
+
store.logger.info(`\u{1F525}`, selectorToken.type, key, `deleted`);
|
|
978
984
|
}
|
|
979
985
|
|
|
980
986
|
// internal/src/subscribe/recall-state.ts
|
|
@@ -1153,18 +1159,18 @@ var Tracker = class {
|
|
|
1153
1159
|
this.unsubscribeFromInnerValue();
|
|
1154
1160
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
1155
1161
|
subscriptionKey,
|
|
1156
|
-
(
|
|
1162
|
+
(transceiverUpdate) => {
|
|
1157
1163
|
if (target.operation.open) {
|
|
1158
1164
|
const unsubscribe = target.on.operationClose.subscribe(
|
|
1159
1165
|
subscriptionKey,
|
|
1160
1166
|
() => {
|
|
1161
1167
|
unsubscribe();
|
|
1162
|
-
setIntoStore(latestUpdateState,
|
|
1168
|
+
setIntoStore(latestUpdateState, transceiverUpdate, target);
|
|
1163
1169
|
}
|
|
1164
1170
|
);
|
|
1165
1171
|
} else {
|
|
1166
1172
|
setIntoStore(mutableState, (current) => current, target);
|
|
1167
|
-
setIntoStore(latestUpdateState,
|
|
1173
|
+
setIntoStore(latestUpdateState, transceiverUpdate, target);
|
|
1168
1174
|
}
|
|
1169
1175
|
}
|
|
1170
1176
|
);
|
|
@@ -1273,14 +1279,14 @@ function createMutableAtom(options, family, store) {
|
|
|
1273
1279
|
const subject = new Subject();
|
|
1274
1280
|
const newAtom = __spreadProps(__spreadValues({}, options), {
|
|
1275
1281
|
type: `mutable_atom`,
|
|
1276
|
-
install: (
|
|
1277
|
-
|
|
1282
|
+
install: (s) => {
|
|
1283
|
+
s.logger.info(
|
|
1278
1284
|
`\u{1F6E0}\uFE0F`,
|
|
1279
1285
|
`atom`,
|
|
1280
1286
|
options.key,
|
|
1281
|
-
`installing in store "${
|
|
1287
|
+
`installing in store "${s.config.name}"`
|
|
1282
1288
|
);
|
|
1283
|
-
return createMutableAtom(options, family,
|
|
1289
|
+
return createMutableAtom(options, family, s);
|
|
1284
1290
|
},
|
|
1285
1291
|
subject
|
|
1286
1292
|
});
|
|
@@ -1297,7 +1303,9 @@ function createMutableAtom(options, family, store) {
|
|
|
1297
1303
|
const cleanupFunctions = [];
|
|
1298
1304
|
for (const effect of options.effects) {
|
|
1299
1305
|
const cleanup = effect({
|
|
1300
|
-
setSelf: (next) =>
|
|
1306
|
+
setSelf: (next) => {
|
|
1307
|
+
setIntoStore(token, next, store);
|
|
1308
|
+
},
|
|
1301
1309
|
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1302
1310
|
});
|
|
1303
1311
|
if (cleanup) {
|
|
@@ -1382,7 +1390,7 @@ function createMutableAtomFamily(options, store) {
|
|
|
1382
1390
|
key: options.key,
|
|
1383
1391
|
type: `mutable_atom_family`,
|
|
1384
1392
|
subject,
|
|
1385
|
-
install: (
|
|
1393
|
+
install: (s) => createMutableAtomFamily(options, s),
|
|
1386
1394
|
toJson: options.toJson,
|
|
1387
1395
|
fromJson: options.fromJson
|
|
1388
1396
|
}
|
|
@@ -1478,14 +1486,14 @@ function createRegularAtom(options, family, store) {
|
|
|
1478
1486
|
const subject = new Subject();
|
|
1479
1487
|
const newAtom = __spreadProps(__spreadValues({}, options), {
|
|
1480
1488
|
type: `atom`,
|
|
1481
|
-
install: (
|
|
1482
|
-
|
|
1489
|
+
install: (s) => {
|
|
1490
|
+
s.logger.info(
|
|
1483
1491
|
`\u{1F6E0}\uFE0F`,
|
|
1484
1492
|
`atom`,
|
|
1485
1493
|
options.key,
|
|
1486
|
-
`installing in store "${
|
|
1494
|
+
`installing in store "${s.config.name}"`
|
|
1487
1495
|
);
|
|
1488
|
-
return createRegularAtom(options, family,
|
|
1496
|
+
return createRegularAtom(options, family, s);
|
|
1489
1497
|
},
|
|
1490
1498
|
subject
|
|
1491
1499
|
});
|
|
@@ -1505,7 +1513,9 @@ function createRegularAtom(options, family, store) {
|
|
|
1505
1513
|
const cleanupFunctions = [];
|
|
1506
1514
|
for (const effect of options.effects) {
|
|
1507
1515
|
const cleanup = effect({
|
|
1508
|
-
setSelf: (next) =>
|
|
1516
|
+
setSelf: (next) => {
|
|
1517
|
+
setIntoStore(token, next, store);
|
|
1518
|
+
},
|
|
1509
1519
|
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1510
1520
|
});
|
|
1511
1521
|
if (cleanup) {
|
|
@@ -1542,7 +1552,7 @@ function deleteAtom(atomToken, store) {
|
|
|
1542
1552
|
store.logger.error(
|
|
1543
1553
|
`\u274C`,
|
|
1544
1554
|
`atom`,
|
|
1545
|
-
|
|
1555
|
+
key,
|
|
1546
1556
|
`Tried to delete atom, but it does not exist in the store.`
|
|
1547
1557
|
);
|
|
1548
1558
|
}
|
|
@@ -1565,7 +1575,7 @@ function deleteAtom(atomToken, store) {
|
|
|
1565
1575
|
const updateToken = getUpdateToken(atomToken);
|
|
1566
1576
|
deleteAtom(updateToken, store);
|
|
1567
1577
|
}
|
|
1568
|
-
store.logger.info(`\u{1F525}`, `atom`,
|
|
1578
|
+
store.logger.info(`\u{1F525}`, `atom`, key, `deleted`);
|
|
1569
1579
|
}
|
|
1570
1580
|
|
|
1571
1581
|
// internal/src/arbitrary.ts
|
|
@@ -1709,7 +1719,7 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1709
1719
|
tl.transactionKey = currentTransactionKey;
|
|
1710
1720
|
const unsubscribe = currentTransaction.subject.subscribe(
|
|
1711
1721
|
`timeline:${tl.key}`,
|
|
1712
|
-
(
|
|
1722
|
+
(transactionUpdate) => {
|
|
1713
1723
|
var _a2, _b2;
|
|
1714
1724
|
unsubscribe();
|
|
1715
1725
|
if (tl.timeTraveling === null && currentTransactionInstanceId) {
|
|
@@ -1717,11 +1727,11 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1717
1727
|
tl.history.splice(tl.at);
|
|
1718
1728
|
}
|
|
1719
1729
|
const filterUpdates = (updates2) => updates2.filter((updateFromTx) => {
|
|
1720
|
-
const
|
|
1730
|
+
const newestStore = newest(store);
|
|
1721
1731
|
if (`updates` in updateFromTx) {
|
|
1722
1732
|
return true;
|
|
1723
1733
|
}
|
|
1724
|
-
const atomOrFamilyKeys =
|
|
1734
|
+
const atomOrFamilyKeys = newestStore.timelineAtoms.getRelatedKeys(tl.key);
|
|
1725
1735
|
return atomOrFamilyKeys ? [...atomOrFamilyKeys].some(
|
|
1726
1736
|
(key) => {
|
|
1727
1737
|
var _a3;
|
|
@@ -1736,11 +1746,11 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1736
1746
|
}
|
|
1737
1747
|
return updateFromTx;
|
|
1738
1748
|
});
|
|
1739
|
-
const updates = filterUpdates(
|
|
1749
|
+
const updates = filterUpdates(transactionUpdate.updates);
|
|
1740
1750
|
const timelineTransactionUpdate = __spreadProps(__spreadValues({
|
|
1741
1751
|
type: `transaction_update`,
|
|
1742
1752
|
timestamp: Date.now()
|
|
1743
|
-
},
|
|
1753
|
+
}, transactionUpdate), {
|
|
1744
1754
|
updates
|
|
1745
1755
|
});
|
|
1746
1756
|
const willCapture = (_b2 = (_a2 = tl.shouldCapture) == null ? void 0 : _a2.call(tl, timelineTransactionUpdate, tl)) != null ? _b2 : true;
|
|
@@ -1755,7 +1765,7 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1755
1765
|
`\u231B`,
|
|
1756
1766
|
`timeline`,
|
|
1757
1767
|
tl.key,
|
|
1758
|
-
`got a transaction_update "${
|
|
1768
|
+
`got a transaction_update "${transactionUpdate.key}"`
|
|
1759
1769
|
);
|
|
1760
1770
|
}
|
|
1761
1771
|
);
|
|
@@ -1855,7 +1865,7 @@ function createTimeline(options, store, data) {
|
|
|
1855
1865
|
transactionKey: null
|
|
1856
1866
|
}, data), {
|
|
1857
1867
|
history: (_a = data == null ? void 0 : data.history.map((update) => __spreadValues({}, update))) != null ? _a : [],
|
|
1858
|
-
install: (
|
|
1868
|
+
install: (s) => createTimeline(options, s, tl),
|
|
1859
1869
|
subject: new Subject()
|
|
1860
1870
|
});
|
|
1861
1871
|
if (options.shouldCapture) {
|
|
@@ -2153,9 +2163,11 @@ var buildTransaction = (key, params, store, id) => {
|
|
|
2153
2163
|
},
|
|
2154
2164
|
transactors: {
|
|
2155
2165
|
get: (token) => getFromStore(token, child),
|
|
2156
|
-
set: (token, value) =>
|
|
2157
|
-
|
|
2158
|
-
|
|
2166
|
+
set: (token, value) => {
|
|
2167
|
+
setIntoStore(token, value, child);
|
|
2168
|
+
},
|
|
2169
|
+
run: (token, identifier = arbitrary()) => actUponStore(token, identifier, child),
|
|
2170
|
+
find: (token, k) => findInStore(token, k, child),
|
|
2159
2171
|
env: () => getEnvironmentData(child)
|
|
2160
2172
|
}
|
|
2161
2173
|
};
|
|
@@ -2192,7 +2204,7 @@ function createTransaction(options, store) {
|
|
|
2192
2204
|
throw thrown;
|
|
2193
2205
|
}
|
|
2194
2206
|
},
|
|
2195
|
-
install: (
|
|
2207
|
+
install: (s) => createTransaction(options, s),
|
|
2196
2208
|
subject: new Subject()
|
|
2197
2209
|
};
|
|
2198
2210
|
const target = newest(store);
|
|
@@ -41,14 +41,14 @@ export function createRegularAtom<T>(
|
|
|
41
41
|
const newAtom: RegularAtom<T> = {
|
|
42
42
|
...options,
|
|
43
43
|
type: `atom`,
|
|
44
|
-
install: (
|
|
45
|
-
|
|
44
|
+
install: (s: Store) => {
|
|
45
|
+
s.logger.info(
|
|
46
46
|
`🛠️`,
|
|
47
47
|
`atom`,
|
|
48
48
|
options.key,
|
|
49
|
-
`installing in store "${
|
|
49
|
+
`installing in store "${s.config.name}"`,
|
|
50
50
|
)
|
|
51
|
-
return createRegularAtom(options, family,
|
|
51
|
+
return createRegularAtom(options, family, s)
|
|
52
52
|
},
|
|
53
53
|
subject,
|
|
54
54
|
} as const
|
|
@@ -68,7 +68,9 @@ export function createRegularAtom<T>(
|
|
|
68
68
|
const cleanupFunctions: (() => void)[] = []
|
|
69
69
|
for (const effect of options.effects) {
|
|
70
70
|
const cleanup = effect({
|
|
71
|
-
setSelf: (next) =>
|
|
71
|
+
setSelf: (next) => {
|
|
72
|
+
setIntoStore(token, next, store)
|
|
73
|
+
},
|
|
72
74
|
onSet: (handle: UpdateHandler<T>) =>
|
|
73
75
|
subscribeToState(token, handle, `effect[${effectIndex}]`, store),
|
|
74
76
|
})
|
|
@@ -11,7 +11,7 @@ export function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
|
11
11
|
store.logger.error(
|
|
12
12
|
`❌`,
|
|
13
13
|
`atom`,
|
|
14
|
-
|
|
14
|
+
key,
|
|
15
15
|
`Tried to delete atom, but it does not exist in the store.`,
|
|
16
16
|
)
|
|
17
17
|
}
|
|
@@ -36,5 +36,5 @@ export function deleteAtom(atomToken: AtomToken<unknown>, store: Store): void {
|
|
|
36
36
|
const updateToken = getUpdateToken(atomToken)
|
|
37
37
|
deleteAtom(updateToken, store)
|
|
38
38
|
}
|
|
39
|
-
store.logger.info(`🔥`, `atom`,
|
|
39
|
+
store.logger.info(`🔥`, `atom`, key, `deleted`)
|
|
40
40
|
}
|
|
@@ -35,13 +35,13 @@ export function createReadonlySelectorFamily<T, K extends Json.Serializable>(
|
|
|
35
35
|
},
|
|
36
36
|
family,
|
|
37
37
|
store,
|
|
38
|
-
)
|
|
38
|
+
)
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
key: options.key,
|
|
42
42
|
type: `readonly_selector_family`,
|
|
43
43
|
subject,
|
|
44
|
-
install: (
|
|
44
|
+
install: (s: Store) => createReadonlySelectorFamily(options, s),
|
|
45
45
|
} as const,
|
|
46
46
|
) as ReadonlySelectorFamily<T, K>
|
|
47
47
|
store.families.set(options.key, readonlySelectorFamily)
|
|
@@ -48,7 +48,7 @@ export function createRegularAtomFamily<T, K extends Json.Serializable>(
|
|
|
48
48
|
key: options.key,
|
|
49
49
|
type: `atom_family`,
|
|
50
50
|
subject,
|
|
51
|
-
install: (
|
|
51
|
+
install: (s: Store) => createRegularAtomFamily(options, s),
|
|
52
52
|
} as const,
|
|
53
53
|
)
|
|
54
54
|
const target = newest(store)
|
|
@@ -43,7 +43,7 @@ export function createWritableSelectorFamily<T, K extends Json.Serializable>(
|
|
|
43
43
|
key: options.key,
|
|
44
44
|
type: `selector_family`,
|
|
45
45
|
subject,
|
|
46
|
-
install: (
|
|
46
|
+
install: (s: Store) => createWritableSelectorFamily(options, s),
|
|
47
47
|
} as const,
|
|
48
48
|
) as WritableSelectorFamily<T, K>
|
|
49
49
|
store.families.set(options.key, selectorFamily)
|
package/internal/src/future.ts
CHANGED
|
@@ -16,10 +16,12 @@ export class Future<T> extends Promise<T> {
|
|
|
16
16
|
| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),
|
|
17
17
|
) {
|
|
18
18
|
super((resolve, reject) => {
|
|
19
|
-
const pass = (value: T) =>
|
|
19
|
+
const pass = (value: T) => {
|
|
20
20
|
this.isCanceled ? reject(`canceled`) : resolve(value)
|
|
21
|
-
|
|
21
|
+
}
|
|
22
|
+
const fail = (reason: any) => {
|
|
22
23
|
this.isCanceled ? reject(`canceled`) : reject(reason)
|
|
24
|
+
}
|
|
23
25
|
if (typeof executor === `function`) {
|
|
24
26
|
executor(pass, fail)
|
|
25
27
|
} else {
|
package/internal/src/lineage.ts
CHANGED
|
@@ -57,7 +57,7 @@ export function createMutableAtomFamily<
|
|
|
57
57
|
key: options.key,
|
|
58
58
|
type: `mutable_atom_family`,
|
|
59
59
|
subject,
|
|
60
|
-
install: (
|
|
60
|
+
install: (s: Store) => createMutableAtomFamily(options, s),
|
|
61
61
|
toJson: options.toJson,
|
|
62
62
|
fromJson: options.fromJson,
|
|
63
63
|
} as const,
|
|
@@ -45,14 +45,14 @@ export function createMutableAtom<
|
|
|
45
45
|
const newAtom: MutableAtom<T, J> = {
|
|
46
46
|
...options,
|
|
47
47
|
type: `mutable_atom`,
|
|
48
|
-
install: (
|
|
49
|
-
|
|
48
|
+
install: (s: Store) => {
|
|
49
|
+
s.logger.info(
|
|
50
50
|
`🛠️`,
|
|
51
51
|
`atom`,
|
|
52
52
|
options.key,
|
|
53
|
-
`installing in store "${
|
|
53
|
+
`installing in store "${s.config.name}"`,
|
|
54
54
|
)
|
|
55
|
-
return createMutableAtom(options, family,
|
|
55
|
+
return createMutableAtom(options, family, s)
|
|
56
56
|
},
|
|
57
57
|
subject,
|
|
58
58
|
} as const
|
|
@@ -69,7 +69,9 @@ export function createMutableAtom<
|
|
|
69
69
|
const cleanupFunctions: (() => void)[] = []
|
|
70
70
|
for (const effect of options.effects) {
|
|
71
71
|
const cleanup = effect({
|
|
72
|
-
setSelf: (next) =>
|
|
72
|
+
setSelf: (next) => {
|
|
73
|
+
setIntoStore(token, next, store)
|
|
74
|
+
},
|
|
73
75
|
onSet: (handle: UpdateHandler<T>) =>
|
|
74
76
|
subscribeToState(token, handle, `effect[${effectIndex}]`, store),
|
|
75
77
|
})
|
|
@@ -87,18 +87,18 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
87
87
|
this.unsubscribeFromInnerValue()
|
|
88
88
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
89
89
|
subscriptionKey,
|
|
90
|
-
(
|
|
90
|
+
(transceiverUpdate) => {
|
|
91
91
|
if (target.operation.open) {
|
|
92
92
|
const unsubscribe = target.on.operationClose.subscribe(
|
|
93
93
|
subscriptionKey,
|
|
94
94
|
() => {
|
|
95
95
|
unsubscribe()
|
|
96
|
-
setIntoStore(latestUpdateState,
|
|
96
|
+
setIntoStore(latestUpdateState, transceiverUpdate, target)
|
|
97
97
|
},
|
|
98
98
|
)
|
|
99
99
|
} else {
|
|
100
100
|
setIntoStore(mutableState, (current) => current, target)
|
|
101
|
-
setIntoStore(latestUpdateState,
|
|
101
|
+
setIntoStore(latestUpdateState, transceiverUpdate, target)
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
)
|
|
@@ -23,9 +23,9 @@ export function isTransceiver(
|
|
|
23
23
|
export type TransceiverMode = `playback` | `record` | `transaction`
|
|
24
24
|
|
|
25
25
|
export type Signal<TVR extends Transceiver<any>> = TVR extends Transceiver<
|
|
26
|
-
infer
|
|
26
|
+
infer S
|
|
27
27
|
>
|
|
28
|
-
?
|
|
28
|
+
? S
|
|
29
29
|
: never
|
|
30
30
|
|
|
31
31
|
/*
|
|
@@ -15,7 +15,7 @@ export function copyMutableIfNeeded<T extends Transceiver<any>>(
|
|
|
15
15
|
return typeof atom.default === `function` ? atom.default() : atom.default
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
origin.logger.info(`📃`, `atom`,
|
|
18
|
+
origin.logger.info(`📃`, `atom`, atom.key, `copying`)
|
|
19
19
|
const jsonValue = atom.toJson(originValue)
|
|
20
20
|
const copiedValue = atom.fromJson(jsonValue)
|
|
21
21
|
target.valueMap.set(atom.key, copiedValue)
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
TransactionToken,
|
|
8
8
|
WritableSelectorToken,
|
|
9
9
|
WritableToken,
|
|
10
|
-
|
|
10
|
+
Func,
|
|
11
11
|
} from "atom.io"
|
|
12
12
|
|
|
13
13
|
import type {
|
|
@@ -28,22 +28,22 @@ export function deposit<T extends Transceiver<any>>(
|
|
|
28
28
|
export function deposit<T>(state: WritableSelector<T>): WritableSelectorToken<T>
|
|
29
29
|
export function deposit<T>(state: ReadonlySelector<T>): ReadonlySelectorToken<T>
|
|
30
30
|
export function deposit<T>(state: WritableState<T>): WritableToken<T>
|
|
31
|
-
export function deposit<T>(
|
|
32
|
-
state: Transaction<T
|
|
31
|
+
export function deposit<T extends Func>(
|
|
32
|
+
state: Transaction<T>,
|
|
33
33
|
): TransactionToken<T>
|
|
34
34
|
export function deposit<T>(state: ReadableState<T>): ReadableToken<T>
|
|
35
35
|
export function deposit<T>(
|
|
36
36
|
state:
|
|
37
37
|
| ReadonlySelector<T>
|
|
38
38
|
| RegularAtom<T>
|
|
39
|
-
| Transaction<T extends
|
|
39
|
+
| Transaction<T extends Func ? T : never>
|
|
40
40
|
| WritableSelector<T>
|
|
41
41
|
| (T extends Transceiver<any> ? MutableAtom<T, any> : never),
|
|
42
42
|
):
|
|
43
43
|
| MutableAtomToken<T extends Transceiver<any> ? T : never, any>
|
|
44
44
|
| RegularAtomToken<T>
|
|
45
45
|
| SelectorToken<T>
|
|
46
|
-
| TransactionToken<T> {
|
|
46
|
+
| TransactionToken<T extends Func ? T : never> {
|
|
47
47
|
const token = {
|
|
48
48
|
key: state.key,
|
|
49
49
|
type: state.type,
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
TransactionToken,
|
|
11
11
|
WritableSelectorFamily,
|
|
12
12
|
WritableSelectorToken,
|
|
13
|
-
|
|
13
|
+
Func,
|
|
14
14
|
} from "atom.io"
|
|
15
15
|
|
|
16
16
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
@@ -54,7 +54,7 @@ export class Store implements Lineage {
|
|
|
54
54
|
>()
|
|
55
55
|
|
|
56
56
|
public timelines = new Map<string, Timeline<any>>()
|
|
57
|
-
public transactions = new Map<string, Transaction
|
|
57
|
+
public transactions = new Map<string, Transaction<Func>>()
|
|
58
58
|
|
|
59
59
|
public atomsThatAreDefault = new Set<string>()
|
|
60
60
|
|
|
@@ -85,15 +85,15 @@ export class Store implements Lineage {
|
|
|
85
85
|
selectorCreation: new Subject<
|
|
86
86
|
ReadonlySelectorToken<unknown> | WritableSelectorToken<unknown>
|
|
87
87
|
>(),
|
|
88
|
-
transactionCreation: new Subject<TransactionToken
|
|
88
|
+
transactionCreation: new Subject<TransactionToken<Func>>(),
|
|
89
89
|
timelineCreation: new Subject<TimelineToken<unknown>>(),
|
|
90
|
-
transactionApplying: new StatefulSubject<TransactionProgress
|
|
90
|
+
transactionApplying: new StatefulSubject<TransactionProgress<Func> | null>(
|
|
91
91
|
null,
|
|
92
92
|
),
|
|
93
93
|
operationClose: new Subject<OperationProgress>(),
|
|
94
94
|
}
|
|
95
95
|
public operation: OperationProgress = { open: false }
|
|
96
|
-
public transactionMeta: TransactionEpoch | TransactionProgress
|
|
96
|
+
public transactionMeta: TransactionEpoch | TransactionProgress<Func> = {
|
|
97
97
|
epoch: new Map<string, number>(),
|
|
98
98
|
actionContinuities: new Junction({
|
|
99
99
|
between: [`continuity`, `action`],
|
|
@@ -22,7 +22,7 @@ import type {
|
|
|
22
22
|
WritableSelectorFamilyToken,
|
|
23
23
|
WritableSelectorToken,
|
|
24
24
|
WritableToken,
|
|
25
|
-
|
|
25
|
+
Func,
|
|
26
26
|
} from "atom.io"
|
|
27
27
|
|
|
28
28
|
import type { Json } from "atom.io/json"
|
|
@@ -49,7 +49,6 @@ export type Withdrawable =
|
|
|
49
49
|
| MutableAtom<any, any>
|
|
50
50
|
| MutableAtomFamily<any, any, any>
|
|
51
51
|
| ReadableState<any>
|
|
52
|
-
| ReadableState<any>
|
|
53
52
|
| ReadonlySelector<any>
|
|
54
53
|
| ReadonlySelectorFamily<any, any>
|
|
55
54
|
| RegularAtom<any>
|
|
@@ -118,10 +117,10 @@ export function withdraw<T, K extends Json.Serializable>(
|
|
|
118
117
|
store: Store,
|
|
119
118
|
): SelectorFamily<T, any>
|
|
120
119
|
|
|
121
|
-
export function withdraw<T>(
|
|
120
|
+
export function withdraw<T extends Func>(
|
|
122
121
|
token: TransactionToken<T>,
|
|
123
122
|
store: Store,
|
|
124
|
-
): Transaction<T extends
|
|
123
|
+
): Transaction<T extends Func ? T : never>
|
|
125
124
|
export function withdraw<T>(
|
|
126
125
|
token: TimelineToken<T>,
|
|
127
126
|
store: Store,
|
|
@@ -133,7 +132,7 @@ export function withdraw<T>(
|
|
|
133
132
|
| SelectorFamilyToken<T, any>
|
|
134
133
|
| SelectorToken<T>
|
|
135
134
|
| TimelineToken<T>
|
|
136
|
-
| TransactionToken<T>
|
|
135
|
+
| TransactionToken<T extends Func ? T : never>
|
|
137
136
|
| (T extends Transceiver<any>
|
|
138
137
|
? MutableAtomFamilyToken<T, any, any> | MutableAtomToken<T, any>
|
|
139
138
|
: never),
|
package/internal/src/subject.ts
CHANGED
|
@@ -5,7 +5,9 @@ export class Subject<T> {
|
|
|
5
5
|
|
|
6
6
|
public subscribe(key: string, subscriber: this[`Subscriber`]): () => void {
|
|
7
7
|
this.subscribers.set(key, subscriber)
|
|
8
|
-
const unsubscribe = () =>
|
|
8
|
+
const unsubscribe = () => {
|
|
9
|
+
this.unsubscribe(key)
|
|
10
|
+
}
|
|
9
11
|
return unsubscribe
|
|
10
12
|
}
|
|
11
13
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { TransactionToken, TransactionUpdateHandler,
|
|
1
|
+
import type { TransactionToken, TransactionUpdateHandler, Func } from "atom.io"
|
|
2
2
|
import type { Store } from ".."
|
|
3
3
|
import { withdraw } from ".."
|
|
4
4
|
|
|
5
|
-
export const subscribeToTransaction =
|
|
6
|
-
token: TransactionToken
|
|
7
|
-
handleUpdate: TransactionUpdateHandler
|
|
5
|
+
export const subscribeToTransaction = <F extends Func>(
|
|
6
|
+
token: TransactionToken<F>,
|
|
7
|
+
handleUpdate: TransactionUpdateHandler<F>,
|
|
8
8
|
key: string,
|
|
9
9
|
store: Store,
|
|
10
10
|
): (() => void) => {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
AtomToken,
|
|
3
|
+
TransactionToken,
|
|
4
|
+
TransactionUpdate,
|
|
5
|
+
Func,
|
|
6
|
+
} from "atom.io"
|
|
2
7
|
import type { TimelineUpdate } from "atom.io"
|
|
3
8
|
|
|
4
9
|
import { newest } from "../lineage"
|
|
@@ -82,7 +87,7 @@ export const addAtomToTimeline = (
|
|
|
82
87
|
tl.transactionKey = currentTransactionKey
|
|
83
88
|
const unsubscribe = currentTransaction.subject.subscribe(
|
|
84
89
|
`timeline:${tl.key}`,
|
|
85
|
-
(
|
|
90
|
+
(transactionUpdate) => {
|
|
86
91
|
unsubscribe()
|
|
87
92
|
if (tl.timeTraveling === null && currentTransactionInstanceId) {
|
|
88
93
|
if (tl.at !== tl.history.length) {
|
|
@@ -90,16 +95,16 @@ export const addAtomToTimeline = (
|
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
const filterUpdates = (
|
|
93
|
-
updates: TransactionUpdate
|
|
98
|
+
updates: TransactionUpdate<Func>[`updates`],
|
|
94
99
|
) =>
|
|
95
100
|
updates
|
|
96
101
|
.filter((updateFromTx) => {
|
|
97
|
-
const
|
|
102
|
+
const newestStore = newest(store)
|
|
98
103
|
if (`updates` in updateFromTx) {
|
|
99
104
|
return true
|
|
100
105
|
}
|
|
101
106
|
const atomOrFamilyKeys =
|
|
102
|
-
|
|
107
|
+
newestStore.timelineAtoms.getRelatedKeys(tl.key)
|
|
103
108
|
|
|
104
109
|
return atomOrFamilyKeys
|
|
105
110
|
? [...atomOrFamilyKeys].some(
|
|
@@ -119,12 +124,12 @@ export const addAtomToTimeline = (
|
|
|
119
124
|
return updateFromTx
|
|
120
125
|
})
|
|
121
126
|
|
|
122
|
-
const updates = filterUpdates(
|
|
127
|
+
const updates = filterUpdates(transactionUpdate.updates)
|
|
123
128
|
|
|
124
129
|
const timelineTransactionUpdate: TimelineTransactionUpdate = {
|
|
125
130
|
type: `transaction_update`,
|
|
126
131
|
timestamp: Date.now(),
|
|
127
|
-
...
|
|
132
|
+
...transactionUpdate,
|
|
128
133
|
updates,
|
|
129
134
|
}
|
|
130
135
|
const willCapture =
|
|
@@ -140,7 +145,7 @@ export const addAtomToTimeline = (
|
|
|
140
145
|
`⌛`,
|
|
141
146
|
`timeline`,
|
|
142
147
|
tl.key,
|
|
143
|
-
`got a transaction_update "${
|
|
148
|
+
`got a transaction_update "${transactionUpdate.key}"`,
|
|
144
149
|
)
|
|
145
150
|
},
|
|
146
151
|
)
|