atom.io 0.3.0 → 0.3.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/README.md +4 -6
- package/dist/index.d.ts +37 -35
- package/dist/index.js +188 -95
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +185 -93
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +11 -5
- package/src/internal/families-internal.ts +3 -3
- package/src/internal/get.ts +1 -1
- package/src/internal/index.ts +0 -1
- package/src/internal/operation.ts +15 -3
- package/src/internal/selector-internal.ts +3 -2
- package/src/internal/store.ts +1 -2
- package/src/internal/timeline-internal.ts +112 -15
- package/src/{internal/logger.ts → logger.ts} +2 -2
- package/src/selector.ts +5 -5
- package/src/subscribe.ts +1 -1
- package/src/timeline.ts +2 -7
- package/src/transaction.ts +7 -2
package/dist/index.js
CHANGED
|
@@ -22,20 +22,20 @@ var __spreadValues = (a, b) => {
|
|
|
22
22
|
};
|
|
23
23
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
24
|
var __objRest = (source, exclude) => {
|
|
25
|
-
var
|
|
25
|
+
var target2 = {};
|
|
26
26
|
for (var prop in source)
|
|
27
27
|
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
28
|
-
|
|
28
|
+
target2[prop] = source[prop];
|
|
29
29
|
if (source != null && __getOwnPropSymbols)
|
|
30
30
|
for (var prop of __getOwnPropSymbols(source)) {
|
|
31
31
|
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
32
|
-
|
|
32
|
+
target2[prop] = source[prop];
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return target2;
|
|
35
35
|
};
|
|
36
|
-
var __export = (
|
|
36
|
+
var __export = (target2, all) => {
|
|
37
37
|
for (var name in all)
|
|
38
|
-
__defProp(
|
|
38
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
39
39
|
};
|
|
40
40
|
var __copyProps = (to, from, except, desc) => {
|
|
41
41
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -45,12 +45,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
45
45
|
}
|
|
46
46
|
return to;
|
|
47
47
|
};
|
|
48
|
-
var __toESM = (mod, isNodeMode,
|
|
48
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
49
49
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
50
50
|
// file that has been converted to a CommonJS file using a Babel-
|
|
51
51
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
52
52
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
53
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(
|
|
53
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
54
54
|
mod
|
|
55
55
|
));
|
|
56
56
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
@@ -58,6 +58,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
58
58
|
// src/index.ts
|
|
59
59
|
var src_exports = {};
|
|
60
60
|
__export(src_exports, {
|
|
61
|
+
LOG_LEVELS: () => LOG_LEVELS,
|
|
61
62
|
__INTERNAL__: () => internal_exports,
|
|
62
63
|
atom: () => atom,
|
|
63
64
|
atomFamily: () => atomFamily,
|
|
@@ -82,7 +83,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
82
83
|
var internal_exports = {};
|
|
83
84
|
__export(internal_exports, {
|
|
84
85
|
IMPLICIT: () => IMPLICIT,
|
|
85
|
-
LOG_LEVELS: () => LOG_LEVELS,
|
|
86
86
|
TRANSACTION_PHASES: () => TRANSACTION_PHASES,
|
|
87
87
|
abortTransaction: () => abortTransaction,
|
|
88
88
|
applyTransaction: () => applyTransaction,
|
|
@@ -120,7 +120,6 @@ __export(internal_exports, {
|
|
|
120
120
|
selectorFamily__INTERNAL: () => selectorFamily__INTERNAL,
|
|
121
121
|
selector__INTERNAL: () => selector__INTERNAL,
|
|
122
122
|
setAtomState: () => setAtomState,
|
|
123
|
-
setLogLevel: () => setLogLevel,
|
|
124
123
|
setSelectorState: () => setSelectorState,
|
|
125
124
|
setState__INTERNAL: () => setState__INTERNAL,
|
|
126
125
|
storeAtom: () => storeAtom,
|
|
@@ -136,7 +135,6 @@ __export(internal_exports, {
|
|
|
136
135
|
undoTransactionUpdate: () => undoTransactionUpdate,
|
|
137
136
|
undo__INTERNAL: () => undo__INTERNAL,
|
|
138
137
|
updateSelectorAtoms: () => updateSelectorAtoms,
|
|
139
|
-
useLogger: () => useLogger,
|
|
140
138
|
withdraw: () => withdraw
|
|
141
139
|
});
|
|
142
140
|
|
|
@@ -168,7 +166,7 @@ var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
|
168
166
|
(_a = store.config.logger) == null ? void 0 : _a.info(`>> read "${state.key}"`);
|
|
169
167
|
return readCachedValue(state.key, store);
|
|
170
168
|
}
|
|
171
|
-
if (`
|
|
169
|
+
if (state.type !== `atom`) {
|
|
172
170
|
(_b = store.config.logger) == null ? void 0 : _b.info(`-> calc "${state.key}"`);
|
|
173
171
|
return computeSelectorState(state);
|
|
174
172
|
}
|
|
@@ -631,21 +629,30 @@ var clearStore = (store = IMPLICIT.STORE) => {
|
|
|
631
629
|
};
|
|
632
630
|
|
|
633
631
|
// src/internal/operation.ts
|
|
634
|
-
var openOperation = (store) => {
|
|
635
|
-
var _a;
|
|
632
|
+
var openOperation = (token, store) => {
|
|
633
|
+
var _a, _b;
|
|
636
634
|
const core = target(store);
|
|
635
|
+
if (core.operation.open) {
|
|
636
|
+
console.warn(core.operation.open);
|
|
637
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
638
|
+
`\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
|
|
639
|
+
);
|
|
640
|
+
throw Symbol(`violation`);
|
|
641
|
+
}
|
|
637
642
|
core.operation = {
|
|
638
643
|
open: true,
|
|
639
644
|
done: /* @__PURE__ */ new Set(),
|
|
640
|
-
prev: store.valueMap
|
|
645
|
+
prev: store.valueMap,
|
|
646
|
+
time: Date.now(),
|
|
647
|
+
token
|
|
641
648
|
};
|
|
642
|
-
(
|
|
649
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(`\u2B55 operation start from "${token.key}"`);
|
|
643
650
|
};
|
|
644
651
|
var closeOperation = (store) => {
|
|
645
652
|
var _a;
|
|
646
653
|
const core = target(store);
|
|
647
654
|
core.operation = { open: false };
|
|
648
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F534}
|
|
655
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F534} operation done`);
|
|
649
656
|
};
|
|
650
657
|
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
651
658
|
var _a;
|
|
@@ -878,7 +885,7 @@ function atomFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
878
885
|
var _a;
|
|
879
886
|
const subKey = stringifyJson(key);
|
|
880
887
|
const family = { key: options.key, subKey };
|
|
881
|
-
const fullKey = `${options.key}
|
|
888
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
882
889
|
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
883
890
|
const token = existing ? deposit(existing) : atom__INTERNAL(
|
|
884
891
|
{
|
|
@@ -906,7 +913,7 @@ function readonlySelectorFamily__INTERNAL(options, store) {
|
|
|
906
913
|
(key) => {
|
|
907
914
|
const subKey = stringifyJson(key);
|
|
908
915
|
const family = { key: options.key, subKey };
|
|
909
|
-
const fullKey = `${options.key}
|
|
916
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
910
917
|
const existing = core.readonlySelectors.get(fullKey);
|
|
911
918
|
if (existing) {
|
|
912
919
|
return deposit(existing);
|
|
@@ -938,7 +945,7 @@ function selectorFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
938
945
|
(key) => {
|
|
939
946
|
const subKey = stringifyJson(key);
|
|
940
947
|
const family = { key: options.key, subKey };
|
|
941
|
-
const fullKey = `${options.key}
|
|
948
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
942
949
|
const existing = core.selectors.get(fullKey);
|
|
943
950
|
if (existing) {
|
|
944
951
|
return deposit(existing);
|
|
@@ -962,39 +969,6 @@ function selectorFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
962
969
|
);
|
|
963
970
|
}
|
|
964
971
|
|
|
965
|
-
// src/internal/logger.ts
|
|
966
|
-
var LOG_LEVELS = [
|
|
967
|
-
`info`,
|
|
968
|
-
`warn`,
|
|
969
|
-
`error`
|
|
970
|
-
];
|
|
971
|
-
var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
|
|
972
|
-
const { logger__INTERNAL } = store.config;
|
|
973
|
-
if (preferredLevel === null) {
|
|
974
|
-
store.config.logger = null;
|
|
975
|
-
} else {
|
|
976
|
-
store.config.logger = __spreadValues({}, console);
|
|
977
|
-
LOG_LEVELS.forEach((logLevel) => {
|
|
978
|
-
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
979
|
-
store.config.logger[logLevel] = doNothing;
|
|
980
|
-
} else {
|
|
981
|
-
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
982
|
-
}
|
|
983
|
-
});
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
var useLogger = (logger, store = IMPLICIT.STORE) => {
|
|
987
|
-
var _a;
|
|
988
|
-
const currentLogLevel = store.config.logger === null ? null : (_a = LOG_LEVELS.find(
|
|
989
|
-
(logLevel) => {
|
|
990
|
-
var _a2;
|
|
991
|
-
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== doNothing;
|
|
992
|
-
}
|
|
993
|
-
)) != null ? _a : null;
|
|
994
|
-
store.config.logger__INTERNAL = __spreadValues({}, logger);
|
|
995
|
-
setLogLevel(currentLogLevel, store);
|
|
996
|
-
};
|
|
997
|
-
|
|
998
972
|
// src/internal/selector-internal.ts
|
|
999
973
|
var import_hamt_plus5 = __toESM(require("hamt_plus"));
|
|
1000
974
|
var Rx4 = __toESM(require("rxjs"));
|
|
@@ -1058,8 +1032,9 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
|
1058
1032
|
);
|
|
1059
1033
|
} else {
|
|
1060
1034
|
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1061
|
-
`\u{1F50C} registerSelector "${selectorKey}" <- "${dependency.key}" =`,
|
|
1062
|
-
dependencyValue
|
|
1035
|
+
`\u{1F50C} registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
|
|
1036
|
+
dependencyValue,
|
|
1037
|
+
`)`
|
|
1063
1038
|
);
|
|
1064
1039
|
core.selectorGraph = core.selectorGraph.set(selectorKey, dependency.key, {
|
|
1065
1040
|
source: dependency.key
|
|
@@ -1251,6 +1226,8 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1251
1226
|
// src/internal/timeline-internal.ts
|
|
1252
1227
|
var import_hamt_plus7 = __toESM(require("hamt_plus"));
|
|
1253
1228
|
function timeline__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
1229
|
+
var _a, _b;
|
|
1230
|
+
let incompleteSelectorTime = null;
|
|
1254
1231
|
let incompleteTransactionKey = null;
|
|
1255
1232
|
const timelineData = {
|
|
1256
1233
|
at: 0,
|
|
@@ -1260,9 +1237,11 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
1260
1237
|
const subscribeToAtom = (token) => {
|
|
1261
1238
|
const state = withdraw(token, store);
|
|
1262
1239
|
state.subject.subscribe((update) => {
|
|
1263
|
-
var
|
|
1240
|
+
var _a2, _b2, _c, _d, _e;
|
|
1241
|
+
const storeCurrentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
1242
|
+
const storeCurrentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
1264
1243
|
const storeCurrentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
1265
|
-
(
|
|
1244
|
+
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1266
1245
|
`\u23F3 timeline "${options.key}" saw atom "${token.key}" go (`,
|
|
1267
1246
|
update.oldValue,
|
|
1268
1247
|
`->`,
|
|
@@ -1276,14 +1255,17 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
1276
1255
|
);
|
|
1277
1256
|
if (incompleteTransactionKey !== storeCurrentTransactionKey) {
|
|
1278
1257
|
if (incompleteTransactionKey) {
|
|
1279
|
-
(
|
|
1258
|
+
(_b2 = store.config.logger) == null ? void 0 : _b2.error(
|
|
1280
1259
|
`Timeline "${options.key}" was unable to resolve transaction "${incompleteTransactionKey}. This is probably a bug.`
|
|
1281
1260
|
);
|
|
1282
1261
|
}
|
|
1283
1262
|
incompleteTransactionKey = storeCurrentTransactionKey;
|
|
1284
1263
|
const subscription = currentTransaction.subject.subscribe((update2) => {
|
|
1285
|
-
var
|
|
1264
|
+
var _a3;
|
|
1286
1265
|
if (timelineData.timeTraveling === false) {
|
|
1266
|
+
if (timelineData.at !== timelineData.history.length) {
|
|
1267
|
+
timelineData.history.splice(timelineData.at);
|
|
1268
|
+
}
|
|
1287
1269
|
timelineData.history.push(__spreadProps(__spreadValues({
|
|
1288
1270
|
type: `transaction_update`
|
|
1289
1271
|
}, update2), {
|
|
@@ -1295,35 +1277,95 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
1295
1277
|
timelineData.at = timelineData.history.length;
|
|
1296
1278
|
subscription.unsubscribe();
|
|
1297
1279
|
incompleteTransactionKey = null;
|
|
1298
|
-
(
|
|
1299
|
-
`\u231B timeline "${options.key}"
|
|
1280
|
+
(_a3 = store.config.logger) == null ? void 0 : _a3.info(
|
|
1281
|
+
`\u231B timeline "${options.key}" got a transaction_update "${update2.key}"`
|
|
1300
1282
|
);
|
|
1301
1283
|
});
|
|
1302
1284
|
}
|
|
1285
|
+
} else if (storeCurrentSelectorKey) {
|
|
1286
|
+
if (timelineData.timeTraveling === false) {
|
|
1287
|
+
if (storeCurrentSelectorTime !== incompleteSelectorTime) {
|
|
1288
|
+
const newSelectorUpdate = {
|
|
1289
|
+
type: `selector_update`,
|
|
1290
|
+
key: storeCurrentSelectorKey,
|
|
1291
|
+
atomUpdates: []
|
|
1292
|
+
};
|
|
1293
|
+
newSelectorUpdate.atomUpdates.push(__spreadValues({
|
|
1294
|
+
key: token.key,
|
|
1295
|
+
type: `atom_update`
|
|
1296
|
+
}, update));
|
|
1297
|
+
if (timelineData.at !== timelineData.history.length) {
|
|
1298
|
+
timelineData.history.splice(timelineData.at);
|
|
1299
|
+
}
|
|
1300
|
+
timelineData.history.push(newSelectorUpdate);
|
|
1301
|
+
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1302
|
+
`\u231B timeline "${options.key}" got a selector_update "${storeCurrentSelectorKey}" with`,
|
|
1303
|
+
newSelectorUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1304
|
+
);
|
|
1305
|
+
timelineData.at = timelineData.history.length;
|
|
1306
|
+
incompleteSelectorTime = storeCurrentSelectorTime;
|
|
1307
|
+
} else {
|
|
1308
|
+
const latestUpdate = timelineData.history.at(-1);
|
|
1309
|
+
if ((latestUpdate == null ? void 0 : latestUpdate.type) === `selector_update`) {
|
|
1310
|
+
latestUpdate.atomUpdates.push(__spreadValues({
|
|
1311
|
+
key: token.key,
|
|
1312
|
+
type: `atom_update`
|
|
1313
|
+
}, update));
|
|
1314
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1315
|
+
` \u231B timeline "${options.key}" set selector_update "${storeCurrentSelectorKey}" to`,
|
|
1316
|
+
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1317
|
+
);
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1303
1321
|
} else {
|
|
1304
1322
|
if (timelineData.timeTraveling === false) {
|
|
1323
|
+
incompleteSelectorTime = null;
|
|
1324
|
+
if (timelineData.at !== timelineData.history.length) {
|
|
1325
|
+
timelineData.history.splice(timelineData.at);
|
|
1326
|
+
}
|
|
1305
1327
|
timelineData.history.push({
|
|
1306
|
-
type: `
|
|
1328
|
+
type: `atom_update`,
|
|
1307
1329
|
key: token.key,
|
|
1308
1330
|
oldValue: update.oldValue,
|
|
1309
1331
|
newValue: update.newValue
|
|
1310
1332
|
});
|
|
1311
|
-
(
|
|
1312
|
-
`\u231B timeline "${options.key}"
|
|
1333
|
+
(_e = store.config.logger) == null ? void 0 : _e.info(
|
|
1334
|
+
`\u231B timeline "${options.key}" got a state_update to "${token.key}"`
|
|
1313
1335
|
);
|
|
1314
1336
|
timelineData.at = timelineData.history.length;
|
|
1315
1337
|
}
|
|
1316
1338
|
}
|
|
1317
1339
|
});
|
|
1318
1340
|
};
|
|
1341
|
+
const core = target(store);
|
|
1319
1342
|
for (const tokenOrFamily of options.atoms) {
|
|
1343
|
+
const timelineKey = core.timelineAtoms.getRelatedId(tokenOrFamily.key);
|
|
1344
|
+
if (timelineKey) {
|
|
1345
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1346
|
+
`\u274C Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`
|
|
1347
|
+
);
|
|
1348
|
+
continue;
|
|
1349
|
+
}
|
|
1320
1350
|
if (tokenOrFamily.type === `atom_family`) {
|
|
1321
1351
|
const family = tokenOrFamily;
|
|
1322
1352
|
family.subject.subscribe((token) => subscribeToAtom(token));
|
|
1323
1353
|
} else {
|
|
1324
1354
|
const token = tokenOrFamily;
|
|
1355
|
+
if (`family` in token && token.family) {
|
|
1356
|
+
const familyTimelineKey = core.timelineAtoms.getRelatedId(
|
|
1357
|
+
token.family.key
|
|
1358
|
+
);
|
|
1359
|
+
if (familyTimelineKey) {
|
|
1360
|
+
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1361
|
+
`\u274C Failed to add atom "${token.key}" to timeline "${options.key}" because its family "${token.family.key}" belongs to timeline "${familyTimelineKey}"`
|
|
1362
|
+
);
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1325
1366
|
subscribeToAtom(token);
|
|
1326
1367
|
}
|
|
1368
|
+
core.timelineAtoms = core.timelineAtoms.set(tokenOrFamily.key, options.key);
|
|
1327
1369
|
}
|
|
1328
1370
|
store.timelineStore = import_hamt_plus7.default.set(options.key, timelineData, store.timelineStore);
|
|
1329
1371
|
return {
|
|
@@ -1332,28 +1374,30 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
|
1332
1374
|
};
|
|
1333
1375
|
}
|
|
1334
1376
|
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1335
|
-
var _a, _b;
|
|
1377
|
+
var _a, _b, _c, _d;
|
|
1378
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23E9 redo "${token.key}"`);
|
|
1336
1379
|
const timelineData = store.timelineStore.get(token.key);
|
|
1337
1380
|
if (!timelineData) {
|
|
1338
|
-
(
|
|
1339
|
-
`
|
|
1381
|
+
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1382
|
+
`Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1340
1383
|
);
|
|
1341
1384
|
return;
|
|
1342
1385
|
}
|
|
1343
1386
|
if (timelineData.at === timelineData.history.length) {
|
|
1344
|
-
(
|
|
1345
|
-
`
|
|
1387
|
+
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1388
|
+
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
1346
1389
|
);
|
|
1347
1390
|
return;
|
|
1348
1391
|
}
|
|
1349
1392
|
timelineData.timeTraveling = true;
|
|
1350
1393
|
const update = timelineData.history[timelineData.at];
|
|
1351
1394
|
switch (update.type) {
|
|
1352
|
-
case `
|
|
1395
|
+
case `atom_update`: {
|
|
1353
1396
|
const { key, newValue } = update;
|
|
1354
1397
|
setState({ key, type: `atom` }, newValue);
|
|
1355
1398
|
break;
|
|
1356
1399
|
}
|
|
1400
|
+
case `selector_update`:
|
|
1357
1401
|
case `transaction_update`: {
|
|
1358
1402
|
for (const atomUpdate of update.atomUpdates) {
|
|
1359
1403
|
const { key, newValue } = atomUpdate;
|
|
@@ -1364,19 +1408,23 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
1364
1408
|
}
|
|
1365
1409
|
++timelineData.at;
|
|
1366
1410
|
timelineData.timeTraveling = false;
|
|
1411
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1412
|
+
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1413
|
+
);
|
|
1367
1414
|
};
|
|
1368
1415
|
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1369
|
-
var _a, _b;
|
|
1416
|
+
var _a, _b, _c, _d;
|
|
1417
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23EA undo "${token.key}"`);
|
|
1370
1418
|
const timelineData = store.timelineStore.get(token.key);
|
|
1371
1419
|
if (!timelineData) {
|
|
1372
|
-
(
|
|
1373
|
-
`
|
|
1420
|
+
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1421
|
+
`Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1374
1422
|
);
|
|
1375
1423
|
return;
|
|
1376
1424
|
}
|
|
1377
1425
|
if (timelineData.at === 0) {
|
|
1378
|
-
(
|
|
1379
|
-
`
|
|
1426
|
+
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1427
|
+
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
1380
1428
|
);
|
|
1381
1429
|
return;
|
|
1382
1430
|
}
|
|
@@ -1384,11 +1432,12 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
1384
1432
|
--timelineData.at;
|
|
1385
1433
|
const update = timelineData.history[timelineData.at];
|
|
1386
1434
|
switch (update.type) {
|
|
1387
|
-
case `
|
|
1435
|
+
case `atom_update`: {
|
|
1388
1436
|
const { key, oldValue } = update;
|
|
1389
1437
|
setState({ key, type: `atom` }, oldValue);
|
|
1390
1438
|
break;
|
|
1391
1439
|
}
|
|
1440
|
+
case `selector_update`:
|
|
1392
1441
|
case `transaction_update`: {
|
|
1393
1442
|
for (const atomUpdate of update.atomUpdates) {
|
|
1394
1443
|
const { key, oldValue } = atomUpdate;
|
|
@@ -1398,6 +1447,9 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
|
1398
1447
|
}
|
|
1399
1448
|
}
|
|
1400
1449
|
timelineData.timeTraveling = false;
|
|
1450
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1451
|
+
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1452
|
+
);
|
|
1401
1453
|
};
|
|
1402
1454
|
|
|
1403
1455
|
// src/atom.ts
|
|
@@ -1408,6 +1460,39 @@ function atomFamily(options) {
|
|
|
1408
1460
|
return atomFamily__INTERNAL(options);
|
|
1409
1461
|
}
|
|
1410
1462
|
|
|
1463
|
+
// src/logger.ts
|
|
1464
|
+
var LOG_LEVELS = [
|
|
1465
|
+
`info`,
|
|
1466
|
+
`warn`,
|
|
1467
|
+
`error`
|
|
1468
|
+
];
|
|
1469
|
+
var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
|
|
1470
|
+
const { logger__INTERNAL } = store.config;
|
|
1471
|
+
if (preferredLevel === null) {
|
|
1472
|
+
store.config.logger = null;
|
|
1473
|
+
} else {
|
|
1474
|
+
store.config.logger = __spreadValues({}, console);
|
|
1475
|
+
LOG_LEVELS.forEach((logLevel) => {
|
|
1476
|
+
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
1477
|
+
store.config.logger[logLevel] = doNothing;
|
|
1478
|
+
} else {
|
|
1479
|
+
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
1480
|
+
}
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
var useLogger = (logger, store = IMPLICIT.STORE) => {
|
|
1485
|
+
var _a;
|
|
1486
|
+
const currentLogLevel = store.config.logger === null ? null : (_a = LOG_LEVELS.find(
|
|
1487
|
+
(logLevel) => {
|
|
1488
|
+
var _a2;
|
|
1489
|
+
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== doNothing;
|
|
1490
|
+
}
|
|
1491
|
+
)) != null ? _a : null;
|
|
1492
|
+
store.config.logger__INTERNAL = __spreadValues({}, logger);
|
|
1493
|
+
setLogLevel(currentLogLevel, store);
|
|
1494
|
+
};
|
|
1495
|
+
|
|
1411
1496
|
// src/selector.ts
|
|
1412
1497
|
function selector(options) {
|
|
1413
1498
|
return selector__INTERNAL(options);
|
|
@@ -1416,30 +1501,13 @@ function selectorFamily(options) {
|
|
|
1416
1501
|
return selectorFamily__INTERNAL(options);
|
|
1417
1502
|
}
|
|
1418
1503
|
|
|
1419
|
-
// src/timeline.ts
|
|
1420
|
-
var timeline = (options) => {
|
|
1421
|
-
return timeline__INTERNAL(options);
|
|
1422
|
-
};
|
|
1423
|
-
var redo = (token) => {
|
|
1424
|
-
return redo__INTERNAL(token, IMPLICIT.STORE);
|
|
1425
|
-
};
|
|
1426
|
-
var undo = (token) => {
|
|
1427
|
-
return undo__INTERNAL(token, IMPLICIT.STORE);
|
|
1428
|
-
};
|
|
1429
|
-
|
|
1430
|
-
// src/transaction.ts
|
|
1431
|
-
function transaction(options) {
|
|
1432
|
-
return transaction__INTERNAL(options);
|
|
1433
|
-
}
|
|
1434
|
-
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => withdraw(token, store).run(...parameters);
|
|
1435
|
-
|
|
1436
1504
|
// src/subscribe.ts
|
|
1437
1505
|
var subscribe = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
1438
1506
|
var _a;
|
|
1439
1507
|
const state = withdraw(token, store);
|
|
1440
1508
|
const subscription = state.subject.subscribe(handleUpdate);
|
|
1441
1509
|
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to "${state.key}"`);
|
|
1442
|
-
const dependencySubscriptions = `
|
|
1510
|
+
const dependencySubscriptions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1443
1511
|
const unsubscribe = dependencySubscriptions === null ? () => {
|
|
1444
1512
|
var _a2;
|
|
1445
1513
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
@@ -1469,13 +1537,37 @@ var subscribeToTransaction = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
|
1469
1537
|
return unsubscribe;
|
|
1470
1538
|
};
|
|
1471
1539
|
|
|
1540
|
+
// src/timeline.ts
|
|
1541
|
+
var timeline = (options) => {
|
|
1542
|
+
return timeline__INTERNAL(options);
|
|
1543
|
+
};
|
|
1544
|
+
var redo = (token) => {
|
|
1545
|
+
return redo__INTERNAL(token, IMPLICIT.STORE);
|
|
1546
|
+
};
|
|
1547
|
+
var undo = (token) => {
|
|
1548
|
+
return undo__INTERNAL(token, IMPLICIT.STORE);
|
|
1549
|
+
};
|
|
1550
|
+
|
|
1551
|
+
// src/transaction.ts
|
|
1552
|
+
function transaction(options) {
|
|
1553
|
+
return transaction__INTERNAL(options);
|
|
1554
|
+
}
|
|
1555
|
+
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => withdraw(token, store).run(...parameters);
|
|
1556
|
+
|
|
1472
1557
|
// src/index.ts
|
|
1473
1558
|
var getState = (token, store = IMPLICIT.STORE) => {
|
|
1474
1559
|
const state = withdraw(token, store);
|
|
1475
1560
|
return getState__INTERNAL(state, store);
|
|
1476
1561
|
};
|
|
1477
1562
|
var setState = (token, value, store = IMPLICIT.STORE) => {
|
|
1478
|
-
|
|
1563
|
+
try {
|
|
1564
|
+
openOperation(token, store);
|
|
1565
|
+
} catch (thrown) {
|
|
1566
|
+
if (!(typeof thrown === `symbol`)) {
|
|
1567
|
+
throw thrown;
|
|
1568
|
+
}
|
|
1569
|
+
return;
|
|
1570
|
+
}
|
|
1479
1571
|
const state = withdraw(token, store);
|
|
1480
1572
|
setState__INTERNAL(state, value, store);
|
|
1481
1573
|
closeOperation(store);
|
|
@@ -1483,6 +1575,7 @@ var setState = (token, value, store = IMPLICIT.STORE) => {
|
|
|
1483
1575
|
var isDefault = (token, store = IMPLICIT.STORE) => token.type === `atom` ? isAtomDefault(token.key, store) : isSelectorDefault(token.key, store);
|
|
1484
1576
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1485
1577
|
0 && (module.exports = {
|
|
1578
|
+
LOG_LEVELS,
|
|
1486
1579
|
__INTERNAL__,
|
|
1487
1580
|
atom,
|
|
1488
1581
|
atomFamily,
|