atom.io 0.8.0 → 0.8.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/dist/index.d.mts +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +67 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -38
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +27 -33
- package/internal/dist/index.d.ts +27 -33
- package/internal/dist/index.js +45 -69
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +34 -39
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/caching.ts +12 -5
- package/internal/src/future.ts +2 -4
- package/internal/src/mutable/create-mutable-atom-family.ts +4 -4
- package/internal/src/mutable/create-mutable-atom.ts +6 -5
- package/internal/src/mutable/is-atom-token-mutable.ts +3 -3
- package/internal/src/mutable/tracker-family.ts +4 -4
- package/internal/src/mutable/tracker.ts +20 -19
- package/internal/src/operation.ts +5 -2
- package/internal/src/selector/create-read-write-selector.ts +2 -2
- package/internal/src/selector/register-selector.ts +2 -2
- package/internal/src/set-state/{set-atom-state.ts → set-atom.ts} +1 -1
- package/internal/src/set-state/set-selector-state.ts +1 -12
- package/internal/src/set-state/set-state-internal.ts +4 -5
- package/internal/src/store/withdraw-new-family-member.ts +7 -7
- package/internal/src/store/withdraw.ts +15 -9
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/timeline/add-atom-to-timeline.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +1 -1
- package/internal/src/transaction/redo-transaction.ts +1 -1
- package/internal/src/transaction/undo-transaction.ts +1 -1
- package/package.json +11 -8
- package/react-devtools/dist/index.d.mts +4 -4
- package/react-devtools/dist/index.d.ts +4 -4
- package/react-devtools/dist/index.js +3 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +3 -3
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime-client/dist/index.d.mts +21 -0
- package/realtime-client/dist/index.d.ts +21 -0
- package/realtime-client/dist/index.js +173 -0
- package/realtime-client/dist/index.js.map +1 -0
- package/realtime-client/dist/index.mjs +144 -0
- package/realtime-client/dist/index.mjs.map +1 -0
- package/realtime-client/package.json +15 -0
- package/realtime-client/src/index.ts +7 -0
- package/realtime-client/src/realtime-state.ts +10 -0
- package/realtime-client/src/use-pull-family-member.ts +26 -0
- package/realtime-client/src/use-pull-mutable-family-member.ts +38 -0
- package/realtime-client/src/use-pull-mutable.ts +32 -0
- package/realtime-client/src/use-pull.ts +19 -0
- package/realtime-client/src/use-push.ts +25 -0
- package/realtime-client/src/use-server-action.ts +49 -0
- package/realtime-server/dist/index.d.mts +25 -0
- package/realtime-server/dist/index.d.ts +25 -0
- package/realtime-server/dist/index.js +316 -0
- package/realtime-server/dist/index.js.map +1 -0
- package/realtime-server/dist/index.mjs +289 -0
- package/realtime-server/dist/index.mjs.map +1 -0
- package/realtime-server/package.json +15 -0
- package/realtime-server/src/README.md +33 -0
- package/realtime-server/src/hook-composition/expose-family.ts +105 -0
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +127 -0
- package/realtime-server/src/hook-composition/expose-mutable.ts +45 -0
- package/realtime-server/src/hook-composition/expose-single.ts +39 -0
- package/realtime-server/src/hook-composition/index.ts +14 -0
- package/realtime-server/src/hook-composition/receive-state.ts +30 -0
- package/realtime-server/src/hook-composition/receive-transaction.ts +37 -0
- package/realtime-server/src/index.ts +1 -0
- package/src/get-set.ts +48 -0
- package/src/index.ts +3 -60
- package/src/subscribe.ts +3 -3
package/internal/dist/index.js
CHANGED
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var atom_io = require('atom.io');
|
|
4
4
|
var json = require('atom.io/json');
|
|
5
5
|
|
|
6
|
-
function _interopNamespace(e) {
|
|
7
|
-
if (e && e.__esModule) return e;
|
|
8
|
-
var n = Object.create(null);
|
|
9
|
-
if (e) {
|
|
10
|
-
Object.keys(e).forEach(function (k) {
|
|
11
|
-
if (k !== 'default') {
|
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () { return e[k]; }
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
n.default = e;
|
|
21
|
-
return Object.freeze(n);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
25
|
-
|
|
26
6
|
var __defProp = Object.defineProperty;
|
|
27
7
|
var __defProps = Object.defineProperties;
|
|
28
8
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -141,13 +121,13 @@ var applyTransaction = (output, store) => {
|
|
|
141
121
|
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
142
122
|
}
|
|
143
123
|
}
|
|
144
|
-
|
|
124
|
+
atom_io.setState(token, newValue, store);
|
|
145
125
|
}
|
|
146
126
|
const myTransaction = withdraw(
|
|
147
127
|
{ key: store.transactionStatus.key, type: `transaction` },
|
|
148
128
|
store
|
|
149
129
|
);
|
|
150
|
-
if (myTransaction ===
|
|
130
|
+
if (myTransaction === void 0) {
|
|
151
131
|
throw new Error(
|
|
152
132
|
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
153
133
|
);
|
|
@@ -403,8 +383,8 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
403
383
|
try {
|
|
404
384
|
const output = options.do(
|
|
405
385
|
{
|
|
406
|
-
get: (token2) =>
|
|
407
|
-
set: (token2, value) =>
|
|
386
|
+
get: (token2) => atom_io.getState(token2, store),
|
|
387
|
+
set: (token2, value) => atom_io.setState(token2, value, store)
|
|
408
388
|
},
|
|
409
389
|
...params
|
|
410
390
|
);
|
|
@@ -435,12 +415,12 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
435
415
|
for (const { key, newValue } of update.atomUpdates) {
|
|
436
416
|
const token = { key, type: `atom` };
|
|
437
417
|
const state = withdraw(token, store);
|
|
438
|
-
if (state ===
|
|
418
|
+
if (state === void 0) {
|
|
439
419
|
throw new Error(
|
|
440
420
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
441
421
|
);
|
|
442
422
|
}
|
|
443
|
-
|
|
423
|
+
atom_io.setState(state, newValue, store);
|
|
444
424
|
}
|
|
445
425
|
};
|
|
446
426
|
var undoTransactionUpdate = (update, store) => {
|
|
@@ -449,12 +429,12 @@ var undoTransactionUpdate = (update, store) => {
|
|
|
449
429
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
450
430
|
const token = { key, type: `atom` };
|
|
451
431
|
const state = withdraw(token, store);
|
|
452
|
-
if (state ===
|
|
432
|
+
if (state === void 0) {
|
|
453
433
|
throw new Error(
|
|
454
434
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
455
435
|
);
|
|
456
436
|
}
|
|
457
|
-
|
|
437
|
+
atom_io.setState(state, oldValue, store);
|
|
458
438
|
}
|
|
459
439
|
};
|
|
460
440
|
|
|
@@ -565,7 +545,7 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
565
545
|
// src/timeline/add-atom-to-timeline.ts
|
|
566
546
|
var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
567
547
|
const atom = withdraw(atomToken, store);
|
|
568
|
-
if (atom ===
|
|
548
|
+
if (atom === void 0) {
|
|
569
549
|
throw new Error(
|
|
570
550
|
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
|
|
571
551
|
);
|
|
@@ -597,7 +577,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
597
577
|
{ key: currentTransactionKey, type: `transaction` },
|
|
598
578
|
store
|
|
599
579
|
);
|
|
600
|
-
if (currentTransaction ===
|
|
580
|
+
if (currentTransaction === void 0) {
|
|
601
581
|
throw new Error(
|
|
602
582
|
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
|
|
603
583
|
);
|
|
@@ -731,14 +711,14 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
731
711
|
switch (update.type) {
|
|
732
712
|
case `atom_update`: {
|
|
733
713
|
const { key, newValue } = update;
|
|
734
|
-
|
|
714
|
+
atom_io.setState({ key, type: `atom` }, newValue, store);
|
|
735
715
|
break;
|
|
736
716
|
}
|
|
737
717
|
case `selector_update`:
|
|
738
718
|
case `transaction_update`: {
|
|
739
719
|
for (const atomUpdate of update.atomUpdates) {
|
|
740
720
|
const { key, newValue } = atomUpdate;
|
|
741
|
-
|
|
721
|
+
atom_io.setState({ key, type: `atom` }, newValue, store);
|
|
742
722
|
}
|
|
743
723
|
break;
|
|
744
724
|
}
|
|
@@ -772,14 +752,14 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
772
752
|
switch (update.type) {
|
|
773
753
|
case `atom_update`: {
|
|
774
754
|
const { key, oldValue } = update;
|
|
775
|
-
|
|
755
|
+
atom_io.setState({ key, type: `atom` }, oldValue, store);
|
|
776
756
|
break;
|
|
777
757
|
}
|
|
778
758
|
case `selector_update`:
|
|
779
759
|
case `transaction_update`: {
|
|
780
760
|
for (const atomUpdate of [...update.atomUpdates].reverse()) {
|
|
781
761
|
const { key, oldValue } = atomUpdate;
|
|
782
|
-
|
|
762
|
+
atom_io.setState({ key, type: `atom` }, oldValue, store);
|
|
783
763
|
}
|
|
784
764
|
break;
|
|
785
765
|
}
|
|
@@ -896,7 +876,7 @@ function withdraw(token, store) {
|
|
|
896
876
|
return state;
|
|
897
877
|
}
|
|
898
878
|
}
|
|
899
|
-
return
|
|
879
|
+
return void 0;
|
|
900
880
|
}
|
|
901
881
|
|
|
902
882
|
// src/store/withdraw-new-family-member.ts
|
|
@@ -915,7 +895,7 @@ function withdrawNewFamilyMember(token, store) {
|
|
|
915
895
|
return state;
|
|
916
896
|
}
|
|
917
897
|
}
|
|
918
|
-
return
|
|
898
|
+
return void 0;
|
|
919
899
|
}
|
|
920
900
|
|
|
921
901
|
// src/caching.ts
|
|
@@ -930,6 +910,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
930
910
|
future.then((value2) => {
|
|
931
911
|
cacheValue(key, value2, subject, store);
|
|
932
912
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
913
|
+
}).catch((error) => {
|
|
914
|
+
var _a;
|
|
915
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
916
|
+
`Promised value for "${key}" rejected:`,
|
|
917
|
+
error
|
|
918
|
+
);
|
|
933
919
|
});
|
|
934
920
|
} else {
|
|
935
921
|
target(store).valueMap.set(key, value);
|
|
@@ -965,7 +951,7 @@ var Tracker = class {
|
|
|
965
951
|
return latestUpdateState;
|
|
966
952
|
}
|
|
967
953
|
observeCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
|
|
968
|
-
const originalInnerValue =
|
|
954
|
+
const originalInnerValue = atom_io.getState(mutableState, store);
|
|
969
955
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
970
956
|
`tracker:${store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
971
957
|
(update) => {
|
|
@@ -973,12 +959,12 @@ var Tracker = class {
|
|
|
973
959
|
mutableState.key,
|
|
974
960
|
() => {
|
|
975
961
|
unsubscribe();
|
|
976
|
-
|
|
962
|
+
atom_io.setState(latestUpdateState, update, store);
|
|
977
963
|
}
|
|
978
964
|
);
|
|
979
965
|
}
|
|
980
966
|
);
|
|
981
|
-
|
|
967
|
+
atom_io.subscribe(
|
|
982
968
|
mutableState,
|
|
983
969
|
(update) => {
|
|
984
970
|
var _a;
|
|
@@ -991,7 +977,7 @@ var Tracker = class {
|
|
|
991
977
|
mutableState.key,
|
|
992
978
|
() => {
|
|
993
979
|
unsubscribe();
|
|
994
|
-
|
|
980
|
+
atom_io.setState(latestUpdateState, update2, store);
|
|
995
981
|
}
|
|
996
982
|
);
|
|
997
983
|
}
|
|
@@ -1003,7 +989,7 @@ var Tracker = class {
|
|
|
1003
989
|
);
|
|
1004
990
|
}
|
|
1005
991
|
updateCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
|
|
1006
|
-
|
|
992
|
+
atom_io.subscribe(
|
|
1007
993
|
latestUpdateState,
|
|
1008
994
|
({ newValue, oldValue }) => {
|
|
1009
995
|
const timelineId = store.timelineAtoms.getRelatedKey(
|
|
@@ -1012,11 +998,11 @@ var Tracker = class {
|
|
|
1012
998
|
if (timelineId) {
|
|
1013
999
|
const timelineData = store.timelines.get(timelineId);
|
|
1014
1000
|
if (timelineData == null ? void 0 : timelineData.timeTraveling) {
|
|
1015
|
-
const unsubscribe2 =
|
|
1001
|
+
const unsubscribe2 = atom_io.subscribeToTimeline(
|
|
1016
1002
|
{ key: timelineId, type: `timeline` },
|
|
1017
1003
|
(update) => {
|
|
1018
1004
|
unsubscribe2();
|
|
1019
|
-
|
|
1005
|
+
atom_io.setState(
|
|
1020
1006
|
mutableState,
|
|
1021
1007
|
(transceiver) => {
|
|
1022
1008
|
if (update === `redo` && newValue) {
|
|
@@ -1038,7 +1024,7 @@ var Tracker = class {
|
|
|
1038
1024
|
() => {
|
|
1039
1025
|
unsubscribe();
|
|
1040
1026
|
if (newValue) {
|
|
1041
|
-
|
|
1027
|
+
atom_io.setState(
|
|
1042
1028
|
mutableState,
|
|
1043
1029
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1044
1030
|
store
|
|
@@ -1062,7 +1048,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1062
1048
|
const coreState = createAtom(options, void 0, store);
|
|
1063
1049
|
new Tracker(coreState, store);
|
|
1064
1050
|
const jsonState = json.selectJson(coreState, options, store);
|
|
1065
|
-
|
|
1051
|
+
atom_io.subscribe(
|
|
1066
1052
|
jsonState,
|
|
1067
1053
|
() => {
|
|
1068
1054
|
var _a2;
|
|
@@ -1150,7 +1136,7 @@ var openOperation = (token, store) => {
|
|
|
1150
1136
|
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1151
1137
|
`\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
|
|
1152
1138
|
);
|
|
1153
|
-
|
|
1139
|
+
return `rejection`;
|
|
1154
1140
|
}
|
|
1155
1141
|
core.operation = {
|
|
1156
1142
|
open: true,
|
|
@@ -1328,8 +1314,8 @@ var stowUpdate = (state, update, store) => {
|
|
|
1328
1314
|
logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
1329
1315
|
};
|
|
1330
1316
|
|
|
1331
|
-
// src/set-state/set-atom
|
|
1332
|
-
var
|
|
1317
|
+
// src/set-state/set-atom.ts
|
|
1318
|
+
var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
1333
1319
|
var _a, _b;
|
|
1334
1320
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1335
1321
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
@@ -1352,22 +1338,12 @@ var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1352
1338
|
}
|
|
1353
1339
|
};
|
|
1354
1340
|
|
|
1355
|
-
// src/set-state/set-selector-state.ts
|
|
1356
|
-
var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
|
|
1357
|
-
var _a, _b;
|
|
1358
|
-
const oldValue = getState__INTERNAL(selector, store);
|
|
1359
|
-
const newValue = become(next)(oldValue);
|
|
1360
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector.key}" to`, newValue);
|
|
1361
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector.key}"`);
|
|
1362
|
-
selector.set(newValue);
|
|
1363
|
-
};
|
|
1364
|
-
|
|
1365
1341
|
// src/set-state/set-state-internal.ts
|
|
1366
1342
|
var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
1367
|
-
if (`
|
|
1368
|
-
|
|
1343
|
+
if (state.type === `selector`) {
|
|
1344
|
+
state.set(value);
|
|
1369
1345
|
} else {
|
|
1370
|
-
|
|
1346
|
+
setAtom(state, value, store);
|
|
1371
1347
|
}
|
|
1372
1348
|
};
|
|
1373
1349
|
|
|
@@ -1433,7 +1409,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1433
1409
|
const core = target(store);
|
|
1434
1410
|
const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
|
|
1435
1411
|
const dependencyState = withdraw(dependency, store);
|
|
1436
|
-
if (dependencyState ===
|
|
1412
|
+
if (dependencyState === void 0) {
|
|
1437
1413
|
throw new Error(
|
|
1438
1414
|
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1439
1415
|
);
|
|
@@ -1465,7 +1441,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1465
1441
|
},
|
|
1466
1442
|
set: (stateToken, newValue) => {
|
|
1467
1443
|
const state = withdraw(stateToken, store);
|
|
1468
|
-
if (state ===
|
|
1444
|
+
if (state === void 0) {
|
|
1469
1445
|
throw new Error(
|
|
1470
1446
|
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1471
1447
|
);
|
|
@@ -1487,14 +1463,14 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1487
1463
|
const setSelf = (next) => {
|
|
1488
1464
|
var _a2;
|
|
1489
1465
|
const oldValue = getSelf();
|
|
1466
|
+
const newValue = become(next)(oldValue);
|
|
1490
1467
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1491
1468
|
` <- "${options.key}" went (`,
|
|
1492
1469
|
oldValue,
|
|
1493
1470
|
`->`,
|
|
1494
|
-
|
|
1471
|
+
newValue,
|
|
1495
1472
|
`)`
|
|
1496
1473
|
);
|
|
1497
|
-
const newValue = become(next)(oldValue);
|
|
1498
1474
|
cacheValue(options.key, newValue, subject, store);
|
|
1499
1475
|
markDone(options.key, store);
|
|
1500
1476
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1780,8 +1756,8 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
|
|
|
1780
1756
|
const token = deposit(newAtom);
|
|
1781
1757
|
for (const effect of (_e = options.effects) != null ? _e : []) {
|
|
1782
1758
|
effect({
|
|
1783
|
-
setSelf: (next) =>
|
|
1784
|
-
onSet: (handle) =>
|
|
1759
|
+
setSelf: (next) => atom_io.setState(token, next, store),
|
|
1760
|
+
onSet: (handle) => atom_io.subscribe(token, handle, `effect[${subject.subscribers.size}]`, store)
|
|
1785
1761
|
});
|
|
1786
1762
|
}
|
|
1787
1763
|
store.subject.atomCreation.next(token);
|
|
@@ -1814,7 +1790,7 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1814
1790
|
var subscribeToRootAtoms = (state, store) => {
|
|
1815
1791
|
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
1816
1792
|
const atom = withdraw(atomToken, store);
|
|
1817
|
-
if (atom ===
|
|
1793
|
+
if (atom === void 0) {
|
|
1818
1794
|
throw new Error(
|
|
1819
1795
|
`Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1820
1796
|
);
|