atom.io 0.6.8 → 0.7.0
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 +21 -2
- package/dist/index.d.mts +42 -461
- package/dist/index.d.ts +42 -461
- package/dist/index.js +128 -1792
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -1742
- package/dist/index.mjs.map +1 -1
- package/internal/dist/index.d.mts +342 -0
- package/internal/dist/index.d.ts +342 -0
- package/internal/dist/index.js +1873 -0
- package/internal/dist/index.js.map +1 -0
- package/internal/dist/index.mjs +1798 -0
- package/internal/dist/index.mjs.map +1 -0
- package/internal/package.json +15 -0
- package/internal/src/atom/create-atom.ts +75 -0
- package/internal/src/atom/delete-atom.ts +10 -0
- package/internal/src/atom/index.ts +3 -0
- package/{src/internal → internal/src/atom}/is-default.ts +4 -2
- package/internal/src/caching.ts +21 -0
- package/internal/src/families/create-atom-family.ts +59 -0
- package/internal/src/families/create-readonly-selector-family.ts +45 -0
- package/internal/src/families/create-selector-family.ts +67 -0
- package/internal/src/families/index.ts +3 -0
- package/internal/src/get-state-internal.ts +23 -0
- package/internal/src/index.ts +13 -0
- package/internal/src/mutable/create-mutable-atom-family.ts +25 -0
- package/internal/src/mutable/create-mutable-atom.ts +49 -0
- package/internal/src/mutable/get-json-token.ts +22 -0
- package/internal/src/mutable/get-update-token.ts +20 -0
- package/internal/src/mutable/index.ts +17 -0
- package/internal/src/mutable/is-atom-token-mutable.ts +7 -0
- package/internal/src/mutable/tracker-family.ts +61 -0
- package/internal/src/mutable/tracker.ts +164 -0
- package/internal/src/mutable/transceiver.ts +110 -0
- package/internal/src/operation.ts +68 -0
- package/{src/internal → internal/src}/selector/create-read-write-selector.ts +10 -13
- package/{src/internal → internal/src}/selector/create-readonly-selector.ts +9 -8
- package/internal/src/selector/create-selector.ts +65 -0
- package/{src/internal → internal/src}/selector/index.ts +1 -0
- package/internal/src/selector/lookup-selector-sources.ts +20 -0
- package/{src/internal → internal/src}/selector/register-selector.ts +13 -9
- package/{src/internal → internal/src}/selector/trace-selector-atoms.ts +4 -2
- package/{src/internal → internal/src}/selector/update-selector-atoms.ts +4 -3
- package/internal/src/set-state/become.ts +10 -0
- package/internal/src/set-state/copy-mutable-if-needed.ts +23 -0
- package/internal/src/set-state/copy-mutable-in-transaction.ts +59 -0
- package/internal/src/set-state/copy-mutable-into-new-store.ts +34 -0
- package/internal/src/set-state/emit-update.ts +23 -0
- package/internal/src/set-state/evict-downstream.ts +39 -0
- package/internal/src/set-state/index.ts +2 -0
- package/internal/src/set-state/set-atom-state.ts +38 -0
- package/internal/src/set-state/set-selector-state.ts +19 -0
- package/internal/src/set-state/set-state-internal.ts +18 -0
- package/internal/src/set-state/stow-update.ts +42 -0
- package/internal/src/store/deposit.ts +43 -0
- package/internal/src/store/index.ts +5 -0
- package/internal/src/store/lookup.ts +26 -0
- package/internal/src/store/store.ts +154 -0
- package/internal/src/store/withdraw-new-family-member.ts +53 -0
- package/internal/src/store/withdraw.ts +113 -0
- package/internal/src/subject.ts +21 -0
- package/internal/src/subscribe/index.ts +1 -0
- package/internal/src/subscribe/recall-state.ts +19 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +47 -0
- package/{src/internal → internal/src}/timeline/add-atom-to-timeline.ts +50 -29
- package/internal/src/timeline/index.ts +3 -0
- package/{src/internal → internal/src/timeline}/time-travel-internal.ts +6 -6
- package/{src/internal → internal/src/timeline}/timeline-internal.ts +20 -12
- package/{src/internal → internal/src}/transaction/abort-transaction.ts +1 -1
- package/{src/internal → internal/src}/transaction/apply-transaction.ts +25 -18
- package/{src/internal → internal/src}/transaction/build-transaction.ts +12 -6
- package/{src/internal → internal/src}/transaction/index.ts +3 -2
- package/{src/internal → internal/src}/transaction/redo-transaction.ts +4 -5
- package/{src/internal → internal/src/transaction}/transaction-internal.ts +16 -13
- package/{src/internal → internal/src}/transaction/undo-transaction.ts +4 -5
- package/introspection/dist/index.d.mts +12 -260
- package/introspection/dist/index.d.ts +12 -260
- package/introspection/dist/index.js +125 -140
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +103 -116
- package/introspection/dist/index.mjs.map +1 -1
- package/{src/introspection → introspection/src}/attach-atom-index.ts +41 -30
- package/{src/introspection → introspection/src}/attach-introspection-states.ts +6 -10
- package/introspection/src/attach-selector-index.ts +90 -0
- package/{src/introspection → introspection/src}/attach-timeline-family.ts +16 -16
- package/introspection/src/attach-timeline-index.ts +38 -0
- package/introspection/src/attach-transaction-index.ts +40 -0
- package/{src/introspection → introspection/src}/attach-transaction-logs.ts +11 -8
- package/json/dist/index.d.mts +41 -2
- package/json/dist/index.d.ts +41 -2
- package/json/dist/index.js +88 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +76 -13
- package/json/dist/index.mjs.map +1 -1
- package/json/src/index.ts +5 -0
- package/json/src/select-json-family.ts +35 -0
- package/json/src/select-json.ts +22 -0
- package/package.json +105 -57
- package/react/dist/index.d.mts +9 -17
- package/react/dist/index.d.ts +9 -17
- package/react/dist/index.js +45 -77
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +18 -34
- package/react/dist/index.mjs.map +1 -1
- package/react/src/store-context.tsx +12 -0
- package/react/src/store-hooks.ts +36 -0
- package/react-devtools/dist/index.css +1 -1
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +199 -230
- package/react-devtools/dist/index.d.ts +199 -230
- package/react-devtools/dist/index.js +610 -2466
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +543 -2401
- package/react-devtools/dist/index.mjs.map +1 -1
- package/{src/react-devtools → react-devtools/src}/AtomIODevtools.tsx +5 -3
- package/{src/react-devtools → react-devtools/src}/Button.tsx +2 -3
- package/{src/react-devtools → react-devtools/src}/StateEditor.tsx +3 -2
- package/{src/react-devtools → react-devtools/src}/StateIndex.tsx +7 -4
- package/{src/react-devtools → react-devtools/src}/TimelineIndex.tsx +7 -11
- package/{src/react-devtools → react-devtools/src}/TransactionIndex.tsx +4 -4
- package/{src/react-devtools → react-devtools/src}/Updates.tsx +9 -4
- package/{src/react-devtools → react-devtools/src}/index.ts +5 -5
- package/realtime-react/dist/index.d.mts +9 -25
- package/realtime-react/dist/index.d.ts +9 -25
- package/realtime-react/dist/index.js +75 -193
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +44 -148
- package/realtime-react/dist/index.mjs.map +1 -1
- package/realtime-react/src/index.ts +7 -0
- package/{src/realtime-react → realtime-react/src}/realtime-context.tsx +3 -4
- package/realtime-react/src/use-pull-family-member.ts +15 -0
- package/realtime-react/src/use-pull-mutable-family-member.ts +20 -0
- package/realtime-react/src/use-pull-mutable.ts +17 -0
- package/realtime-react/src/use-pull.ts +15 -0
- package/realtime-react/src/use-push.ts +19 -0
- package/realtime-react/src/use-server-action.ts +18 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +147 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +116 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/{src/realtime-testing → realtime-testing/src}/setup-realtime-test.tsx +10 -8
- package/src/atom.ts +64 -8
- package/src/index.ts +36 -29
- package/src/logger.ts +7 -7
- package/src/selector.ts +5 -5
- package/src/silo.ts +49 -43
- package/src/subscribe.ts +27 -22
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/transceivers/set-rtx/dist/index.d.mts +39 -0
- package/transceivers/set-rtx/dist/index.d.ts +39 -0
- package/transceivers/set-rtx/dist/index.js +213 -0
- package/transceivers/set-rtx/dist/index.js.map +1 -0
- package/transceivers/set-rtx/dist/index.mjs +211 -0
- package/transceivers/set-rtx/dist/index.mjs.map +1 -0
- package/{realtime → transceivers/set-rtx}/package.json +1 -1
- package/transceivers/set-rtx/src/index.ts +1 -0
- package/transceivers/set-rtx/src/set-rtx.ts +242 -0
- package/realtime/dist/index.d.mts +0 -25
- package/realtime/dist/index.d.ts +0 -25
- package/realtime/dist/index.js +0 -190
- package/realtime/dist/index.js.map +0 -1
- package/realtime/dist/index.mjs +0 -151
- package/realtime/dist/index.mjs.map +0 -1
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -144
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector-internal.ts +0 -58
- package/src/internal/set.ts +0 -99
- package/src/internal/store.ts +0 -151
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/timeline/index.ts +0 -1
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-explorer/AtomIOExplorer.tsx +0 -218
- package/src/react-explorer/explorer-effects.ts +0 -20
- package/src/react-explorer/explorer-states.ts +0 -217
- package/src/react-explorer/index.ts +0 -23
- package/src/react-explorer/space-states.ts +0 -72
- package/src/react-explorer/view-states.ts +0 -41
- package/src/realtime/README.md +0 -33
- package/src/realtime/hook-composition/expose-family.ts +0 -101
- package/src/realtime/hook-composition/expose-single.ts +0 -38
- package/src/realtime/hook-composition/expose-timeline.ts +0 -60
- package/src/realtime/hook-composition/index.ts +0 -12
- package/src/realtime/hook-composition/receive-state.ts +0 -29
- package/src/realtime/hook-composition/receive-transaction.ts +0 -18
- package/src/realtime/index.ts +0 -1
- package/src/realtime-react/index.ts +0 -3
- package/src/realtime-react/realtime-hooks.ts +0 -39
- package/src/realtime-react/realtime-state.ts +0 -10
- package/src/realtime-react/use-pull-family-member.ts +0 -26
- package/src/realtime-react/use-pull-family.ts +0 -24
- package/src/realtime-react/use-pull.ts +0 -24
- package/src/realtime-react/use-push.ts +0 -27
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/tracker/index.ts +0 -3
- package/src/tracker/tracker.ts +0 -61
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
- /package/{src/introspection → introspection/src}/index.ts +0 -0
- /package/{src/react → react/src}/index.ts +0 -0
- /package/{src/react-devtools → react-devtools/src}/devtools.scss +0 -0
- /package/{src/realtime-testing → realtime-testing/src}/index.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var IO = require('atom.io/internal');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var IO__namespace = /*#__PURE__*/_interopNamespace(IO);
|
|
24
|
+
|
|
1
25
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
26
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
27
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
28
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -18,1710 +38,25 @@ var __spreadValues = (a, b) => {
|
|
|
18
38
|
}
|
|
19
39
|
return a;
|
|
20
40
|
};
|
|
21
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
-
var __objRest = (source, exclude) => {
|
|
23
|
-
var target2 = {};
|
|
24
|
-
for (var prop in source)
|
|
25
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
26
|
-
target2[prop] = source[prop];
|
|
27
|
-
if (source != null && __getOwnPropSymbols)
|
|
28
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
29
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
30
|
-
target2[prop] = source[prop];
|
|
31
|
-
}
|
|
32
|
-
return target2;
|
|
33
|
-
};
|
|
34
|
-
var __export = (target2, all) => {
|
|
35
|
-
for (var name in all)
|
|
36
|
-
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
37
|
-
};
|
|
38
|
-
var __copyProps = (to, from, except, desc) => {
|
|
39
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
40
|
-
for (let key of __getOwnPropNames(from))
|
|
41
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
42
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
43
|
-
}
|
|
44
|
-
return to;
|
|
45
|
-
};
|
|
46
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
47
|
-
|
|
48
|
-
// src/index.ts
|
|
49
|
-
var src_exports = {};
|
|
50
|
-
__export(src_exports, {
|
|
51
|
-
LOG_LEVELS: () => LOG_LEVELS,
|
|
52
|
-
__INTERNAL__: () => internal_exports,
|
|
53
|
-
atom: () => atom,
|
|
54
|
-
atomFamily: () => atomFamily,
|
|
55
|
-
getState: () => getState,
|
|
56
|
-
isDefault: () => isDefault,
|
|
57
|
-
redo: () => redo,
|
|
58
|
-
runTransaction: () => runTransaction,
|
|
59
|
-
selector: () => selector,
|
|
60
|
-
selectorFamily: () => selectorFamily,
|
|
61
|
-
setLogLevel: () => setLogLevel,
|
|
62
|
-
setState: () => setState,
|
|
63
|
-
silo: () => silo,
|
|
64
|
-
subscribe: () => subscribe,
|
|
65
|
-
subscribeToTimeline: () => subscribeToTimeline,
|
|
66
|
-
subscribeToTransaction: () => subscribeToTransaction,
|
|
67
|
-
timeline: () => timeline,
|
|
68
|
-
transaction: () => transaction,
|
|
69
|
-
undo: () => undo,
|
|
70
|
-
useLogger: () => useLogger
|
|
71
|
-
});
|
|
72
|
-
module.exports = __toCommonJS(src_exports);
|
|
73
|
-
|
|
74
|
-
// ../anvl/src/string/capitalize.ts
|
|
75
|
-
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
76
|
-
|
|
77
|
-
// src/internal/index.ts
|
|
78
|
-
var internal_exports = {};
|
|
79
|
-
__export(internal_exports, {
|
|
80
|
-
IMPLICIT: () => IMPLICIT,
|
|
81
|
-
Subject: () => Subject,
|
|
82
|
-
TRANSACTION_PHASES: () => TRANSACTION_PHASES,
|
|
83
|
-
abortTransaction: () => abortTransaction,
|
|
84
|
-
applyTransaction: () => applyTransaction,
|
|
85
|
-
atomFamily__INTERNAL: () => atomFamily__INTERNAL,
|
|
86
|
-
atom__INTERNAL: () => atom__INTERNAL,
|
|
87
|
-
buildTransaction: () => buildTransaction,
|
|
88
|
-
cacheValue: () => cacheValue,
|
|
89
|
-
clearStore: () => clearStore,
|
|
90
|
-
closeOperation: () => closeOperation,
|
|
91
|
-
computeSelectorState: () => computeSelectorState,
|
|
92
|
-
createStore: () => createStore,
|
|
93
|
-
deposit: () => deposit,
|
|
94
|
-
emitUpdate: () => emitUpdate,
|
|
95
|
-
evictCachedValue: () => evictCachedValue,
|
|
96
|
-
evictDownStream: () => evictDownStream,
|
|
97
|
-
getState__INTERNAL: () => getState__INTERNAL,
|
|
98
|
-
hasKeyBeenUsed: () => hasKeyBeenUsed,
|
|
99
|
-
isAtomDefault: () => isAtomDefault,
|
|
100
|
-
isDone: () => isDone,
|
|
101
|
-
isSelectorDefault: () => isSelectorDefault,
|
|
102
|
-
isValueCached: () => isValueCached,
|
|
103
|
-
lookup: () => lookup,
|
|
104
|
-
lookupSelectorSources: () => lookupSelectorSources,
|
|
105
|
-
markAtomAsDefault: () => markAtomAsDefault,
|
|
106
|
-
markAtomAsNotDefault: () => markAtomAsNotDefault,
|
|
107
|
-
markDone: () => markDone,
|
|
108
|
-
openOperation: () => openOperation,
|
|
109
|
-
prepareUpdate: () => prepareUpdate,
|
|
110
|
-
readCachedValue: () => readCachedValue,
|
|
111
|
-
readonlySelectorFamily__INTERNAL: () => readonlySelectorFamily__INTERNAL,
|
|
112
|
-
recallState: () => recallState,
|
|
113
|
-
redoTransactionUpdate: () => redoTransactionUpdate,
|
|
114
|
-
redo__INTERNAL: () => redo__INTERNAL,
|
|
115
|
-
registerSelector: () => registerSelector,
|
|
116
|
-
selectorFamily__INTERNAL: () => selectorFamily__INTERNAL,
|
|
117
|
-
selector__INTERNAL: () => selector__INTERNAL,
|
|
118
|
-
setAtomState: () => setAtomState,
|
|
119
|
-
setSelectorState: () => setSelectorState,
|
|
120
|
-
setState__INTERNAL: () => setState__INTERNAL,
|
|
121
|
-
storeAtom: () => storeAtom,
|
|
122
|
-
storeReadonlySelector: () => storeReadonlySelector,
|
|
123
|
-
storeSelector: () => storeSelector,
|
|
124
|
-
stowUpdate: () => stowUpdate,
|
|
125
|
-
subscribeToRootAtoms: () => subscribeToRootAtoms,
|
|
126
|
-
target: () => target,
|
|
127
|
-
timeline__INTERNAL: () => timeline__INTERNAL,
|
|
128
|
-
traceAllSelectorAtoms: () => traceAllSelectorAtoms,
|
|
129
|
-
traceSelectorAtoms: () => traceSelectorAtoms,
|
|
130
|
-
transaction__INTERNAL: () => transaction__INTERNAL,
|
|
131
|
-
undoTransactionUpdate: () => undoTransactionUpdate,
|
|
132
|
-
undo__INTERNAL: () => undo__INTERNAL,
|
|
133
|
-
updateSelectorAtoms: () => updateSelectorAtoms,
|
|
134
|
-
withdraw: () => withdraw
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// src/internal/get.ts
|
|
138
|
-
var computeSelectorState = (selector2) => selector2.get();
|
|
139
|
-
function lookup(key, store) {
|
|
140
|
-
const core = target(store);
|
|
141
|
-
const type = core.atoms.has(key) ? `atom` : core.selectors.has(key) ? `selector` : `readonly_selector`;
|
|
142
|
-
return { key, type };
|
|
143
|
-
}
|
|
144
|
-
function withdraw(token, store) {
|
|
145
|
-
var _a, _b, _c, _d, _e;
|
|
146
|
-
const core = target(store);
|
|
147
|
-
return (_e = (_d = (_c = (_b = (_a = core.atoms.get(token.key)) != null ? _a : core.selectors.get(token.key)) != null ? _b : core.readonlySelectors.get(token.key)) != null ? _c : core.transactions.get(token.key)) != null ? _d : core.timelines.get(token.key)) != null ? _e : null;
|
|
148
|
-
}
|
|
149
|
-
function deposit(state) {
|
|
150
|
-
return __spreadValues({
|
|
151
|
-
key: state.key,
|
|
152
|
-
type: state.type
|
|
153
|
-
}, `family` in state && { family: state.family });
|
|
154
|
-
}
|
|
155
|
-
var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
|
|
156
|
-
var _a, _b, _c;
|
|
157
|
-
if (isValueCached(state.key, store)) {
|
|
158
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`>> read "${state.key}"`);
|
|
159
|
-
return readCachedValue(state.key, store);
|
|
160
|
-
}
|
|
161
|
-
if (state.type !== `atom`) {
|
|
162
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`-> calc "${state.key}"`);
|
|
163
|
-
return computeSelectorState(state);
|
|
164
|
-
}
|
|
165
|
-
(_c = store.config.logger) == null ? void 0 : _c.error(
|
|
166
|
-
`Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
|
|
167
|
-
);
|
|
168
|
-
return state.default;
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
// src/internal/is-default.ts
|
|
172
|
-
var isAtomDefault = (key, store = IMPLICIT.STORE) => {
|
|
173
|
-
const core = target(store);
|
|
174
|
-
return core.atomsThatAreDefault.has(key);
|
|
175
|
-
};
|
|
176
|
-
var markAtomAsDefault = (key, store = IMPLICIT.STORE) => {
|
|
177
|
-
const core = target(store);
|
|
178
|
-
core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key);
|
|
179
|
-
};
|
|
180
|
-
var markAtomAsNotDefault = (key, store = IMPLICIT.STORE) => {
|
|
181
|
-
const core = target(store);
|
|
182
|
-
core.atomsThatAreDefault = new Set(target(store).atomsThatAreDefault);
|
|
183
|
-
core.atomsThatAreDefault.delete(key);
|
|
184
|
-
};
|
|
185
|
-
var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
186
|
-
const roots = traceAllSelectorAtoms(key, store);
|
|
187
|
-
return roots.every((root) => isAtomDefault(root.key, store));
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
// ../anvl/src/function/index.ts
|
|
191
|
-
var doNothing = () => void 0;
|
|
192
|
-
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
193
|
-
originalThing instanceof Function ? originalThing() : originalThing
|
|
194
|
-
) : nextVersionOfThing;
|
|
195
|
-
var pass = (...params) => (fn) => fn(...params);
|
|
196
|
-
|
|
197
|
-
// ../anvl/src/join/core-relation-data.ts
|
|
198
|
-
var import_string = require("fp-ts/string");
|
|
199
|
-
|
|
200
|
-
// ../anvl/src/array/venn.ts
|
|
201
|
-
var includesAll = (items) => (array) => {
|
|
202
|
-
for (const item of items) {
|
|
203
|
-
if (!array.includes(item))
|
|
204
|
-
return false;
|
|
205
|
-
}
|
|
206
|
-
return true;
|
|
207
|
-
};
|
|
208
|
-
var comprises = (items) => (array) => includesAll(items)(array) && includesAll(array)(items);
|
|
209
|
-
|
|
210
|
-
// ../anvl/src/array/index.ts
|
|
211
|
-
var isArray = (isType) => (input) => Array.isArray(input) && input.every((item) => isType(item));
|
|
212
|
-
var map = (f) => (a) => a.map(f);
|
|
213
|
-
var every = (f = Boolean) => (a) => a.every(f);
|
|
214
|
-
var allTrue = every((x) => x === true);
|
|
215
|
-
var addTo = (a) => (x) => a.includes(x) ? a : [...a, x];
|
|
216
|
-
var isEmptyArray = (input) => Array.isArray(input) && input.length === 0;
|
|
217
|
-
var isOneOf = (...args) => (input) => args.includes(input);
|
|
218
|
-
|
|
219
|
-
// ../anvl/src/object/refinement.ts
|
|
220
|
-
var import_function2 = require("fp-ts/function");
|
|
221
|
-
|
|
222
|
-
// ../anvl/src/object/access.ts
|
|
223
|
-
var access = (k) => Object.assign((obj) => obj[k], {
|
|
224
|
-
in: (obj) => obj[k]
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
// ../anvl/src/object/entries.ts
|
|
228
|
-
var recordToEntries = (obj) => Object.entries(obj);
|
|
229
|
-
var entriesToRecord = (entries) => Object.fromEntries(entries);
|
|
230
|
-
|
|
231
|
-
// ../anvl/src/object/mapObject.ts
|
|
232
|
-
var import_function = require("fp-ts/function");
|
|
233
|
-
var mapObject = (obj, fn) => (0, import_function.pipe)(
|
|
234
|
-
obj,
|
|
235
|
-
recordToEntries,
|
|
236
|
-
map(([key, val]) => [key, fn(val, key)]),
|
|
237
|
-
entriesToRecord
|
|
238
|
-
);
|
|
239
|
-
var mob = (fn) => (obj) => mapObject(obj, fn);
|
|
240
|
-
|
|
241
|
-
// ../anvl/src/nullish/index.ts
|
|
242
|
-
var isUndefined = (input) => input === void 0;
|
|
243
|
-
var ifNullish = (alt) => (input) => input != null ? input : alt;
|
|
244
|
-
|
|
245
|
-
// ../anvl/src/object/refinement.ts
|
|
246
|
-
var isNonNullObject = (input) => typeof input === `object` && input !== null;
|
|
247
|
-
var isPlainObject = (input) => isNonNullObject(input) && Object.getPrototypeOf(input) === Object.prototype;
|
|
248
|
-
var isEmptyObject = (input) => isPlainObject(input) && Object.keys(input).length === 0;
|
|
249
|
-
var isRecord = (isKey, isValue) => (input) => isPlainObject(input) && Object.entries(input).every(([k, v]) => isKey(k) && isValue(v));
|
|
250
|
-
var hasProperties = (isValue, options = { allowExtraProperties: false }) => {
|
|
251
|
-
const name = `{${recordToEntries(
|
|
252
|
-
isValue
|
|
253
|
-
).map(([k, v]) => String(k) + `:` + v.name).join(`,`)}}`;
|
|
254
|
-
const _ = {
|
|
255
|
-
[name]: (input) => isPlainObject(input) && (0, import_function2.pipe)(
|
|
256
|
-
isValue,
|
|
257
|
-
Object.entries,
|
|
258
|
-
every(([key, val]) => key in input || val(void 0))
|
|
259
|
-
) && (0, import_function2.pipe)(
|
|
260
|
-
input,
|
|
261
|
-
mob(
|
|
262
|
-
(val, key) => (0, import_function2.pipe)(
|
|
263
|
-
isValue,
|
|
264
|
-
access(key),
|
|
265
|
-
ifNullish(() => options.allowExtraProperties),
|
|
266
|
-
pass(val)
|
|
267
|
-
)
|
|
268
|
-
),
|
|
269
|
-
Object.values,
|
|
270
|
-
allTrue
|
|
271
|
-
)
|
|
272
|
-
};
|
|
273
|
-
return _[name];
|
|
274
|
-
};
|
|
275
|
-
var hasExactProperties = (
|
|
276
|
-
/* alias for hasProperties without allowExtraProperties */
|
|
277
|
-
(isValue) => hasProperties(isValue, { allowExtraProperties: false })
|
|
278
|
-
);
|
|
279
|
-
|
|
280
|
-
// ../anvl/src/refinement/index.ts
|
|
281
|
-
var canExist = (_) => true;
|
|
282
|
-
var cannotExist = (_) => false;
|
|
283
|
-
var isLiteral = (value) => (input) => input === value;
|
|
284
|
-
var couldBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
285
|
-
const name = `(${refinements.map((r) => r.name || `anon`).join(` | `)})`;
|
|
286
|
-
const _ = {
|
|
287
|
-
[name]: (input) => refinements.some(
|
|
288
|
-
(refinement) => {
|
|
289
|
-
var _a;
|
|
290
|
-
return logging && console.log(
|
|
291
|
-
refinements.map((r) => r.name || `anon`).join(` | `),
|
|
292
|
-
`>`,
|
|
293
|
-
(_a = refinement.name) != null ? _a : `anon`,
|
|
294
|
-
`:`,
|
|
295
|
-
refinement(input)
|
|
296
|
-
), refinement(input);
|
|
297
|
-
}
|
|
298
|
-
)
|
|
299
|
-
};
|
|
300
|
-
const checkTypes = Object.assign(_[name], {
|
|
301
|
-
or: (isTypeB) => couldBe(isTypeB, logging, [...refinements, isTypeB])
|
|
302
|
-
});
|
|
303
|
-
return checkTypes;
|
|
304
|
-
};
|
|
305
|
-
var isUnion = couldBe(cannotExist);
|
|
306
|
-
var mustBe = (isTypeA, logging = false, refinements = [isTypeA]) => {
|
|
307
|
-
const name = `(${refinements.map((r) => r.name || `anon`).join(` & `)})`;
|
|
308
|
-
const _ = {
|
|
309
|
-
[name]: (input) => refinements.every(
|
|
310
|
-
(refinement) => (logging && console.log(
|
|
311
|
-
refinements.map((r) => r.name || `anon`).join(` & `),
|
|
312
|
-
`>`,
|
|
313
|
-
refinement.name || `anon`,
|
|
314
|
-
`:`,
|
|
315
|
-
refinement(input)
|
|
316
|
-
), refinement(input))
|
|
317
|
-
)
|
|
318
|
-
};
|
|
319
|
-
const checkTypes = Object.assign(_[name], {
|
|
320
|
-
and: (isTypeB) => mustBe(isTypeB, logging, [...refinements, isTypeB])
|
|
321
|
-
});
|
|
322
|
-
return checkTypes;
|
|
323
|
-
};
|
|
324
|
-
var isIntersection = mustBe(canExist);
|
|
325
|
-
|
|
326
|
-
// ../anvl/src/join/core-relation-data.ts
|
|
327
|
-
var RELATION_TYPES = [`1:1`, `1:n`, `n:n`];
|
|
328
|
-
var isRelationType = (x) => RELATION_TYPES.includes(x);
|
|
329
|
-
var EMPTY_RELATION_DATA = {
|
|
330
|
-
contents: {},
|
|
331
|
-
relations: {},
|
|
332
|
-
relationType: `n:n`,
|
|
333
|
-
a: `from`,
|
|
334
|
-
b: `to`
|
|
335
|
-
};
|
|
336
|
-
var isRelationData = ({
|
|
337
|
-
from: a = `from`,
|
|
338
|
-
to: b = `to`,
|
|
339
|
-
isContent
|
|
340
|
-
} = {}) => (input) => {
|
|
341
|
-
return hasExactProperties({
|
|
342
|
-
contents: isContent ? isRecord(import_string.isString, isContent) : hasExactProperties({}),
|
|
343
|
-
relations: isRecord(import_string.isString, isArray(import_string.isString)),
|
|
344
|
-
relationType: isRelationType,
|
|
345
|
-
a: isLiteral(a),
|
|
346
|
-
b: isLiteral(b)
|
|
347
|
-
})(input);
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
// ../anvl/src/join/get-related-ids.ts
|
|
351
|
-
var getRelatedIds = (relationMap, id) => {
|
|
352
|
-
var _a;
|
|
353
|
-
return (_a = relationMap.relations[id]) != null ? _a : [];
|
|
354
|
-
};
|
|
355
|
-
var getRelatedId = (relationMap, id) => {
|
|
356
|
-
const relations = getRelatedIds(relationMap, id);
|
|
357
|
-
if (relations.length > 1) {
|
|
358
|
-
console.warn(
|
|
359
|
-
`entry with id ${id} was not expected to have multiple relations`
|
|
360
|
-
);
|
|
361
|
-
}
|
|
362
|
-
return relations[0];
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
// ../anvl/src/join/make-json-interface.ts
|
|
366
|
-
var makeJsonInterface = (join, ...params) => {
|
|
367
|
-
const isContent = params[0];
|
|
368
|
-
const { a, b } = join;
|
|
369
|
-
const options = {
|
|
370
|
-
from: a,
|
|
371
|
-
to: b,
|
|
372
|
-
isContent
|
|
373
|
-
};
|
|
374
|
-
return {
|
|
375
|
-
toJson: (join2) => join2.toJSON(),
|
|
376
|
-
fromJson: (json) => Join.fromJSON(json, options)
|
|
377
|
-
};
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
// ../anvl/src/join/relation-contents.ts
|
|
381
|
-
var import_function6 = require("fp-ts/function");
|
|
382
|
-
|
|
383
|
-
// ../anvl/src/join/relation-record.ts
|
|
384
|
-
var getRelationEntries = (relationMap, idA) => getRelatedIds(relationMap, idA).map((idB) => [
|
|
385
|
-
idB,
|
|
386
|
-
getContent(relationMap, idA, idB)
|
|
387
|
-
]);
|
|
388
|
-
var getRelationRecord = (relationMap, id) => Object.fromEntries(getRelationEntries(relationMap, id));
|
|
389
|
-
|
|
390
|
-
// ../anvl/src/join/remove-relation.ts
|
|
391
|
-
var import_function5 = require("fp-ts/function");
|
|
392
|
-
var import_string2 = require("fp-ts/string");
|
|
393
|
-
|
|
394
|
-
// ../anvl/src/object/index.ts
|
|
395
|
-
var import_function4 = require("fp-ts/function");
|
|
396
|
-
var treeShake = (shouldDiscard = isUndefined) => (obj) => {
|
|
397
|
-
const newObj = {};
|
|
398
|
-
const entries = Object.entries(obj);
|
|
399
|
-
entries.forEach(
|
|
400
|
-
([key, val]) => !shouldDiscard(val, key) ? newObj[key] = val : null
|
|
401
|
-
);
|
|
402
|
-
return newObj;
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
// ../anvl/src/string/split.ts
|
|
406
|
-
var split = (separator) => (str) => str.split(separator);
|
|
407
|
-
|
|
408
|
-
// ../anvl/src/join/remove-relation.ts
|
|
409
|
-
var removeSpecific = (current, idA, idB) => {
|
|
410
|
-
const isIdForRemoval = isOneOf(idA, idB);
|
|
411
|
-
return __spreadProps(__spreadValues({}, current), {
|
|
412
|
-
relations: (0, import_function5.pipe)(
|
|
413
|
-
current.relations,
|
|
414
|
-
recordToEntries,
|
|
415
|
-
map(([id, relations]) => [
|
|
416
|
-
id,
|
|
417
|
-
isIdForRemoval(id) ? relations.filter((relation) => !isIdForRemoval(relation)) : relations
|
|
418
|
-
]),
|
|
419
|
-
entriesToRecord,
|
|
420
|
-
treeShake(isEmptyArray)
|
|
421
|
-
),
|
|
422
|
-
contents: (0, import_function5.pipe)(
|
|
423
|
-
current.contents,
|
|
424
|
-
treeShake(
|
|
425
|
-
(_, key) => (0, import_string2.isString)(key) && (0, import_function5.pipe)(key, split(`/`), comprises([idA, idB]))
|
|
426
|
-
)
|
|
427
|
-
)
|
|
428
|
-
});
|
|
429
|
-
};
|
|
430
|
-
var removeAll = (current, idToRemove) => {
|
|
431
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
432
|
-
relations: (0, import_function5.pipe)(
|
|
433
|
-
current.relations,
|
|
434
|
-
recordToEntries,
|
|
435
|
-
map(([id, relations]) => [
|
|
436
|
-
id,
|
|
437
|
-
relations.filter((relation) => relation !== idToRemove)
|
|
438
|
-
]),
|
|
439
|
-
entriesToRecord,
|
|
440
|
-
treeShake((val, key) => key === idToRemove || isEmptyArray(val))
|
|
441
|
-
),
|
|
442
|
-
contents: (0, import_function5.pipe)(
|
|
443
|
-
current.contents,
|
|
444
|
-
treeShake(
|
|
445
|
-
(_, key) => (0, import_string2.isString)(key) && key.split(`/`).includes(idToRemove)
|
|
446
|
-
)
|
|
447
|
-
)
|
|
448
|
-
});
|
|
449
|
-
return next;
|
|
450
|
-
};
|
|
451
|
-
var removeRelation = (current, relation) => {
|
|
452
|
-
const idA = relation[current.a];
|
|
453
|
-
const idB = relation[current.b];
|
|
454
|
-
return idB ? removeSpecific(current, idA, idB) : removeAll(current, idA);
|
|
455
|
-
};
|
|
456
|
-
|
|
457
|
-
// ../anvl/src/join/set-relation.ts
|
|
458
|
-
var setManyToMany = (map2, idA, idB, ...rest) => {
|
|
459
|
-
var _a, _b;
|
|
460
|
-
const next = __spreadProps(__spreadValues({}, map2), {
|
|
461
|
-
relations: __spreadProps(__spreadValues({}, map2.relations), {
|
|
462
|
-
[idA]: addTo((_a = map2.relations[idA]) != null ? _a : [])(idB),
|
|
463
|
-
[idB]: addTo((_b = map2.relations[idB]) != null ? _b : [])(idA)
|
|
464
|
-
})
|
|
465
|
-
});
|
|
466
|
-
const content = rest[0];
|
|
467
|
-
return content ? setContent(next, idA, idB, content) : next;
|
|
468
|
-
};
|
|
469
|
-
var removeEmpties = treeShake(isEmptyArray);
|
|
470
|
-
var set1ToMany = (current, leaderId, followerId, ...rest) => {
|
|
471
|
-
var _a;
|
|
472
|
-
const relations = __spreadValues({}, current.relations);
|
|
473
|
-
const prevLeaderId = getRelatedId(current, followerId);
|
|
474
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
475
|
-
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues({}, relations), prevLeaderId && prevLeaderId !== leaderId && {
|
|
476
|
-
[prevLeaderId]: relations[prevLeaderId].filter(
|
|
477
|
-
(id) => id !== followerId
|
|
478
|
-
)
|
|
479
|
-
}), {
|
|
480
|
-
[followerId]: [leaderId],
|
|
481
|
-
[leaderId]: addTo((_a = relations[leaderId]) != null ? _a : [])(followerId)
|
|
482
|
-
}))
|
|
483
|
-
});
|
|
484
|
-
const content = rest[0];
|
|
485
|
-
return content ? setContent(next, leaderId, followerId, content) : next;
|
|
486
|
-
};
|
|
487
|
-
var set1To1 = (current, wifeId, husbandId, ...rest) => {
|
|
488
|
-
const prevWifeId = getRelatedId(current, husbandId);
|
|
489
|
-
const prevHusbandId = getRelatedId(current, wifeId);
|
|
490
|
-
const next = __spreadProps(__spreadValues({}, current), {
|
|
491
|
-
relations: removeEmpties(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, current.relations), prevWifeId && { [prevWifeId]: [] }), prevHusbandId && { [prevHusbandId]: [] }), {
|
|
492
|
-
[wifeId]: [husbandId],
|
|
493
|
-
[husbandId]: [wifeId]
|
|
494
|
-
}))
|
|
495
|
-
});
|
|
496
|
-
const content = rest[0];
|
|
497
|
-
return content ? setContent(next, wifeId, husbandId, content) : next;
|
|
498
|
-
};
|
|
499
|
-
var setRelationWithContent = (current, relation, ...rest) => {
|
|
500
|
-
const { [current.a]: idA, [current.b]: idB } = relation;
|
|
501
|
-
switch (current.relationType) {
|
|
502
|
-
case `1:1`:
|
|
503
|
-
return set1To1(current, idA, idB, ...rest);
|
|
504
|
-
case `1:n`:
|
|
505
|
-
return set1ToMany(current, idA, idB, ...rest);
|
|
506
|
-
case `n:n`:
|
|
507
|
-
return setManyToMany(current, idA, idB, ...rest);
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
// ../anvl/src/join/relation-contents.ts
|
|
512
|
-
var makeContentId = (idA, idB) => [idA, idB].sort().join(`/`);
|
|
513
|
-
var getContent = (relationMap, idA, idB) => relationMap.contents[makeContentId(idA, idB)];
|
|
514
|
-
var setContent = (map2, idA, idB, content) => __spreadProps(__spreadValues({}, map2), {
|
|
515
|
-
contents: __spreadProps(__spreadValues({}, map2.contents), {
|
|
516
|
-
[makeContentId(idA, idB)]: content
|
|
517
|
-
})
|
|
518
|
-
});
|
|
519
|
-
var getRelations = (relationMap, id) => getRelationEntries(relationMap, id).map(
|
|
520
|
-
([id2, content]) => __spreadValues({
|
|
521
|
-
id: id2
|
|
522
|
-
}, content)
|
|
523
|
-
);
|
|
524
|
-
var setRelations = (current, subject, relations) => {
|
|
525
|
-
const idA = subject[current.a];
|
|
526
|
-
const idB = subject[current.b];
|
|
527
|
-
return (0, import_function6.pipe)(
|
|
528
|
-
current,
|
|
529
|
-
(relationData) => {
|
|
530
|
-
const relatedIds = getRelatedIds(current, idA);
|
|
531
|
-
const removedIds = relatedIds.filter(
|
|
532
|
-
(id) => !relations.some((r) => r.id === id)
|
|
533
|
-
);
|
|
534
|
-
let step = relationData;
|
|
535
|
-
for (const id of removedIds) {
|
|
536
|
-
const remove = {
|
|
537
|
-
[current.a]: idA != null ? idA : id,
|
|
538
|
-
[current.b]: idB != null ? idB : id
|
|
539
|
-
};
|
|
540
|
-
step = removeRelation(step, remove);
|
|
541
|
-
}
|
|
542
|
-
return step;
|
|
543
|
-
},
|
|
544
|
-
(relationData) => {
|
|
545
|
-
let step = relationData;
|
|
546
|
-
for (const _a of relations) {
|
|
547
|
-
const _b = _a, { id } = _b, rest = __objRest(_b, ["id"]);
|
|
548
|
-
const content = isEmptyObject(rest) ? void 0 : rest;
|
|
549
|
-
step = setRelationWithContent(
|
|
550
|
-
step,
|
|
551
|
-
{ [current.a]: idA != null ? idA : id, [current.b]: idB != null ? idB : id },
|
|
552
|
-
// @ts-expect-error hacky
|
|
553
|
-
content
|
|
554
|
-
);
|
|
555
|
-
}
|
|
556
|
-
return step;
|
|
557
|
-
},
|
|
558
|
-
(relationData) => {
|
|
559
|
-
const newlyOrderedIds = relations.map((r) => r.id);
|
|
560
|
-
return __spreadProps(__spreadValues({}, relationData), {
|
|
561
|
-
relations: __spreadProps(__spreadValues({}, relationData.relations), {
|
|
562
|
-
[idA != null ? idA : idB]: newlyOrderedIds
|
|
563
|
-
})
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
);
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
// ../anvl/src/join/index.ts
|
|
570
|
-
var Join = class _Join {
|
|
571
|
-
constructor(json) {
|
|
572
|
-
this.a = `from`;
|
|
573
|
-
this.b = `to`;
|
|
574
|
-
this.makeJsonInterface = (...params) => {
|
|
575
|
-
return makeJsonInterface(this, ...params);
|
|
576
|
-
};
|
|
577
|
-
Object.assign(this, __spreadProps(__spreadValues(__spreadValues({}, EMPTY_RELATION_DATA), json), {
|
|
578
|
-
makeJsonInterface: this.makeJsonInterface
|
|
579
|
-
}));
|
|
580
|
-
}
|
|
581
|
-
toJSON() {
|
|
582
|
-
return {
|
|
583
|
-
relationType: this.relationType,
|
|
584
|
-
relations: this.relations,
|
|
585
|
-
contents: this.contents,
|
|
586
|
-
a: this.a,
|
|
587
|
-
b: this.b
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
static fromJSON(json, options) {
|
|
591
|
-
const isValid = isRelationData(options)(json);
|
|
592
|
-
if (isValid) {
|
|
593
|
-
return new _Join(json);
|
|
594
|
-
}
|
|
595
|
-
throw new Error(
|
|
596
|
-
`Saved JSON for this Join is invalid: ${JSON.stringify(json)}`
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
from(newA) {
|
|
600
|
-
return new _Join(__spreadProps(__spreadValues({}, this), { a: newA }));
|
|
601
|
-
}
|
|
602
|
-
to(newB) {
|
|
603
|
-
return new _Join(__spreadProps(__spreadValues({}, this), { b: newB }));
|
|
604
|
-
}
|
|
605
|
-
getRelatedId(id) {
|
|
606
|
-
return getRelatedId(this, id);
|
|
607
|
-
}
|
|
608
|
-
getRelatedIds(id) {
|
|
609
|
-
return getRelatedIds(this, id);
|
|
610
|
-
}
|
|
611
|
-
getContent(idA, idB) {
|
|
612
|
-
return getContent(this, idA, idB);
|
|
613
|
-
}
|
|
614
|
-
getRelationEntries(id) {
|
|
615
|
-
return getRelationEntries(this, id);
|
|
616
|
-
}
|
|
617
|
-
getRelationRecord(id) {
|
|
618
|
-
return getRelationRecord(this, id);
|
|
619
|
-
}
|
|
620
|
-
getRelation(id) {
|
|
621
|
-
return getRelations(this, id)[0];
|
|
622
|
-
}
|
|
623
|
-
getRelations(id) {
|
|
624
|
-
return getRelations(this, id);
|
|
625
|
-
}
|
|
626
|
-
setRelations(subject, relations) {
|
|
627
|
-
return new _Join(setRelations(this, subject, relations));
|
|
628
|
-
}
|
|
629
|
-
set(relation, ...rest) {
|
|
630
|
-
return new _Join(setRelationWithContent(this, relation, ...rest));
|
|
631
|
-
}
|
|
632
|
-
remove(relation) {
|
|
633
|
-
return new _Join(
|
|
634
|
-
removeRelation(this, relation)
|
|
635
|
-
);
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
// src/internal/store.ts
|
|
640
|
-
var createStore = (name, store = null) => {
|
|
641
|
-
var _a;
|
|
642
|
-
const created = __spreadProps(__spreadValues({}, store != null ? store : (() => ({
|
|
643
|
-
atomsThatAreDefault: /* @__PURE__ */ new Set(),
|
|
644
|
-
selectorAtoms: new Join({ relationType: `n:n` }).from(`selectorKey`).to(`atomKey`),
|
|
645
|
-
selectorGraph: new Join({ relationType: `n:n` })
|
|
646
|
-
}))()), {
|
|
647
|
-
valueMap: new Map(store == null ? void 0 : store.valueMap),
|
|
648
|
-
atoms: /* @__PURE__ */ new Map(),
|
|
649
|
-
readonlySelectors: /* @__PURE__ */ new Map(),
|
|
650
|
-
selectors: /* @__PURE__ */ new Map(),
|
|
651
|
-
transactions: /* @__PURE__ */ new Map(),
|
|
652
|
-
timelines: /* @__PURE__ */ new Map(),
|
|
653
|
-
timelineAtoms: new Join({ relationType: `1:n` }).from(`timelineKey`).to(`atomKey`),
|
|
654
|
-
subject: {
|
|
655
|
-
atomCreation: new Subject(),
|
|
656
|
-
selectorCreation: new Subject(),
|
|
657
|
-
transactionCreation: new Subject(),
|
|
658
|
-
timelineCreation: new Subject(),
|
|
659
|
-
operationStatus: new Subject()
|
|
660
|
-
},
|
|
661
|
-
operation: __spreadValues({
|
|
662
|
-
open: false
|
|
663
|
-
}, store == null ? void 0 : store.operation),
|
|
664
|
-
transactionStatus: __spreadValues({
|
|
665
|
-
phase: `idle`
|
|
666
|
-
}, store == null ? void 0 : store.transactionStatus),
|
|
667
|
-
config: __spreadProps(__spreadValues({
|
|
668
|
-
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
669
|
-
info: doNothing
|
|
670
|
-
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
671
|
-
logger__INTERNAL: console
|
|
672
|
-
}, store == null ? void 0 : store.config), {
|
|
673
|
-
name
|
|
674
|
-
})
|
|
675
|
-
});
|
|
676
|
-
store == null ? void 0 : store.atoms.forEach((atom2) => {
|
|
677
|
-
const copiedAtom = __spreadProps(__spreadValues({}, atom2), { subject: new Subject() });
|
|
678
|
-
created.atoms.set(atom2.key, copiedAtom);
|
|
679
|
-
});
|
|
680
|
-
store == null ? void 0 : store.readonlySelectors.forEach((selector2) => {
|
|
681
|
-
selector2.install(created);
|
|
682
|
-
});
|
|
683
|
-
store == null ? void 0 : store.selectors.forEach((selector2) => {
|
|
684
|
-
selector2.install(created);
|
|
685
|
-
});
|
|
686
|
-
store == null ? void 0 : store.transactions.forEach((tx) => {
|
|
687
|
-
tx.install(created);
|
|
688
|
-
});
|
|
689
|
-
store == null ? void 0 : store.timelines.forEach((timeline2) => {
|
|
690
|
-
timeline2.install(created);
|
|
691
|
-
});
|
|
692
|
-
return created;
|
|
693
|
-
};
|
|
694
|
-
var IMPLICIT = {
|
|
695
|
-
STORE_INTERNAL: void 0,
|
|
696
|
-
get STORE() {
|
|
697
|
-
var _a;
|
|
698
|
-
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = createStore(`DEFAULT`);
|
|
699
|
-
}
|
|
700
|
-
};
|
|
701
|
-
var clearStore = (store = IMPLICIT.STORE) => {
|
|
702
|
-
const { config } = store;
|
|
703
|
-
Object.assign(store, createStore(config.name));
|
|
704
|
-
store.config = config;
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
// src/internal/operation.ts
|
|
708
|
-
var openOperation = (token, store) => {
|
|
709
|
-
var _a, _b;
|
|
710
|
-
const core = target(store);
|
|
711
|
-
if (core.operation.open) {
|
|
712
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
713
|
-
`\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
|
|
714
|
-
);
|
|
715
|
-
throw Symbol(`violation`);
|
|
716
|
-
}
|
|
717
|
-
core.operation = {
|
|
718
|
-
open: true,
|
|
719
|
-
done: /* @__PURE__ */ new Set(),
|
|
720
|
-
prev: new Map(store.valueMap),
|
|
721
|
-
time: Date.now(),
|
|
722
|
-
token
|
|
723
|
-
};
|
|
724
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
725
|
-
`\u2B55 operation start from "${token.key}" in store "${store.config.name}"`
|
|
726
|
-
);
|
|
727
|
-
};
|
|
728
|
-
var closeOperation = (store) => {
|
|
729
|
-
var _a;
|
|
730
|
-
const core = target(store);
|
|
731
|
-
core.operation = { open: false };
|
|
732
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F534} operation done`);
|
|
733
|
-
store.subject.operationStatus.next(core.operation);
|
|
734
|
-
};
|
|
735
|
-
var isDone = (key, store = IMPLICIT.STORE) => {
|
|
736
|
-
var _a;
|
|
737
|
-
const core = target(store);
|
|
738
|
-
if (!core.operation.open) {
|
|
739
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
740
|
-
`isDone called outside of an operation. This is probably a bug.`
|
|
741
|
-
);
|
|
742
|
-
return true;
|
|
743
|
-
}
|
|
744
|
-
return core.operation.done.has(key);
|
|
745
|
-
};
|
|
746
|
-
var markDone = (key, store = IMPLICIT.STORE) => {
|
|
747
|
-
var _a;
|
|
748
|
-
const core = target(store);
|
|
749
|
-
if (!core.operation.open) {
|
|
750
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
751
|
-
`markDone called outside of an operation. This is probably a bug.`
|
|
752
|
-
);
|
|
753
|
-
return;
|
|
754
|
-
}
|
|
755
|
-
core.operation.done.add(key);
|
|
756
|
-
};
|
|
757
|
-
var recallState = (state, store = IMPLICIT.STORE) => {
|
|
758
|
-
var _a;
|
|
759
|
-
const core = target(store);
|
|
760
|
-
if (!core.operation.open) {
|
|
761
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
762
|
-
`recall called outside of an operation. This is probably a bug.`
|
|
763
|
-
);
|
|
764
|
-
return core.valueMap.get(state.key);
|
|
765
|
-
}
|
|
766
|
-
return core.operation.prev.get(state.key);
|
|
767
|
-
};
|
|
768
|
-
var cacheValue = (key, value, store = IMPLICIT.STORE) => {
|
|
769
|
-
const core = target(store);
|
|
770
|
-
core.valueMap.set(key, value);
|
|
771
|
-
};
|
|
772
|
-
var evictCachedValue = (key, store = IMPLICIT.STORE) => {
|
|
773
|
-
const core = target(store);
|
|
774
|
-
core.valueMap.delete(key);
|
|
775
|
-
};
|
|
776
|
-
var readCachedValue = (key, store = IMPLICIT.STORE) => target(store).valueMap.get(key);
|
|
777
|
-
var isValueCached = (key, store = IMPLICIT.STORE) => target(store).valueMap.has(key);
|
|
778
|
-
var storeAtom = (atom2, store = IMPLICIT.STORE) => {
|
|
779
|
-
const core = target(store);
|
|
780
|
-
core.atoms.set(atom2.key, atom2);
|
|
781
|
-
};
|
|
782
|
-
var storeSelector = (selector2, store = IMPLICIT.STORE) => {
|
|
783
|
-
const core = target(store);
|
|
784
|
-
core.selectors.set(selector2.key, selector2);
|
|
785
|
-
};
|
|
786
|
-
var storeReadonlySelector = (selector2, store = IMPLICIT.STORE) => {
|
|
787
|
-
const core = target(store);
|
|
788
|
-
core.readonlySelectors.set(selector2.key, selector2);
|
|
789
|
-
};
|
|
790
|
-
var hasKeyBeenUsed = (key, store = IMPLICIT.STORE) => {
|
|
791
|
-
const core = target(store);
|
|
792
|
-
return core.atoms.has(key) || core.selectors.has(key) || core.readonlySelectors.has(key);
|
|
793
|
-
};
|
|
794
|
-
|
|
795
|
-
// src/internal/transaction-internal.ts
|
|
796
|
-
function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
797
|
-
const newTransaction = {
|
|
798
|
-
key: options.key,
|
|
799
|
-
type: `transaction`,
|
|
800
|
-
run: (...params) => {
|
|
801
|
-
var _a;
|
|
802
|
-
buildTransaction(options.key, params, store);
|
|
803
|
-
try {
|
|
804
|
-
const output = options.do(
|
|
805
|
-
{
|
|
806
|
-
get: (token2) => getState(token2, store),
|
|
807
|
-
set: (token2, value) => setState(token2, value, store)
|
|
808
|
-
},
|
|
809
|
-
...params
|
|
810
|
-
);
|
|
811
|
-
applyTransaction(output, store);
|
|
812
|
-
return output;
|
|
813
|
-
} catch (thrown) {
|
|
814
|
-
abortTransaction(store);
|
|
815
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(`Transaction ${options.key} failed`, thrown);
|
|
816
|
-
throw thrown;
|
|
817
|
-
}
|
|
818
|
-
},
|
|
819
|
-
install: (store2) => transaction__INTERNAL(options, store2),
|
|
820
|
-
subject: new Subject()
|
|
821
|
-
};
|
|
822
|
-
const core = target(store);
|
|
823
|
-
core.transactions.set(newTransaction.key, newTransaction);
|
|
824
|
-
const token = deposit(newTransaction);
|
|
825
|
-
store.subject.transactionCreation.next(token);
|
|
826
|
-
return token;
|
|
827
|
-
}
|
|
828
|
-
var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
|
|
829
|
-
|
|
830
|
-
// src/internal/atom-internal.ts
|
|
831
|
-
function atom__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
832
|
-
var _a, _b, _c;
|
|
833
|
-
const core = target(store);
|
|
834
|
-
const existing = core.atoms.get(options.key);
|
|
835
|
-
if (existing) {
|
|
836
|
-
(_b = (_a = store.config.logger) == null ? void 0 : _a.error) == null ? void 0 : _b.call(
|
|
837
|
-
_a,
|
|
838
|
-
`Key "${options.key}" already exists in the store.`
|
|
839
|
-
);
|
|
840
|
-
return deposit(existing);
|
|
841
|
-
}
|
|
842
|
-
const subject = new Subject();
|
|
843
|
-
const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
844
|
-
subject,
|
|
845
|
-
type: `atom`
|
|
846
|
-
}), family && { family });
|
|
847
|
-
const initialValue = options.default instanceof Function ? options.default() : options.default;
|
|
848
|
-
core.atoms.set(newAtom.key, newAtom);
|
|
849
|
-
markAtomAsDefault(options.key, store);
|
|
850
|
-
cacheValue(options.key, initialValue, store);
|
|
851
|
-
const token = deposit(newAtom);
|
|
852
|
-
(_c = options.effects) == null ? void 0 : _c.forEach(
|
|
853
|
-
(effect) => effect({
|
|
854
|
-
setSelf: (next) => setState(token, next, store),
|
|
855
|
-
onSet: (handle) => subscribe(token, handle, store)
|
|
856
|
-
})
|
|
857
|
-
);
|
|
858
|
-
store.subject.atomCreation.next(token);
|
|
859
|
-
return token;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
// ../anvl/src/json/index.ts
|
|
863
|
-
var stringifyJson = (json) => JSON.stringify(json);
|
|
864
|
-
|
|
865
|
-
// src/internal/families-internal.ts
|
|
866
|
-
function atomFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
867
|
-
const subject = new Subject();
|
|
868
|
-
return Object.assign(
|
|
869
|
-
(key) => {
|
|
870
|
-
const subKey = stringifyJson(key);
|
|
871
|
-
const family = { key: options.key, subKey };
|
|
872
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
873
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
874
|
-
let token;
|
|
875
|
-
if (existing) {
|
|
876
|
-
token = deposit(existing);
|
|
877
|
-
} else {
|
|
878
|
-
const individualOptions = {
|
|
879
|
-
key: fullKey,
|
|
880
|
-
default: options.default instanceof Function ? options.default(key) : options.default
|
|
881
|
-
};
|
|
882
|
-
if (options.effects) {
|
|
883
|
-
individualOptions.effects = options.effects(key);
|
|
884
|
-
}
|
|
885
|
-
token = atom__INTERNAL(individualOptions, family, store);
|
|
886
|
-
}
|
|
887
|
-
subject.next(token);
|
|
888
|
-
return token;
|
|
889
|
-
},
|
|
890
|
-
{
|
|
891
|
-
key: options.key,
|
|
892
|
-
type: `atom_family`,
|
|
893
|
-
subject
|
|
894
|
-
}
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
function readonlySelectorFamily__INTERNAL(options, store) {
|
|
898
|
-
const core = target(store);
|
|
899
|
-
const subject = new Subject();
|
|
900
|
-
return Object.assign(
|
|
901
|
-
(key) => {
|
|
902
|
-
const subKey = stringifyJson(key);
|
|
903
|
-
const family = { key: options.key, subKey };
|
|
904
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
905
|
-
const existing = core.readonlySelectors.get(fullKey);
|
|
906
|
-
if (existing) {
|
|
907
|
-
return deposit(existing);
|
|
908
|
-
}
|
|
909
|
-
return selector__INTERNAL(
|
|
910
|
-
{
|
|
911
|
-
key: fullKey,
|
|
912
|
-
get: options.get(key)
|
|
913
|
-
},
|
|
914
|
-
family,
|
|
915
|
-
store
|
|
916
|
-
);
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
key: options.key,
|
|
920
|
-
type: `readonly_selector_family`,
|
|
921
|
-
subject
|
|
922
|
-
}
|
|
923
|
-
);
|
|
924
|
-
}
|
|
925
|
-
function selectorFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
926
|
-
const isReadonly = !(`set` in options);
|
|
927
|
-
if (isReadonly) {
|
|
928
|
-
return readonlySelectorFamily__INTERNAL(options, store);
|
|
929
|
-
}
|
|
930
|
-
const core = target(store);
|
|
931
|
-
const subject = new Subject();
|
|
932
|
-
return Object.assign(
|
|
933
|
-
(key) => {
|
|
934
|
-
const subKey = stringifyJson(key);
|
|
935
|
-
const family = { key: options.key, subKey };
|
|
936
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
937
|
-
const existing = core.selectors.get(fullKey);
|
|
938
|
-
if (existing) {
|
|
939
|
-
return deposit(existing);
|
|
940
|
-
}
|
|
941
|
-
const token = selector__INTERNAL(
|
|
942
|
-
{
|
|
943
|
-
key: fullKey,
|
|
944
|
-
get: options.get(key),
|
|
945
|
-
set: options.set(key)
|
|
946
|
-
},
|
|
947
|
-
family,
|
|
948
|
-
store
|
|
949
|
-
);
|
|
950
|
-
subject.next(token);
|
|
951
|
-
return token;
|
|
952
|
-
},
|
|
953
|
-
{
|
|
954
|
-
key: options.key,
|
|
955
|
-
type: `selector_family`
|
|
956
|
-
}
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
// src/internal/selector/create-read-write-selector.ts
|
|
961
|
-
var createReadWriteSelector = (options, family, store, core) => {
|
|
962
|
-
var _a;
|
|
963
|
-
const subject = new Subject();
|
|
964
|
-
const { get, set } = registerSelector(options.key, store);
|
|
965
|
-
const getSelf = () => {
|
|
966
|
-
const value = options.get({ get });
|
|
967
|
-
cacheValue(options.key, value, store);
|
|
968
|
-
return value;
|
|
969
|
-
};
|
|
970
|
-
const setSelf = (next) => {
|
|
971
|
-
var _a2;
|
|
972
|
-
const oldValue = getSelf();
|
|
973
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
974
|
-
` <- "${options.key}" went (`,
|
|
975
|
-
oldValue,
|
|
976
|
-
`->`,
|
|
977
|
-
next,
|
|
978
|
-
`)`
|
|
979
|
-
);
|
|
980
|
-
const newValue = become(next)(oldValue);
|
|
981
|
-
cacheValue(options.key, newValue, store);
|
|
982
|
-
markDone(options.key, store);
|
|
983
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
984
|
-
subject.next({ newValue, oldValue });
|
|
985
|
-
}
|
|
986
|
-
options.set({ get, set }, newValue);
|
|
987
|
-
};
|
|
988
|
-
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
989
|
-
subject,
|
|
990
|
-
install: (s) => selector__INTERNAL(options, family, s),
|
|
991
|
-
get: getSelf,
|
|
992
|
-
set: setSelf,
|
|
993
|
-
type: `selector`
|
|
994
|
-
}), family && { family });
|
|
995
|
-
core.selectors.set(options.key, mySelector);
|
|
996
|
-
const initialValue = getSelf();
|
|
997
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
998
|
-
const token = {
|
|
999
|
-
key: options.key,
|
|
1000
|
-
type: `selector`
|
|
1001
|
-
};
|
|
1002
|
-
if (family) {
|
|
1003
|
-
token.family = family;
|
|
1004
|
-
}
|
|
1005
|
-
store.subject.selectorCreation.next(token);
|
|
1006
|
-
return token;
|
|
1007
|
-
};
|
|
1008
|
-
|
|
1009
|
-
// src/internal/selector/lookup-selector-sources.ts
|
|
1010
|
-
var lookupSelectorSources = (key, store) => target(store).selectorGraph.getRelations(key).filter(({ source }) => source !== key).map(({ source }) => lookup(source, store));
|
|
1011
|
-
|
|
1012
|
-
// src/internal/selector/trace-selector-atoms.ts
|
|
1013
|
-
var traceSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1014
|
-
const roots = [];
|
|
1015
|
-
const sources = lookupSelectorSources(dependency.key, store);
|
|
1016
|
-
let depth = 0;
|
|
1017
|
-
while (sources.length > 0) {
|
|
1018
|
-
const source = sources.shift();
|
|
1019
|
-
++depth;
|
|
1020
|
-
if (depth > 999) {
|
|
1021
|
-
throw new Error(
|
|
1022
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`
|
|
1023
|
-
);
|
|
1024
|
-
}
|
|
1025
|
-
if (source.type !== `atom`) {
|
|
1026
|
-
sources.push(...lookupSelectorSources(source.key, store));
|
|
1027
|
-
} else {
|
|
1028
|
-
roots.push(source);
|
|
1029
|
-
}
|
|
1030
|
-
}
|
|
1031
|
-
return roots;
|
|
1032
|
-
};
|
|
1033
|
-
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
1034
|
-
const sources = lookupSelectorSources(selectorKey, store);
|
|
1035
|
-
return sources.flatMap(
|
|
1036
|
-
(source) => source.type === `atom` ? source : traceSelectorAtoms(selectorKey, source, store)
|
|
1037
|
-
);
|
|
1038
|
-
};
|
|
1039
|
-
|
|
1040
|
-
// src/internal/selector/update-selector-atoms.ts
|
|
1041
|
-
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1042
|
-
var _a, _b;
|
|
1043
|
-
const core = target(store);
|
|
1044
|
-
if (dependency.type === `atom`) {
|
|
1045
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
1046
|
-
selectorKey,
|
|
1047
|
-
atomKey: dependency.key
|
|
1048
|
-
});
|
|
1049
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1050
|
-
` || adding root for "${selectorKey}": ${dependency.key}`
|
|
1051
|
-
);
|
|
1052
|
-
return;
|
|
1053
|
-
}
|
|
1054
|
-
const roots = traceSelectorAtoms(selectorKey, dependency, store);
|
|
1055
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1056
|
-
` || adding roots for "${selectorKey}":`,
|
|
1057
|
-
roots.map((r) => r.key)
|
|
1058
|
-
);
|
|
1059
|
-
for (const root of roots) {
|
|
1060
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
1061
|
-
selectorKey,
|
|
1062
|
-
atomKey: root.key
|
|
1063
|
-
});
|
|
1064
|
-
}
|
|
1065
|
-
};
|
|
1066
|
-
|
|
1067
|
-
// src/internal/set.ts
|
|
1068
|
-
var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
1069
|
-
var _a, _b;
|
|
1070
|
-
const core = target(store);
|
|
1071
|
-
const downstream = core.selectorAtoms.getRelations(state.key);
|
|
1072
|
-
const downstreamKeys = downstream.map(({ id }) => id);
|
|
1073
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1074
|
-
` || ${downstreamKeys.length} downstream:`,
|
|
1075
|
-
downstreamKeys
|
|
1076
|
-
);
|
|
1077
|
-
if (core.operation.open) {
|
|
1078
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` ||`, [...core.operation.done], `already done`);
|
|
1079
|
-
}
|
|
1080
|
-
downstream.forEach(({ id: stateKey }) => {
|
|
1081
|
-
var _a2, _b2, _c, _d;
|
|
1082
|
-
if (isDone(stateKey, store)) {
|
|
1083
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` || ${stateKey} already done`);
|
|
1084
|
-
return;
|
|
1085
|
-
}
|
|
1086
|
-
const state2 = (_b2 = core.selectors.get(stateKey)) != null ? _b2 : core.readonlySelectors.get(stateKey);
|
|
1087
|
-
if (!state2) {
|
|
1088
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1089
|
-
` || ${stateKey} is an atom, and can't be downstream`
|
|
1090
|
-
);
|
|
1091
|
-
return;
|
|
1092
|
-
}
|
|
1093
|
-
evictCachedValue(stateKey, store);
|
|
1094
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(` xx evicted "${stateKey}"`);
|
|
1095
|
-
markDone(stateKey, store);
|
|
1096
|
-
});
|
|
1097
|
-
};
|
|
1098
|
-
var setAtomState = (atom2, next, store = IMPLICIT.STORE) => {
|
|
1099
|
-
var _a, _b;
|
|
1100
|
-
const oldValue = getState__INTERNAL(atom2, store);
|
|
1101
|
-
const newValue = become(next)(oldValue);
|
|
1102
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting atom "${atom2.key}" to`, newValue);
|
|
1103
|
-
cacheValue(atom2.key, newValue, store);
|
|
1104
|
-
if (isAtomDefault(atom2.key, store)) {
|
|
1105
|
-
markAtomAsNotDefault(atom2.key, store);
|
|
1106
|
-
}
|
|
1107
|
-
markDone(atom2.key, store);
|
|
1108
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1109
|
-
` || evicting caches downstream from "${atom2.key}"`
|
|
1110
|
-
);
|
|
1111
|
-
evictDownStream(atom2, store);
|
|
1112
|
-
const update = { oldValue, newValue };
|
|
1113
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1114
|
-
emitUpdate(atom2, update, store);
|
|
1115
|
-
} else {
|
|
1116
|
-
stowUpdate(atom2, update, store);
|
|
1117
|
-
}
|
|
1118
|
-
};
|
|
1119
|
-
var setSelectorState = (selector2, next, store = IMPLICIT.STORE) => {
|
|
1120
|
-
var _a, _b;
|
|
1121
|
-
const oldValue = getState__INTERNAL(selector2, store);
|
|
1122
|
-
const newValue = become(next)(oldValue);
|
|
1123
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector2.key}" to`, newValue);
|
|
1124
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector2.key}"`);
|
|
1125
|
-
selector2.set(newValue);
|
|
1126
|
-
};
|
|
1127
|
-
var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
1128
|
-
if (`set` in state) {
|
|
1129
|
-
setSelectorState(state, value, store);
|
|
1130
|
-
} else {
|
|
1131
|
-
setAtomState(state, value, store);
|
|
1132
|
-
}
|
|
1133
|
-
};
|
|
1134
|
-
|
|
1135
|
-
// src/internal/selector/register-selector.ts
|
|
1136
|
-
var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
1137
|
-
get: (dependency) => {
|
|
1138
|
-
var _a, _b;
|
|
1139
|
-
const core = target(store);
|
|
1140
|
-
const alreadyRegistered = core.selectorGraph.getRelations(selectorKey).some(({ source }) => source === dependency.key);
|
|
1141
|
-
const dependencyState = withdraw(dependency, store);
|
|
1142
|
-
if (dependencyState === null) {
|
|
1143
|
-
throw new Error(
|
|
1144
|
-
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1145
|
-
);
|
|
1146
|
-
}
|
|
1147
|
-
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1148
|
-
if (alreadyRegistered) {
|
|
1149
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1150
|
-
` || ${selectorKey} <- ${dependency.key} =`,
|
|
1151
|
-
dependencyValue
|
|
1152
|
-
);
|
|
1153
|
-
} else {
|
|
1154
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1155
|
-
`\u{1F50C} registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
|
|
1156
|
-
dependencyValue,
|
|
1157
|
-
`)`
|
|
1158
|
-
);
|
|
1159
|
-
core.selectorGraph = core.selectorGraph.set(
|
|
1160
|
-
{ from: dependency.key, to: selectorKey },
|
|
1161
|
-
{
|
|
1162
|
-
source: dependency.key
|
|
1163
|
-
}
|
|
1164
|
-
);
|
|
1165
|
-
}
|
|
1166
|
-
updateSelectorAtoms(selectorKey, dependency, store);
|
|
1167
|
-
return dependencyValue;
|
|
1168
|
-
},
|
|
1169
|
-
set: (stateToken, newValue) => {
|
|
1170
|
-
const state = withdraw(stateToken, store);
|
|
1171
|
-
if (state === null) {
|
|
1172
|
-
throw new Error(
|
|
1173
|
-
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1174
|
-
);
|
|
1175
|
-
}
|
|
1176
|
-
setState__INTERNAL(state, newValue, store);
|
|
1177
|
-
}
|
|
1178
|
-
});
|
|
1179
|
-
|
|
1180
|
-
// src/internal/selector/create-readonly-selector.ts
|
|
1181
|
-
var createReadonlySelector = (options, family, store, core) => {
|
|
1182
|
-
var _a;
|
|
1183
|
-
const subject = new Subject();
|
|
1184
|
-
const { get } = registerSelector(options.key, store);
|
|
1185
|
-
const getSelf = () => {
|
|
1186
|
-
const value = options.get({ get });
|
|
1187
|
-
cacheValue(options.key, value, store);
|
|
1188
|
-
return value;
|
|
1189
|
-
};
|
|
1190
|
-
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1191
|
-
subject,
|
|
1192
|
-
install: (s) => selector__INTERNAL(options, family, s),
|
|
1193
|
-
get: getSelf,
|
|
1194
|
-
type: `readonly_selector`
|
|
1195
|
-
}), family && { family });
|
|
1196
|
-
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1197
|
-
const initialValue = getSelf();
|
|
1198
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
1199
|
-
const token = {
|
|
1200
|
-
key: options.key,
|
|
1201
|
-
type: `readonly_selector`
|
|
1202
|
-
};
|
|
1203
|
-
if (family) {
|
|
1204
|
-
token.family = family;
|
|
1205
|
-
}
|
|
1206
|
-
store.subject.selectorCreation.next(token);
|
|
1207
|
-
return token;
|
|
1208
|
-
};
|
|
1209
|
-
|
|
1210
|
-
// src/internal/selector-internal.ts
|
|
1211
|
-
function selector__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
1212
|
-
var _a;
|
|
1213
|
-
const core = target(store);
|
|
1214
|
-
if (core.selectors.has(options.key)) {
|
|
1215
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1216
|
-
`Key "${options.key}" already exists in the store.`
|
|
1217
|
-
);
|
|
1218
|
-
}
|
|
1219
|
-
if (!(`set` in options)) {
|
|
1220
|
-
return createReadonlySelector(options, family, store, core);
|
|
1221
|
-
}
|
|
1222
|
-
return createReadWriteSelector(options, family, store, core);
|
|
1223
|
-
}
|
|
1224
|
-
|
|
1225
|
-
// ../anvl/reactivity/subject.ts
|
|
1226
|
-
var Subject = class {
|
|
1227
|
-
constructor() {
|
|
1228
|
-
this.subscribers = [];
|
|
1229
|
-
}
|
|
1230
|
-
subscribe(subscriber) {
|
|
1231
|
-
this.subscribers.push(subscriber);
|
|
1232
|
-
const unsubscribe = () => this.unsubscribe(subscriber);
|
|
1233
|
-
return { unsubscribe };
|
|
1234
|
-
}
|
|
1235
|
-
unsubscribe(subscriber) {
|
|
1236
|
-
const subscriberIndex = this.subscribers.indexOf(subscriber);
|
|
1237
|
-
if (subscriberIndex !== -1) {
|
|
1238
|
-
this.subscribers.splice(subscriberIndex, 1);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
next(value) {
|
|
1242
|
-
for (const subscriber of this.subscribers) {
|
|
1243
|
-
subscriber(value);
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
};
|
|
1247
|
-
|
|
1248
|
-
// src/internal/subscribe-internal.ts
|
|
1249
|
-
var prepareUpdate = (state, store) => {
|
|
1250
|
-
const oldValue = recallState(state, store);
|
|
1251
|
-
const newValue = getState__INTERNAL(state, store);
|
|
1252
|
-
return { newValue, oldValue };
|
|
1253
|
-
};
|
|
1254
|
-
var stowUpdate = (state, update, store) => {
|
|
1255
|
-
var _a;
|
|
1256
|
-
const { key } = state;
|
|
1257
|
-
const { logger } = store.config;
|
|
1258
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1259
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1260
|
-
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
1261
|
-
);
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
store.transactionStatus.atomUpdates.push(__spreadValues({ key }, update));
|
|
1265
|
-
logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
1266
|
-
};
|
|
1267
|
-
var emitUpdate = (state, update, store) => {
|
|
1268
|
-
const { key } = state;
|
|
1269
|
-
const { logger } = store.config;
|
|
1270
|
-
logger == null ? void 0 : logger.info(
|
|
1271
|
-
`\u{1F4E2} ${state.type} "${key}" went (`,
|
|
1272
|
-
update.oldValue,
|
|
1273
|
-
`->`,
|
|
1274
|
-
update.newValue,
|
|
1275
|
-
`)`
|
|
1276
|
-
);
|
|
1277
|
-
state.subject.next(update);
|
|
1278
|
-
};
|
|
1279
|
-
var subscribeToRootAtoms = (state, store) => {
|
|
1280
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
1281
|
-
const atom2 = withdraw(atomToken, store);
|
|
1282
|
-
if (atom2 === null) {
|
|
1283
|
-
throw new Error(
|
|
1284
|
-
`Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1285
|
-
);
|
|
1286
|
-
}
|
|
1287
|
-
return atom2.subject.subscribe((atomChange) => {
|
|
1288
|
-
var _a, _b;
|
|
1289
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1290
|
-
`\u{1F4E2} selector "${state.key}" saw root "${atomToken.key}" go (`,
|
|
1291
|
-
atomChange.oldValue,
|
|
1292
|
-
`->`,
|
|
1293
|
-
atomChange.newValue,
|
|
1294
|
-
`)`
|
|
1295
|
-
);
|
|
1296
|
-
const oldValue = recallState(state, store);
|
|
1297
|
-
const newValue = getState__INTERNAL(state, store);
|
|
1298
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1299
|
-
` <- "${state.key}" went (`,
|
|
1300
|
-
oldValue,
|
|
1301
|
-
`->`,
|
|
1302
|
-
newValue,
|
|
1303
|
-
`)`
|
|
1304
|
-
);
|
|
1305
|
-
state.subject.next({ newValue, oldValue });
|
|
1306
|
-
});
|
|
1307
|
-
});
|
|
1308
|
-
return dependencySubscriptions;
|
|
1309
|
-
};
|
|
1310
|
-
|
|
1311
|
-
// src/internal/time-travel-internal.ts
|
|
1312
|
-
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1313
|
-
var _a, _b, _c, _d;
|
|
1314
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23E9 redo "${token.key}"`);
|
|
1315
|
-
const timelineData = store.timelines.get(token.key);
|
|
1316
|
-
if (!timelineData) {
|
|
1317
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1318
|
-
`Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1319
|
-
);
|
|
1320
|
-
return;
|
|
1321
|
-
}
|
|
1322
|
-
if (timelineData.at === timelineData.history.length) {
|
|
1323
|
-
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1324
|
-
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
1325
|
-
);
|
|
1326
|
-
return;
|
|
1327
|
-
}
|
|
1328
|
-
timelineData.timeTraveling = `into_future`;
|
|
1329
|
-
const update = timelineData.history[timelineData.at];
|
|
1330
|
-
switch (update.type) {
|
|
1331
|
-
case `atom_update`: {
|
|
1332
|
-
const { key, newValue } = update;
|
|
1333
|
-
setState({ key, type: `atom` }, newValue, store);
|
|
1334
|
-
break;
|
|
1335
|
-
}
|
|
1336
|
-
case `selector_update`:
|
|
1337
|
-
case `transaction_update`: {
|
|
1338
|
-
for (const atomUpdate of update.atomUpdates) {
|
|
1339
|
-
const { key, newValue } = atomUpdate;
|
|
1340
|
-
setState({ key, type: `atom` }, newValue, store);
|
|
1341
|
-
}
|
|
1342
|
-
break;
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
++timelineData.at;
|
|
1346
|
-
timelineData.subject.next(`redo`);
|
|
1347
|
-
timelineData.timeTraveling = null;
|
|
1348
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1349
|
-
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1350
|
-
);
|
|
1351
|
-
};
|
|
1352
|
-
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1353
|
-
var _a, _b, _c, _d;
|
|
1354
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23EA undo "${token.key}"`);
|
|
1355
|
-
const timelineData = store.timelines.get(token.key);
|
|
1356
|
-
if (!timelineData) {
|
|
1357
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1358
|
-
`Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1359
|
-
);
|
|
1360
|
-
return;
|
|
1361
|
-
}
|
|
1362
|
-
if (timelineData.at === 0) {
|
|
1363
|
-
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1364
|
-
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
1365
|
-
);
|
|
1366
|
-
return;
|
|
1367
|
-
}
|
|
1368
|
-
timelineData.timeTraveling = `into_past`;
|
|
1369
|
-
--timelineData.at;
|
|
1370
|
-
const update = timelineData.history[timelineData.at];
|
|
1371
|
-
switch (update.type) {
|
|
1372
|
-
case `atom_update`: {
|
|
1373
|
-
const { key, oldValue } = update;
|
|
1374
|
-
setState({ key, type: `atom` }, oldValue, store);
|
|
1375
|
-
break;
|
|
1376
|
-
}
|
|
1377
|
-
case `selector_update`:
|
|
1378
|
-
case `transaction_update`: {
|
|
1379
|
-
for (const atomUpdate of update.atomUpdates) {
|
|
1380
|
-
const { key, oldValue } = atomUpdate;
|
|
1381
|
-
setState({ key, type: `atom` }, oldValue, store);
|
|
1382
|
-
}
|
|
1383
|
-
break;
|
|
1384
|
-
}
|
|
1385
|
-
}
|
|
1386
|
-
timelineData.subject.next(`undo`);
|
|
1387
|
-
timelineData.timeTraveling = null;
|
|
1388
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1389
|
-
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1390
|
-
);
|
|
1391
|
-
};
|
|
1392
|
-
|
|
1393
|
-
// src/internal/timeline/add-atom-to-timeline.ts
|
|
1394
|
-
var addAtomToTimeline = (atomToken, atoms, tl, store = IMPLICIT.STORE) => {
|
|
1395
|
-
const atom2 = withdraw(atomToken, store);
|
|
1396
|
-
if (atom2 === null) {
|
|
1397
|
-
throw new Error(
|
|
1398
|
-
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
|
|
1399
|
-
);
|
|
1400
|
-
}
|
|
1401
|
-
atom2.subject.subscribe((update) => {
|
|
1402
|
-
var _a, _b, _c, _d, _e;
|
|
1403
|
-
const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
1404
|
-
const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
1405
|
-
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
1406
|
-
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
1407
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1408
|
-
`\u23F3 timeline "${tl.key}" saw atom "${atomToken.key}" go (`,
|
|
1409
|
-
update.oldValue,
|
|
1410
|
-
`->`,
|
|
1411
|
-
update.newValue,
|
|
1412
|
-
currentTransactionKey ? `) in transaction "${currentTransactionKey}"` : currentSelectorKey ? `) in selector "${currentSelectorKey}"` : `)`
|
|
1413
|
-
);
|
|
1414
|
-
if (tl.timeTraveling === null) {
|
|
1415
|
-
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
1416
|
-
const mostRecentUpdate = tl.history.at(-1);
|
|
1417
|
-
if (mostRecentUpdate === void 0) {
|
|
1418
|
-
throw new Error(
|
|
1419
|
-
`Timeline "${tl.key}" has a selectorTime, but no history. This is most likely a bug in AtomIO.`
|
|
1420
|
-
);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
if (currentTransactionKey && store.transactionStatus.phase === `applying`) {
|
|
1424
|
-
const currentTransaction = withdraw(
|
|
1425
|
-
{ key: currentTransactionKey, type: `transaction` },
|
|
1426
|
-
store
|
|
1427
|
-
);
|
|
1428
|
-
if (currentTransaction === null) {
|
|
1429
|
-
throw new Error(
|
|
1430
|
-
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
|
|
1431
|
-
);
|
|
1432
|
-
}
|
|
1433
|
-
if (tl.transactionKey !== currentTransactionKey) {
|
|
1434
|
-
if (tl.transactionKey) {
|
|
1435
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1436
|
-
`Timeline "${tl.key}" was unable to resolve transaction "${tl.transactionKey}. This is probably a bug.`
|
|
1437
|
-
);
|
|
1438
|
-
}
|
|
1439
|
-
tl.transactionKey = currentTransactionKey;
|
|
1440
|
-
const subscription = currentTransaction.subject.subscribe((update2) => {
|
|
1441
|
-
var _a2;
|
|
1442
|
-
subscription.unsubscribe();
|
|
1443
|
-
if (tl.timeTraveling === null && currentTransactionTime) {
|
|
1444
|
-
if (tl.at !== tl.history.length) {
|
|
1445
|
-
tl.history.splice(tl.at);
|
|
1446
|
-
}
|
|
1447
|
-
const timelineTransactionUpdate = __spreadProps(__spreadValues({
|
|
1448
|
-
type: `transaction_update`,
|
|
1449
|
-
timestamp: currentTransactionTime
|
|
1450
|
-
}, update2), {
|
|
1451
|
-
atomUpdates: update2.atomUpdates.filter(
|
|
1452
|
-
(atomUpdate) => atoms.some((atom3) => atom3.key === atomUpdate.key)
|
|
1453
|
-
)
|
|
1454
|
-
});
|
|
1455
|
-
tl.history.push(timelineTransactionUpdate);
|
|
1456
|
-
tl.at = tl.history.length;
|
|
1457
|
-
tl.subject.next(timelineTransactionUpdate);
|
|
1458
|
-
}
|
|
1459
|
-
tl.transactionKey = null;
|
|
1460
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1461
|
-
`\u231B timeline "${tl.key}" got a transaction_update "${update2.key}"`
|
|
1462
|
-
);
|
|
1463
|
-
});
|
|
1464
|
-
}
|
|
1465
|
-
} else if (currentSelectorKey && currentSelectorTime) {
|
|
1466
|
-
let latestUpdate = tl.history.at(-1);
|
|
1467
|
-
if (currentSelectorTime !== tl.selectorTime) {
|
|
1468
|
-
latestUpdate = {
|
|
1469
|
-
type: `selector_update`,
|
|
1470
|
-
timestamp: currentSelectorTime,
|
|
1471
|
-
key: currentSelectorKey,
|
|
1472
|
-
atomUpdates: []
|
|
1473
|
-
};
|
|
1474
|
-
latestUpdate.atomUpdates.push(__spreadValues({
|
|
1475
|
-
key: atom2.key,
|
|
1476
|
-
type: `atom_update`
|
|
1477
|
-
}, update));
|
|
1478
|
-
if (tl.at !== tl.history.length) {
|
|
1479
|
-
tl.history.splice(tl.at);
|
|
1480
|
-
}
|
|
1481
|
-
tl.history.push(latestUpdate);
|
|
1482
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1483
|
-
`\u231B timeline "${tl.key}" got a selector_update "${currentSelectorKey}" with`,
|
|
1484
|
-
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1485
|
-
);
|
|
1486
|
-
tl.at = tl.history.length;
|
|
1487
|
-
tl.selectorTime = currentSelectorTime;
|
|
1488
|
-
} else {
|
|
1489
|
-
if ((latestUpdate == null ? void 0 : latestUpdate.type) === `selector_update`) {
|
|
1490
|
-
latestUpdate.atomUpdates.push(__spreadValues({
|
|
1491
|
-
key: atom2.key,
|
|
1492
|
-
type: `atom_update`
|
|
1493
|
-
}, update));
|
|
1494
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1495
|
-
` \u231B timeline "${tl.key}" set selector_update "${currentSelectorKey}" to`,
|
|
1496
|
-
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1497
|
-
);
|
|
1498
|
-
}
|
|
1499
|
-
}
|
|
1500
|
-
if (latestUpdate)
|
|
1501
|
-
tl.subject.next(latestUpdate);
|
|
1502
|
-
} else {
|
|
1503
|
-
const timestamp = Date.now();
|
|
1504
|
-
tl.selectorTime = null;
|
|
1505
|
-
if (tl.at !== tl.history.length) {
|
|
1506
|
-
tl.history.splice(tl.at);
|
|
1507
|
-
}
|
|
1508
|
-
const atomUpdate = {
|
|
1509
|
-
type: `atom_update`,
|
|
1510
|
-
timestamp,
|
|
1511
|
-
key: atom2.key,
|
|
1512
|
-
oldValue: update.oldValue,
|
|
1513
|
-
newValue: update.newValue
|
|
1514
|
-
};
|
|
1515
|
-
tl.history.push(atomUpdate);
|
|
1516
|
-
tl.subject.next(atomUpdate);
|
|
1517
|
-
(_e = store.config.logger) == null ? void 0 : _e.info(
|
|
1518
|
-
`\u231B timeline "${tl.key}" got an atom_update to "${atom2.key}"`
|
|
1519
|
-
);
|
|
1520
|
-
tl.at = tl.history.length;
|
|
1521
|
-
}
|
|
1522
|
-
}
|
|
1523
|
-
});
|
|
1524
|
-
};
|
|
1525
|
-
|
|
1526
|
-
// src/internal/timeline-internal.ts
|
|
1527
|
-
function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
1528
|
-
var _a, _b, _c;
|
|
1529
|
-
const tl = __spreadProps(__spreadValues({
|
|
1530
|
-
key: options.key,
|
|
1531
|
-
at: 0,
|
|
1532
|
-
timeTraveling: null,
|
|
1533
|
-
selectorTime: null,
|
|
1534
|
-
transactionKey: null
|
|
1535
|
-
}, data), {
|
|
1536
|
-
history: (_a = data == null ? void 0 : data.history.map((update) => __spreadValues({}, update))) != null ? _a : [],
|
|
1537
|
-
install: (store2) => timeline__INTERNAL(options, store2, tl),
|
|
1538
|
-
subject: new Subject()
|
|
1539
|
-
});
|
|
1540
|
-
const core = target(store);
|
|
1541
|
-
for (const tokenOrFamily of options.atoms) {
|
|
1542
|
-
const timelineKey = core.timelineAtoms.getRelatedId(tokenOrFamily.key);
|
|
1543
|
-
if (timelineKey) {
|
|
1544
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1545
|
-
`\u274C Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`
|
|
1546
|
-
);
|
|
1547
|
-
continue;
|
|
1548
|
-
}
|
|
1549
|
-
if (tokenOrFamily.type === `atom_family`) {
|
|
1550
|
-
const family = tokenOrFamily;
|
|
1551
|
-
family.subject.subscribe(
|
|
1552
|
-
(token2) => addAtomToTimeline(token2, options.atoms, tl, store)
|
|
1553
|
-
);
|
|
1554
|
-
} else {
|
|
1555
|
-
const token2 = tokenOrFamily;
|
|
1556
|
-
if (`family` in token2 && token2.family) {
|
|
1557
|
-
const familyTimelineKey = core.timelineAtoms.getRelatedId(
|
|
1558
|
-
token2.family.key
|
|
1559
|
-
);
|
|
1560
|
-
if (familyTimelineKey) {
|
|
1561
|
-
(_c = store.config.logger) == null ? void 0 : _c.error(
|
|
1562
|
-
`\u274C Failed to add atom "${token2.key}" to timeline "${options.key}" because its family "${token2.family.key}" belongs to timeline "${familyTimelineKey}"`
|
|
1563
|
-
);
|
|
1564
|
-
continue;
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
addAtomToTimeline(token2, options.atoms, tl, store);
|
|
1568
|
-
}
|
|
1569
|
-
core.timelineAtoms = core.timelineAtoms.set({
|
|
1570
|
-
atomKey: tokenOrFamily.key,
|
|
1571
|
-
timelineKey: options.key
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
store.timelines.set(options.key, tl);
|
|
1575
|
-
const token = {
|
|
1576
|
-
key: options.key,
|
|
1577
|
-
type: `timeline`
|
|
1578
|
-
};
|
|
1579
|
-
store.subject.timelineCreation.next(token);
|
|
1580
|
-
return token;
|
|
1581
|
-
}
|
|
1582
|
-
|
|
1583
|
-
// src/internal/transaction/abort-transaction.ts
|
|
1584
|
-
var abortTransaction = (store) => {
|
|
1585
|
-
var _a, _b;
|
|
1586
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
1587
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1588
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
1589
|
-
);
|
|
1590
|
-
return;
|
|
1591
|
-
}
|
|
1592
|
-
store.transactionStatus = { phase: `idle` };
|
|
1593
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
1594
|
-
};
|
|
1595
|
-
|
|
1596
|
-
// src/internal/transaction/apply-transaction.ts
|
|
1597
|
-
var applyTransaction = (output, store) => {
|
|
1598
|
-
var _a, _b, _c, _d;
|
|
1599
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1600
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1601
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
1602
|
-
);
|
|
1603
|
-
return;
|
|
1604
|
-
}
|
|
1605
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1606
|
-
`\u{1F6C3} apply transaction "${store.transactionStatus.key}"`
|
|
1607
|
-
);
|
|
1608
|
-
store.transactionStatus.phase = `applying`;
|
|
1609
|
-
store.transactionStatus.output = output;
|
|
1610
|
-
const { atomUpdates } = store.transactionStatus;
|
|
1611
|
-
for (const { key, newValue } of atomUpdates) {
|
|
1612
|
-
const token = { key, type: `atom` };
|
|
1613
|
-
if (!store.valueMap.has(token.key)) {
|
|
1614
|
-
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
1615
|
-
if (!newAtom) {
|
|
1616
|
-
throw new Error(
|
|
1617
|
-
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
1618
|
-
);
|
|
1619
|
-
}
|
|
1620
|
-
store.atoms.set(newAtom.key, newAtom);
|
|
1621
|
-
store.valueMap.set(newAtom.key, newAtom.default);
|
|
1622
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
1623
|
-
}
|
|
1624
|
-
setState(token, newValue, store);
|
|
1625
|
-
}
|
|
1626
|
-
const myTransaction = withdraw(
|
|
1627
|
-
{ key: store.transactionStatus.key, type: `transaction` },
|
|
1628
|
-
store
|
|
1629
|
-
);
|
|
1630
|
-
if (myTransaction === null) {
|
|
1631
|
-
throw new Error(
|
|
1632
|
-
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
1633
|
-
);
|
|
1634
|
-
}
|
|
1635
|
-
myTransaction.subject.next({
|
|
1636
|
-
key: store.transactionStatus.key,
|
|
1637
|
-
atomUpdates,
|
|
1638
|
-
output,
|
|
1639
|
-
params: store.transactionStatus.params
|
|
1640
|
-
});
|
|
1641
|
-
store.transactionStatus = { phase: `idle` };
|
|
1642
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F6EC}`, `transaction done`);
|
|
1643
|
-
};
|
|
1644
|
-
|
|
1645
|
-
// src/internal/transaction/build-transaction.ts
|
|
1646
|
-
var buildTransaction = (key, params, store) => {
|
|
1647
|
-
var _a;
|
|
1648
|
-
store.transactionStatus = {
|
|
1649
|
-
key,
|
|
1650
|
-
phase: `building`,
|
|
1651
|
-
time: Date.now(),
|
|
1652
|
-
core: {
|
|
1653
|
-
atoms: new Map(store.atoms),
|
|
1654
|
-
atomsThatAreDefault: store.atomsThatAreDefault,
|
|
1655
|
-
operation: { open: false },
|
|
1656
|
-
readonlySelectors: new Map(store.readonlySelectors),
|
|
1657
|
-
timelines: new Map(store.timelines),
|
|
1658
|
-
timelineAtoms: store.timelineAtoms,
|
|
1659
|
-
transactions: new Map(store.transactions),
|
|
1660
|
-
selectorAtoms: store.selectorAtoms,
|
|
1661
|
-
selectorGraph: store.selectorGraph,
|
|
1662
|
-
selectors: new Map(store.selectors),
|
|
1663
|
-
valueMap: new Map(store.valueMap)
|
|
1664
|
-
},
|
|
1665
|
-
atomUpdates: [],
|
|
1666
|
-
params,
|
|
1667
|
-
output: void 0
|
|
1668
|
-
};
|
|
1669
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1670
|
-
`\u{1F6EB}`,
|
|
1671
|
-
`transaction "${key}" started in store "${store.config.name}"`
|
|
1672
|
-
);
|
|
1673
|
-
};
|
|
1674
|
-
|
|
1675
|
-
// src/internal/transaction/redo-transaction.ts
|
|
1676
|
-
var redoTransactionUpdate = (update, store) => {
|
|
1677
|
-
var _a;
|
|
1678
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23ED redo transaction "${update.key}" (redo)`);
|
|
1679
|
-
for (const { key, newValue } of update.atomUpdates) {
|
|
1680
|
-
const token = { key, type: `atom` };
|
|
1681
|
-
const state = withdraw(token, store);
|
|
1682
|
-
if (state === null) {
|
|
1683
|
-
throw new Error(
|
|
1684
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
1685
|
-
);
|
|
1686
|
-
}
|
|
1687
|
-
setState(state, newValue, store);
|
|
1688
|
-
}
|
|
1689
|
-
};
|
|
1690
|
-
|
|
1691
|
-
// src/internal/transaction/undo-transaction.ts
|
|
1692
|
-
var undoTransactionUpdate = (update, store) => {
|
|
1693
|
-
var _a;
|
|
1694
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23EE undo transaction "${update.key}" (undo)`);
|
|
1695
|
-
for (const { key, oldValue } of update.atomUpdates) {
|
|
1696
|
-
const token = { key, type: `atom` };
|
|
1697
|
-
const state = withdraw(token, store);
|
|
1698
|
-
if (state === null) {
|
|
1699
|
-
throw new Error(
|
|
1700
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
1701
|
-
);
|
|
1702
|
-
}
|
|
1703
|
-
setState(state, oldValue, store);
|
|
1704
|
-
}
|
|
1705
|
-
};
|
|
1706
|
-
|
|
1707
|
-
// src/internal/transaction/index.ts
|
|
1708
|
-
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
1709
|
-
|
|
1710
|
-
// src/atom.ts
|
|
1711
41
|
function atom(options) {
|
|
1712
|
-
|
|
42
|
+
if (`mutable` in options) {
|
|
43
|
+
return IO.createMutableAtom(options);
|
|
44
|
+
}
|
|
45
|
+
return IO.createAtom(options);
|
|
1713
46
|
}
|
|
1714
47
|
function atomFamily(options) {
|
|
1715
|
-
|
|
48
|
+
if (`mutable` in options) {
|
|
49
|
+
return IO.createMutableAtomFamily(options);
|
|
50
|
+
}
|
|
51
|
+
return IO.createAtomFamily(options);
|
|
1716
52
|
}
|
|
1717
|
-
|
|
1718
|
-
// src/logger.ts
|
|
53
|
+
var NO_OP = () => void 0;
|
|
1719
54
|
var LOG_LEVELS = [
|
|
1720
55
|
`info`,
|
|
1721
56
|
`warn`,
|
|
1722
57
|
`error`
|
|
1723
58
|
];
|
|
1724
|
-
var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
|
|
59
|
+
var setLogLevel = (preferredLevel, store = IO.IMPLICIT.STORE) => {
|
|
1725
60
|
const { logger__INTERNAL } = store.config;
|
|
1726
61
|
if (preferredLevel === null) {
|
|
1727
62
|
store.config.logger = null;
|
|
@@ -1729,132 +64,130 @@ var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
|
|
|
1729
64
|
store.config.logger = __spreadValues({}, console);
|
|
1730
65
|
LOG_LEVELS.forEach((logLevel) => {
|
|
1731
66
|
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
1732
|
-
store.config.logger[logLevel] =
|
|
67
|
+
store.config.logger[logLevel] = NO_OP;
|
|
1733
68
|
} else {
|
|
1734
69
|
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
1735
70
|
}
|
|
1736
71
|
});
|
|
1737
72
|
}
|
|
1738
73
|
};
|
|
1739
|
-
var useLogger = (logger, store = IMPLICIT.STORE) => {
|
|
74
|
+
var useLogger = (logger, store = IO.IMPLICIT.STORE) => {
|
|
1740
75
|
var _a;
|
|
1741
76
|
const currentLogLevel = store.config.logger === null ? null : (_a = LOG_LEVELS.find(
|
|
1742
77
|
(logLevel) => {
|
|
1743
78
|
var _a2;
|
|
1744
|
-
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !==
|
|
79
|
+
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== NO_OP;
|
|
1745
80
|
}
|
|
1746
81
|
)) != null ? _a : null;
|
|
1747
82
|
store.config.logger__INTERNAL = __spreadValues({}, logger);
|
|
1748
83
|
setLogLevel(currentLogLevel, store);
|
|
1749
84
|
};
|
|
1750
|
-
|
|
1751
|
-
// src/selector.ts
|
|
1752
85
|
function selector(options) {
|
|
1753
|
-
return
|
|
86
|
+
return IO.createSelector(options);
|
|
1754
87
|
}
|
|
1755
88
|
function selectorFamily(options) {
|
|
1756
|
-
return
|
|
89
|
+
return IO.createSelectorFamily(options);
|
|
1757
90
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
91
|
+
var Silo = class {
|
|
92
|
+
constructor(name, fromStore = null) {
|
|
93
|
+
const s = new IO.Store(name, fromStore);
|
|
94
|
+
this.store = s;
|
|
95
|
+
this.atom = (options) => {
|
|
96
|
+
if (`mutable` in options) {
|
|
97
|
+
return IO.createMutableAtom(options, s);
|
|
98
|
+
}
|
|
99
|
+
return IO.createAtom(options, void 0, s);
|
|
100
|
+
};
|
|
101
|
+
this.atomFamily = (options) => {
|
|
102
|
+
if (`mutable` in options) {
|
|
103
|
+
return IO.createMutableAtomFamily(options, s);
|
|
104
|
+
}
|
|
105
|
+
return IO.createAtomFamily(options, s);
|
|
106
|
+
};
|
|
107
|
+
this.selector = (options) => IO.createSelector(options, void 0, s);
|
|
108
|
+
this.selectorFamily = (options) => IO.createSelectorFamily(options, s);
|
|
109
|
+
this.transaction = (options) => IO.transaction__INTERNAL(options, s);
|
|
110
|
+
this.timeline = (options) => IO.timeline__INTERNAL(options, s);
|
|
111
|
+
this.getState = (token) => getState(token, s);
|
|
112
|
+
this.setState = (token, newValue) => setState(token, newValue, s);
|
|
113
|
+
this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
|
|
114
|
+
this.undo = (token) => IO.undo__INTERNAL(token, s);
|
|
115
|
+
this.redo = (token) => IO.redo__INTERNAL(token, s);
|
|
116
|
+
}
|
|
1776
117
|
};
|
|
1777
|
-
|
|
1778
|
-
// src/subscribe.ts
|
|
1779
|
-
var subscribe = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
118
|
+
function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) {
|
|
1780
119
|
var _a;
|
|
1781
|
-
const state = withdraw(token, store);
|
|
120
|
+
const state = IO.withdraw(token, store);
|
|
1782
121
|
if (state === null) {
|
|
1783
122
|
throw new Error(
|
|
1784
123
|
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1785
124
|
);
|
|
1786
125
|
}
|
|
1787
|
-
const
|
|
1788
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440}
|
|
1789
|
-
const
|
|
1790
|
-
const unsubscribe =
|
|
126
|
+
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
127
|
+
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} adding subscription "${key}" to "${state.key}"`);
|
|
128
|
+
const dependencyUnsubFunctions = state.type !== `atom` ? IO.subscribeToRootAtoms(state, store) : null;
|
|
129
|
+
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
1791
130
|
var _a2;
|
|
1792
131
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
1793
|
-
|
|
132
|
+
unsubFunction();
|
|
1794
133
|
} : () => {
|
|
1795
134
|
var _a2;
|
|
1796
135
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1797
136
|
`\u{1F648} unsubscribe from "${state.key}" and its dependencies`
|
|
1798
137
|
);
|
|
1799
|
-
|
|
1800
|
-
for (const
|
|
1801
|
-
|
|
138
|
+
unsubFunction();
|
|
139
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
140
|
+
unsubFromDependency();
|
|
1802
141
|
}
|
|
1803
142
|
};
|
|
1804
143
|
return unsubscribe;
|
|
1805
|
-
}
|
|
1806
|
-
var subscribeToTransaction = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
144
|
+
}
|
|
145
|
+
var subscribeToTransaction = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) => {
|
|
1807
146
|
var _a;
|
|
1808
|
-
const tx = withdraw(token, store);
|
|
147
|
+
const tx = IO.withdraw(token, store);
|
|
1809
148
|
if (tx === null) {
|
|
1810
149
|
throw new Error(
|
|
1811
150
|
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
1812
151
|
);
|
|
1813
152
|
}
|
|
1814
153
|
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to transaction "${token.key}"`);
|
|
1815
|
-
const
|
|
1816
|
-
|
|
154
|
+
const unsubscribe = tx.subject.subscribe(key, handleUpdate);
|
|
155
|
+
return () => {
|
|
1817
156
|
var _a2;
|
|
1818
157
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
1819
|
-
|
|
158
|
+
unsubscribe();
|
|
1820
159
|
};
|
|
1821
|
-
return unsubscribe;
|
|
1822
160
|
};
|
|
1823
|
-
var subscribeToTimeline = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
161
|
+
var subscribeToTimeline = (token, handleUpdate, key = Math.random().toString(36).slice(2), store = IO.IMPLICIT.STORE) => {
|
|
1824
162
|
var _a;
|
|
1825
|
-
const tl = withdraw(token, store);
|
|
163
|
+
const tl = IO.withdraw(token, store);
|
|
1826
164
|
if (tl === null) {
|
|
1827
165
|
throw new Error(
|
|
1828
166
|
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
1829
167
|
);
|
|
1830
168
|
}
|
|
1831
169
|
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to timeline "${token.key}"`);
|
|
1832
|
-
const
|
|
1833
|
-
|
|
170
|
+
const unsubscribe = tl.subject.subscribe(key, handleUpdate);
|
|
171
|
+
return () => {
|
|
1834
172
|
var _a2;
|
|
1835
173
|
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
1836
|
-
|
|
174
|
+
unsubscribe();
|
|
1837
175
|
};
|
|
1838
|
-
return unsubscribe;
|
|
1839
176
|
};
|
|
1840
|
-
|
|
1841
|
-
// src/timeline.ts
|
|
1842
177
|
var timeline = (options) => {
|
|
1843
|
-
return timeline__INTERNAL(options);
|
|
178
|
+
return IO.timeline__INTERNAL(options);
|
|
1844
179
|
};
|
|
1845
180
|
var redo = (token) => {
|
|
1846
|
-
redo__INTERNAL(token, IMPLICIT.STORE);
|
|
181
|
+
IO.redo__INTERNAL(token, IO.IMPLICIT.STORE);
|
|
1847
182
|
};
|
|
1848
183
|
var undo = (token) => {
|
|
1849
|
-
undo__INTERNAL(token, IMPLICIT.STORE);
|
|
184
|
+
IO.undo__INTERNAL(token, IO.IMPLICIT.STORE);
|
|
1850
185
|
};
|
|
1851
|
-
|
|
1852
|
-
// src/transaction.ts
|
|
1853
186
|
function transaction(options) {
|
|
1854
|
-
return transaction__INTERNAL(options);
|
|
187
|
+
return IO.transaction__INTERNAL(options);
|
|
1855
188
|
}
|
|
1856
|
-
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
1857
|
-
const tx = withdraw(token, store);
|
|
189
|
+
var runTransaction = (token, store = IO.IMPLICIT.STORE) => (...parameters) => {
|
|
190
|
+
const tx = IO.withdraw(token, store);
|
|
1858
191
|
if (tx) {
|
|
1859
192
|
return tx.run(...parameters);
|
|
1860
193
|
}
|
|
@@ -1864,55 +197,58 @@ var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
|
1864
197
|
};
|
|
1865
198
|
|
|
1866
199
|
// src/index.ts
|
|
1867
|
-
var
|
|
1868
|
-
|
|
200
|
+
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
201
|
+
var getState = (token, store = IO__namespace.IMPLICIT.STORE) => {
|
|
202
|
+
var _a;
|
|
203
|
+
const state = (_a = IO__namespace.withdraw(token, store)) != null ? _a : IO__namespace.withdrawNewFamilyMember(token, store);
|
|
1869
204
|
if (state === null) {
|
|
1870
205
|
throw new Error(
|
|
1871
206
|
`${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
|
|
1872
207
|
);
|
|
1873
208
|
}
|
|
1874
|
-
return getState__INTERNAL(state, store);
|
|
209
|
+
return IO__namespace.getState__INTERNAL(state, store);
|
|
1875
210
|
};
|
|
1876
|
-
var setState = (token, value, store = IMPLICIT.STORE) => {
|
|
211
|
+
var setState = (token, value, store = IO__namespace.IMPLICIT.STORE) => {
|
|
212
|
+
var _a;
|
|
1877
213
|
try {
|
|
1878
|
-
openOperation(token, store);
|
|
214
|
+
IO__namespace.openOperation(token, store);
|
|
1879
215
|
} catch (thrown) {
|
|
1880
216
|
if (!(typeof thrown === `symbol`)) {
|
|
1881
217
|
throw thrown;
|
|
1882
218
|
}
|
|
1883
219
|
return;
|
|
1884
220
|
}
|
|
1885
|
-
const state = withdraw(token, store);
|
|
221
|
+
const state = (_a = IO__namespace.withdraw(token, store)) != null ? _a : IO__namespace.withdrawNewFamilyMember(token, store);
|
|
1886
222
|
if (state === null) {
|
|
1887
223
|
throw new Error(
|
|
1888
224
|
`${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
|
|
1889
225
|
);
|
|
1890
226
|
}
|
|
1891
|
-
setState__INTERNAL(state, value, store);
|
|
1892
|
-
closeOperation(store);
|
|
1893
|
-
};
|
|
1894
|
-
var isDefault = (token, store = IMPLICIT.STORE) => token.type === `atom` ? isAtomDefault(token.key, store) : isSelectorDefault(token.key, store);
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
227
|
+
IO__namespace.setState__INTERNAL(state, value, store);
|
|
228
|
+
IO__namespace.closeOperation(store);
|
|
229
|
+
};
|
|
230
|
+
var isDefault = (token, store = IO__namespace.IMPLICIT.STORE) => token.type === `atom` ? IO__namespace.isAtomDefault(token.key, store) : IO__namespace.isSelectorDefault(token.key, store);
|
|
231
|
+
|
|
232
|
+
exports.LOG_LEVELS = LOG_LEVELS;
|
|
233
|
+
exports.NO_OP = NO_OP;
|
|
234
|
+
exports.Silo = Silo;
|
|
235
|
+
exports.atom = atom;
|
|
236
|
+
exports.atomFamily = atomFamily;
|
|
237
|
+
exports.capitalize = capitalize;
|
|
238
|
+
exports.getState = getState;
|
|
239
|
+
exports.isDefault = isDefault;
|
|
240
|
+
exports.redo = redo;
|
|
241
|
+
exports.runTransaction = runTransaction;
|
|
242
|
+
exports.selector = selector;
|
|
243
|
+
exports.selectorFamily = selectorFamily;
|
|
244
|
+
exports.setLogLevel = setLogLevel;
|
|
245
|
+
exports.setState = setState;
|
|
246
|
+
exports.subscribe = subscribe;
|
|
247
|
+
exports.subscribeToTimeline = subscribeToTimeline;
|
|
248
|
+
exports.subscribeToTransaction = subscribeToTransaction;
|
|
249
|
+
exports.timeline = timeline;
|
|
250
|
+
exports.transaction = transaction;
|
|
251
|
+
exports.undo = undo;
|
|
252
|
+
exports.useLogger = useLogger;
|
|
253
|
+
//# sourceMappingURL=out.js.map
|
|
1918
254
|
//# sourceMappingURL=index.js.map
|