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.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { setState, getState, subscribe } from 'atom.io';
|
|
1
|
+
import { setState, getState, subscribe, subscribeToTimeline } from 'atom.io';
|
|
3
2
|
import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
|
|
4
3
|
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
@@ -126,7 +125,7 @@ var applyTransaction = (output, store) => {
|
|
|
126
125
|
{ key: store.transactionStatus.key, type: `transaction` },
|
|
127
126
|
store
|
|
128
127
|
);
|
|
129
|
-
if (myTransaction ===
|
|
128
|
+
if (myTransaction === void 0) {
|
|
130
129
|
throw new Error(
|
|
131
130
|
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
132
131
|
);
|
|
@@ -414,7 +413,7 @@ var redoTransactionUpdate = (update, store) => {
|
|
|
414
413
|
for (const { key, newValue } of update.atomUpdates) {
|
|
415
414
|
const token = { key, type: `atom` };
|
|
416
415
|
const state = withdraw(token, store);
|
|
417
|
-
if (state ===
|
|
416
|
+
if (state === void 0) {
|
|
418
417
|
throw new Error(
|
|
419
418
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
420
419
|
);
|
|
@@ -428,7 +427,7 @@ var undoTransactionUpdate = (update, store) => {
|
|
|
428
427
|
for (const { key, oldValue } of update.atomUpdates) {
|
|
429
428
|
const token = { key, type: `atom` };
|
|
430
429
|
const state = withdraw(token, store);
|
|
431
|
-
if (state ===
|
|
430
|
+
if (state === void 0) {
|
|
432
431
|
throw new Error(
|
|
433
432
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
434
433
|
);
|
|
@@ -544,7 +543,7 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
544
543
|
// src/timeline/add-atom-to-timeline.ts
|
|
545
544
|
var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
546
545
|
const atom = withdraw(atomToken, store);
|
|
547
|
-
if (atom ===
|
|
546
|
+
if (atom === void 0) {
|
|
548
547
|
throw new Error(
|
|
549
548
|
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
|
|
550
549
|
);
|
|
@@ -576,7 +575,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
|
576
575
|
{ key: currentTransactionKey, type: `transaction` },
|
|
577
576
|
store
|
|
578
577
|
);
|
|
579
|
-
if (currentTransaction ===
|
|
578
|
+
if (currentTransaction === void 0) {
|
|
580
579
|
throw new Error(
|
|
581
580
|
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
|
|
582
581
|
);
|
|
@@ -875,7 +874,7 @@ function withdraw(token, store) {
|
|
|
875
874
|
return state;
|
|
876
875
|
}
|
|
877
876
|
}
|
|
878
|
-
return
|
|
877
|
+
return void 0;
|
|
879
878
|
}
|
|
880
879
|
|
|
881
880
|
// src/store/withdraw-new-family-member.ts
|
|
@@ -894,7 +893,7 @@ function withdrawNewFamilyMember(token, store) {
|
|
|
894
893
|
return state;
|
|
895
894
|
}
|
|
896
895
|
}
|
|
897
|
-
return
|
|
896
|
+
return void 0;
|
|
898
897
|
}
|
|
899
898
|
|
|
900
899
|
// src/caching.ts
|
|
@@ -909,6 +908,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
909
908
|
future.then((value2) => {
|
|
910
909
|
cacheValue(key, value2, subject, store);
|
|
911
910
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
911
|
+
}).catch((error) => {
|
|
912
|
+
var _a;
|
|
913
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
914
|
+
`Promised value for "${key}" rejected:`,
|
|
915
|
+
error
|
|
916
|
+
);
|
|
912
917
|
});
|
|
913
918
|
} else {
|
|
914
919
|
target(store).valueMap.set(key, value);
|
|
@@ -944,7 +949,7 @@ var Tracker = class {
|
|
|
944
949
|
return latestUpdateState;
|
|
945
950
|
}
|
|
946
951
|
observeCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
|
|
947
|
-
const originalInnerValue =
|
|
952
|
+
const originalInnerValue = getState(mutableState, store);
|
|
948
953
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
949
954
|
`tracker:${store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
|
|
950
955
|
(update) => {
|
|
@@ -952,12 +957,12 @@ var Tracker = class {
|
|
|
952
957
|
mutableState.key,
|
|
953
958
|
() => {
|
|
954
959
|
unsubscribe();
|
|
955
|
-
|
|
960
|
+
setState(latestUpdateState, update, store);
|
|
956
961
|
}
|
|
957
962
|
);
|
|
958
963
|
}
|
|
959
964
|
);
|
|
960
|
-
|
|
965
|
+
subscribe(
|
|
961
966
|
mutableState,
|
|
962
967
|
(update) => {
|
|
963
968
|
var _a;
|
|
@@ -970,7 +975,7 @@ var Tracker = class {
|
|
|
970
975
|
mutableState.key,
|
|
971
976
|
() => {
|
|
972
977
|
unsubscribe();
|
|
973
|
-
|
|
978
|
+
setState(latestUpdateState, update2, store);
|
|
974
979
|
}
|
|
975
980
|
);
|
|
976
981
|
}
|
|
@@ -982,7 +987,7 @@ var Tracker = class {
|
|
|
982
987
|
);
|
|
983
988
|
}
|
|
984
989
|
updateCore(mutableState, latestUpdateState, store = IMPLICIT.STORE) {
|
|
985
|
-
|
|
990
|
+
subscribe(
|
|
986
991
|
latestUpdateState,
|
|
987
992
|
({ newValue, oldValue }) => {
|
|
988
993
|
const timelineId = store.timelineAtoms.getRelatedKey(
|
|
@@ -991,11 +996,11 @@ var Tracker = class {
|
|
|
991
996
|
if (timelineId) {
|
|
992
997
|
const timelineData = store.timelines.get(timelineId);
|
|
993
998
|
if (timelineData == null ? void 0 : timelineData.timeTraveling) {
|
|
994
|
-
const unsubscribe2 =
|
|
999
|
+
const unsubscribe2 = subscribeToTimeline(
|
|
995
1000
|
{ key: timelineId, type: `timeline` },
|
|
996
1001
|
(update) => {
|
|
997
1002
|
unsubscribe2();
|
|
998
|
-
|
|
1003
|
+
setState(
|
|
999
1004
|
mutableState,
|
|
1000
1005
|
(transceiver) => {
|
|
1001
1006
|
if (update === `redo` && newValue) {
|
|
@@ -1017,7 +1022,7 @@ var Tracker = class {
|
|
|
1017
1022
|
() => {
|
|
1018
1023
|
unsubscribe();
|
|
1019
1024
|
if (newValue) {
|
|
1020
|
-
|
|
1025
|
+
setState(
|
|
1021
1026
|
mutableState,
|
|
1022
1027
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1023
1028
|
store
|
|
@@ -1041,7 +1046,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
|
|
|
1041
1046
|
const coreState = createAtom(options, void 0, store);
|
|
1042
1047
|
new Tracker(coreState, store);
|
|
1043
1048
|
const jsonState = selectJson(coreState, options, store);
|
|
1044
|
-
|
|
1049
|
+
subscribe(
|
|
1045
1050
|
jsonState,
|
|
1046
1051
|
() => {
|
|
1047
1052
|
var _a2;
|
|
@@ -1129,7 +1134,7 @@ var openOperation = (token, store) => {
|
|
|
1129
1134
|
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1130
1135
|
`\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
|
|
1131
1136
|
);
|
|
1132
|
-
|
|
1137
|
+
return `rejection`;
|
|
1133
1138
|
}
|
|
1134
1139
|
core.operation = {
|
|
1135
1140
|
open: true,
|
|
@@ -1307,8 +1312,8 @@ var stowUpdate = (state, update, store) => {
|
|
|
1307
1312
|
logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
1308
1313
|
};
|
|
1309
1314
|
|
|
1310
|
-
// src/set-state/set-atom
|
|
1311
|
-
var
|
|
1315
|
+
// src/set-state/set-atom.ts
|
|
1316
|
+
var setAtom = (atom, next, store = IMPLICIT.STORE) => {
|
|
1312
1317
|
var _a, _b;
|
|
1313
1318
|
const oldValue = getState__INTERNAL(atom, store);
|
|
1314
1319
|
let newValue = copyMutableIfWithinTransaction(atom, store);
|
|
@@ -1331,22 +1336,12 @@ var setAtomState = (atom, next, store = IMPLICIT.STORE) => {
|
|
|
1331
1336
|
}
|
|
1332
1337
|
};
|
|
1333
1338
|
|
|
1334
|
-
// src/set-state/set-selector-state.ts
|
|
1335
|
-
var setSelectorState = (selector, next, store = IMPLICIT.STORE) => {
|
|
1336
|
-
var _a, _b;
|
|
1337
|
-
const oldValue = getState__INTERNAL(selector, store);
|
|
1338
|
-
const newValue = become(next)(oldValue);
|
|
1339
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector.key}" to`, newValue);
|
|
1340
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector.key}"`);
|
|
1341
|
-
selector.set(newValue);
|
|
1342
|
-
};
|
|
1343
|
-
|
|
1344
1339
|
// src/set-state/set-state-internal.ts
|
|
1345
1340
|
var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
1346
|
-
if (`
|
|
1347
|
-
|
|
1341
|
+
if (state.type === `selector`) {
|
|
1342
|
+
state.set(value);
|
|
1348
1343
|
} else {
|
|
1349
|
-
|
|
1344
|
+
setAtom(state, value, store);
|
|
1350
1345
|
}
|
|
1351
1346
|
};
|
|
1352
1347
|
|
|
@@ -1412,7 +1407,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1412
1407
|
const core = target(store);
|
|
1413
1408
|
const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
|
|
1414
1409
|
const dependencyState = withdraw(dependency, store);
|
|
1415
|
-
if (dependencyState ===
|
|
1410
|
+
if (dependencyState === void 0) {
|
|
1416
1411
|
throw new Error(
|
|
1417
1412
|
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1418
1413
|
);
|
|
@@ -1444,7 +1439,7 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1444
1439
|
},
|
|
1445
1440
|
set: (stateToken, newValue) => {
|
|
1446
1441
|
const state = withdraw(stateToken, store);
|
|
1447
|
-
if (state ===
|
|
1442
|
+
if (state === void 0) {
|
|
1448
1443
|
throw new Error(
|
|
1449
1444
|
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1450
1445
|
);
|
|
@@ -1466,14 +1461,14 @@ var createReadWriteSelector = (options, family, store, core) => {
|
|
|
1466
1461
|
const setSelf = (next) => {
|
|
1467
1462
|
var _a2;
|
|
1468
1463
|
const oldValue = getSelf();
|
|
1464
|
+
const newValue = become(next)(oldValue);
|
|
1469
1465
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1470
1466
|
` <- "${options.key}" went (`,
|
|
1471
1467
|
oldValue,
|
|
1472
1468
|
`->`,
|
|
1473
|
-
|
|
1469
|
+
newValue,
|
|
1474
1470
|
`)`
|
|
1475
1471
|
);
|
|
1476
|
-
const newValue = become(next)(oldValue);
|
|
1477
1472
|
cacheValue(options.key, newValue, subject, store);
|
|
1478
1473
|
markDone(options.key, store);
|
|
1479
1474
|
if (store.transactionStatus.phase === `idle`) {
|
|
@@ -1793,7 +1788,7 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1793
1788
|
var subscribeToRootAtoms = (state, store) => {
|
|
1794
1789
|
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
1795
1790
|
const atom = withdraw(atomToken, store);
|
|
1796
|
-
if (atom ===
|
|
1791
|
+
if (atom === void 0) {
|
|
1797
1792
|
throw new Error(
|
|
1798
1793
|
`Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1799
1794
|
);
|