atom.io 0.6.7 → 0.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +241 -263
- package/dist/index.d.ts +241 -263
- package/dist/index.js +28 -1911
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -1871
- package/dist/index.mjs.map +1 -1
- package/introspection/dist/index.d.mts +121 -176
- package/introspection/dist/index.d.ts +121 -176
- package/introspection/dist/index.js +6 -346
- package/introspection/dist/index.js.map +1 -1
- package/introspection/dist/index.mjs +5 -324
- package/introspection/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +37 -8
- package/json/dist/index.d.ts +37 -8
- package/json/dist/index.js +31 -48
- package/json/dist/index.js.map +1 -1
- package/json/dist/index.mjs +6 -14
- package/json/dist/index.mjs.map +1 -1
- package/package.json +30 -14
- package/react/dist/index.js +34 -83
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.mjs +7 -43
- package/react/dist/index.mjs.map +1 -1
- package/react-devtools/dist/index.css +1 -42
- package/react-devtools/dist/index.css.map +1 -1
- package/react-devtools/dist/index.d.mts +128 -193
- package/react-devtools/dist/index.d.ts +128 -193
- package/react-devtools/dist/index.js +56 -4154
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/dist/index.mjs +19 -4117
- package/react-devtools/dist/index.mjs.map +1 -1
- package/realtime/dist/index.d.mts +7 -11
- package/realtime/dist/index.d.ts +7 -11
- package/realtime/dist/index.js +26 -185
- package/realtime/dist/index.js.map +1 -1
- package/realtime/dist/index.mjs +4 -149
- package/realtime/dist/index.mjs.map +1 -1
- package/realtime-react/dist/index.d.mts +12 -16
- package/realtime-react/dist/index.d.ts +12 -16
- package/realtime-react/dist/index.js +41 -214
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/dist/index.mjs +9 -169
- package/realtime-react/dist/index.mjs.map +1 -1
- package/src/atom.ts +7 -6
- package/src/index.ts +12 -9
- package/src/logger.ts +5 -5
- package/src/selector.ts +16 -14
- package/src/silo.ts +36 -39
- package/src/subscribe.ts +25 -20
- package/src/timeline.ts +9 -4
- package/src/transaction.ts +3 -4
- package/src/internal/atom-internal.ts +0 -54
- package/src/internal/families-internal.ts +0 -141
- package/src/internal/get.ts +0 -129
- package/src/internal/index.ts +0 -15
- package/src/internal/is-default.ts +0 -35
- package/src/internal/operation.ts +0 -139
- package/src/internal/selector/create-read-write-selector.ts +0 -66
- package/src/internal/selector/create-readonly-selector.ts +0 -46
- package/src/internal/selector/index.ts +0 -4
- package/src/internal/selector/lookup-selector-sources.ts +0 -16
- package/src/internal/selector/register-selector.ts +0 -57
- package/src/internal/selector/trace-selector-atoms.ts +0 -43
- package/src/internal/selector/update-selector-atoms.ts +0 -33
- 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/subject.ts +0 -24
- package/src/internal/subscribe-internal.ts +0 -88
- package/src/internal/time-travel-internal.ts +0 -91
- package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
- package/src/internal/timeline/index.ts +0 -1
- package/src/internal/timeline-internal.ts +0 -107
- package/src/internal/transaction/abort-transaction.ts +0 -12
- package/src/internal/transaction/apply-transaction.ts +0 -57
- package/src/internal/transaction/build-transaction.ts +0 -33
- package/src/internal/transaction/index.ts +0 -25
- package/src/internal/transaction/redo-transaction.ts +0 -23
- package/src/internal/transaction/undo-transaction.ts +0 -23
- package/src/internal/transaction-internal.ts +0 -61
- package/src/introspection/attach-atom-index.ts +0 -73
- package/src/introspection/attach-introspection-states.ts +0 -42
- package/src/introspection/attach-selector-index.ts +0 -77
- package/src/introspection/attach-timeline-family.ts +0 -59
- package/src/introspection/attach-timeline-index.ts +0 -36
- package/src/introspection/attach-transaction-index.ts +0 -38
- package/src/introspection/attach-transaction-logs.ts +0 -40
- package/src/introspection/index.ts +0 -20
- package/src/json/index.ts +0 -1
- package/src/json/select-json.ts +0 -18
- package/src/react/index.ts +0 -2
- package/src/react/store-context.tsx +0 -13
- package/src/react/store-hooks.ts +0 -47
- package/src/react-devtools/AtomIODevtools.tsx +0 -107
- package/src/react-devtools/Button.tsx +0 -24
- package/src/react-devtools/StateEditor.tsx +0 -70
- package/src/react-devtools/StateIndex.tsx +0 -153
- package/src/react-devtools/TimelineIndex.tsx +0 -92
- package/src/react-devtools/TransactionIndex.tsx +0 -70
- package/src/react-devtools/Updates.tsx +0 -145
- package/src/react-devtools/devtools.scss +0 -311
- package/src/react-devtools/index.ts +0 -72
- 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-context.tsx +0 -30
- 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 -22
- package/src/realtime-react/use-push.ts +0 -25
- package/src/realtime-react/use-server-action.ts +0 -33
- package/src/realtime-testing/index.ts +0 -1
- package/src/realtime-testing/setup-realtime-test.tsx +0 -159
- package/src/web-effects/index.ts +0 -1
- package/src/web-effects/storage.ts +0 -30
package/dist/index.js
CHANGED
|
@@ -1,1912 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 import_function8 = require("fp-ts/function");
|
|
864
|
-
var stringifyJson = (json) => JSON.stringify(json);
|
|
865
|
-
|
|
866
|
-
// src/internal/families-internal.ts
|
|
867
|
-
function atomFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
868
|
-
const subject = new Subject();
|
|
869
|
-
return Object.assign(
|
|
870
|
-
(key) => {
|
|
871
|
-
var _a;
|
|
872
|
-
const subKey = stringifyJson(key);
|
|
873
|
-
const family = { key: options.key, subKey };
|
|
874
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
875
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
876
|
-
const token = existing ? deposit(existing) : atom__INTERNAL(
|
|
877
|
-
{
|
|
878
|
-
key: fullKey,
|
|
879
|
-
default: options.default instanceof Function ? options.default(key) : options.default,
|
|
880
|
-
effects: (_a = options.effects) == null ? void 0 : _a.call(options, key)
|
|
881
|
-
},
|
|
882
|
-
family,
|
|
883
|
-
store
|
|
884
|
-
);
|
|
885
|
-
subject.next(token);
|
|
886
|
-
return token;
|
|
887
|
-
},
|
|
888
|
-
{
|
|
889
|
-
key: options.key,
|
|
890
|
-
type: `atom_family`,
|
|
891
|
-
subject
|
|
892
|
-
}
|
|
893
|
-
);
|
|
894
|
-
}
|
|
895
|
-
function readonlySelectorFamily__INTERNAL(options, store) {
|
|
896
|
-
const core = target(store);
|
|
897
|
-
const subject = new Subject();
|
|
898
|
-
return Object.assign(
|
|
899
|
-
(key) => {
|
|
900
|
-
const subKey = stringifyJson(key);
|
|
901
|
-
const family = { key: options.key, subKey };
|
|
902
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
903
|
-
const existing = core.readonlySelectors.get(fullKey);
|
|
904
|
-
if (existing) {
|
|
905
|
-
return deposit(existing);
|
|
906
|
-
}
|
|
907
|
-
return selector__INTERNAL(
|
|
908
|
-
{
|
|
909
|
-
key: fullKey,
|
|
910
|
-
get: options.get(key)
|
|
911
|
-
},
|
|
912
|
-
family,
|
|
913
|
-
store
|
|
914
|
-
);
|
|
915
|
-
},
|
|
916
|
-
{
|
|
917
|
-
key: options.key,
|
|
918
|
-
type: `readonly_selector_family`,
|
|
919
|
-
subject
|
|
920
|
-
}
|
|
921
|
-
);
|
|
922
|
-
}
|
|
923
|
-
function selectorFamily__INTERNAL(options, store = IMPLICIT.STORE) {
|
|
924
|
-
const isReadonly = !(`set` in options);
|
|
925
|
-
if (isReadonly) {
|
|
926
|
-
return readonlySelectorFamily__INTERNAL(options, store);
|
|
927
|
-
}
|
|
928
|
-
const core = target(store);
|
|
929
|
-
const subject = new Subject();
|
|
930
|
-
return Object.assign(
|
|
931
|
-
(key) => {
|
|
932
|
-
const subKey = stringifyJson(key);
|
|
933
|
-
const family = { key: options.key, subKey };
|
|
934
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
935
|
-
const existing = core.selectors.get(fullKey);
|
|
936
|
-
if (existing) {
|
|
937
|
-
return deposit(existing);
|
|
938
|
-
}
|
|
939
|
-
const token = selector__INTERNAL(
|
|
940
|
-
{
|
|
941
|
-
key: fullKey,
|
|
942
|
-
get: options.get(key),
|
|
943
|
-
set: options.set(key)
|
|
944
|
-
},
|
|
945
|
-
family,
|
|
946
|
-
store
|
|
947
|
-
);
|
|
948
|
-
subject.next(token);
|
|
949
|
-
return token;
|
|
950
|
-
},
|
|
951
|
-
{
|
|
952
|
-
key: options.key,
|
|
953
|
-
type: `selector_family`
|
|
954
|
-
}
|
|
955
|
-
);
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
// src/internal/selector/create-read-write-selector.ts
|
|
959
|
-
var createReadWriteSelector = (options, family, store, core) => {
|
|
960
|
-
var _a;
|
|
961
|
-
const subject = new Subject();
|
|
962
|
-
const { get, set } = registerSelector(options.key, store);
|
|
963
|
-
const getSelf = () => {
|
|
964
|
-
const value = options.get({ get });
|
|
965
|
-
cacheValue(options.key, value, store);
|
|
966
|
-
return value;
|
|
967
|
-
};
|
|
968
|
-
const setSelf = (next) => {
|
|
969
|
-
var _a2;
|
|
970
|
-
const oldValue = getSelf();
|
|
971
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
972
|
-
` <- "${options.key}" went (`,
|
|
973
|
-
oldValue,
|
|
974
|
-
`->`,
|
|
975
|
-
next,
|
|
976
|
-
`)`
|
|
977
|
-
);
|
|
978
|
-
const newValue = become(next)(oldValue);
|
|
979
|
-
cacheValue(options.key, newValue, store);
|
|
980
|
-
markDone(options.key, store);
|
|
981
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
982
|
-
subject.next({ newValue, oldValue });
|
|
983
|
-
}
|
|
984
|
-
options.set({ get, set }, newValue);
|
|
985
|
-
};
|
|
986
|
-
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
987
|
-
subject,
|
|
988
|
-
install: (s) => selector__INTERNAL(options, family, s),
|
|
989
|
-
get: getSelf,
|
|
990
|
-
set: setSelf,
|
|
991
|
-
type: `selector`
|
|
992
|
-
}), family && { family });
|
|
993
|
-
core.selectors.set(options.key, mySelector);
|
|
994
|
-
const initialValue = getSelf();
|
|
995
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
996
|
-
const token = {
|
|
997
|
-
key: options.key,
|
|
998
|
-
type: `selector`,
|
|
999
|
-
family
|
|
1000
|
-
};
|
|
1001
|
-
store.subject.selectorCreation.next(token);
|
|
1002
|
-
return token;
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
// src/internal/selector/lookup-selector-sources.ts
|
|
1006
|
-
var lookupSelectorSources = (key, store) => target(store).selectorGraph.getRelations(key).filter(({ source }) => source !== key).map(({ source }) => lookup(source, store));
|
|
1007
|
-
|
|
1008
|
-
// src/internal/selector/trace-selector-atoms.ts
|
|
1009
|
-
var traceSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1010
|
-
const roots = [];
|
|
1011
|
-
const sources = lookupSelectorSources(dependency.key, store);
|
|
1012
|
-
let depth = 0;
|
|
1013
|
-
while (sources.length > 0) {
|
|
1014
|
-
const source = sources.shift();
|
|
1015
|
-
++depth;
|
|
1016
|
-
if (depth > 999) {
|
|
1017
|
-
throw new Error(
|
|
1018
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`
|
|
1019
|
-
);
|
|
1020
|
-
}
|
|
1021
|
-
if (source.type !== `atom`) {
|
|
1022
|
-
sources.push(...lookupSelectorSources(source.key, store));
|
|
1023
|
-
} else {
|
|
1024
|
-
roots.push(source);
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
return roots;
|
|
1028
|
-
};
|
|
1029
|
-
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
1030
|
-
const sources = lookupSelectorSources(selectorKey, store);
|
|
1031
|
-
return sources.flatMap(
|
|
1032
|
-
(source) => source.type === `atom` ? source : traceSelectorAtoms(selectorKey, source, store)
|
|
1033
|
-
);
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
// src/internal/selector/update-selector-atoms.ts
|
|
1037
|
-
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1038
|
-
var _a, _b;
|
|
1039
|
-
const core = target(store);
|
|
1040
|
-
if (dependency.type === `atom`) {
|
|
1041
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
1042
|
-
selectorKey,
|
|
1043
|
-
atomKey: dependency.key
|
|
1044
|
-
});
|
|
1045
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1046
|
-
` || adding root for "${selectorKey}": ${dependency.key}`
|
|
1047
|
-
);
|
|
1048
|
-
return;
|
|
1049
|
-
}
|
|
1050
|
-
const roots = traceSelectorAtoms(selectorKey, dependency, store);
|
|
1051
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1052
|
-
` || adding roots for "${selectorKey}":`,
|
|
1053
|
-
roots.map((r) => r.key)
|
|
1054
|
-
);
|
|
1055
|
-
for (const root of roots) {
|
|
1056
|
-
core.selectorAtoms = core.selectorAtoms.set({
|
|
1057
|
-
selectorKey,
|
|
1058
|
-
atomKey: root.key
|
|
1059
|
-
});
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
|
|
1063
|
-
// src/internal/set.ts
|
|
1064
|
-
var evictDownStream = (state, store = IMPLICIT.STORE) => {
|
|
1065
|
-
var _a, _b;
|
|
1066
|
-
const core = target(store);
|
|
1067
|
-
const downstream = core.selectorAtoms.getRelations(state.key);
|
|
1068
|
-
const downstreamKeys = downstream.map(({ id }) => id);
|
|
1069
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1070
|
-
` || ${downstreamKeys.length} downstream:`,
|
|
1071
|
-
downstreamKeys
|
|
1072
|
-
);
|
|
1073
|
-
if (core.operation.open) {
|
|
1074
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` ||`, [...core.operation.done], `already done`);
|
|
1075
|
-
}
|
|
1076
|
-
downstream.forEach(({ id: stateKey }) => {
|
|
1077
|
-
var _a2, _b2, _c, _d;
|
|
1078
|
-
if (isDone(stateKey, store)) {
|
|
1079
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(` || ${stateKey} already done`);
|
|
1080
|
-
return;
|
|
1081
|
-
}
|
|
1082
|
-
const state2 = (_b2 = core.selectors.get(stateKey)) != null ? _b2 : core.readonlySelectors.get(stateKey);
|
|
1083
|
-
if (!state2) {
|
|
1084
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1085
|
-
` || ${stateKey} is an atom, and can't be downstream`
|
|
1086
|
-
);
|
|
1087
|
-
return;
|
|
1088
|
-
}
|
|
1089
|
-
evictCachedValue(stateKey, store);
|
|
1090
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(` xx evicted "${stateKey}"`);
|
|
1091
|
-
markDone(stateKey, store);
|
|
1092
|
-
});
|
|
1093
|
-
};
|
|
1094
|
-
var setAtomState = (atom2, next, store = IMPLICIT.STORE) => {
|
|
1095
|
-
var _a, _b;
|
|
1096
|
-
const oldValue = getState__INTERNAL(atom2, store);
|
|
1097
|
-
const newValue = become(next)(oldValue);
|
|
1098
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting atom "${atom2.key}" to`, newValue);
|
|
1099
|
-
cacheValue(atom2.key, newValue, store);
|
|
1100
|
-
if (isAtomDefault(atom2.key, store)) {
|
|
1101
|
-
markAtomAsNotDefault(atom2.key, store);
|
|
1102
|
-
}
|
|
1103
|
-
markDone(atom2.key, store);
|
|
1104
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1105
|
-
` || evicting caches downstream from "${atom2.key}"`
|
|
1106
|
-
);
|
|
1107
|
-
evictDownStream(atom2, store);
|
|
1108
|
-
const update = { oldValue, newValue };
|
|
1109
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1110
|
-
emitUpdate(atom2, update, store);
|
|
1111
|
-
} else {
|
|
1112
|
-
stowUpdate(atom2, update, store);
|
|
1113
|
-
}
|
|
1114
|
-
};
|
|
1115
|
-
var setSelectorState = (selector2, next, store = IMPLICIT.STORE) => {
|
|
1116
|
-
var _a, _b;
|
|
1117
|
-
const oldValue = getState__INTERNAL(selector2, store);
|
|
1118
|
-
const newValue = become(next)(oldValue);
|
|
1119
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`<< setting selector "${selector2.key}" to`, newValue);
|
|
1120
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(` || propagating change made to "${selector2.key}"`);
|
|
1121
|
-
selector2.set(newValue);
|
|
1122
|
-
};
|
|
1123
|
-
var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
1124
|
-
if (`set` in state) {
|
|
1125
|
-
setSelectorState(state, value, store);
|
|
1126
|
-
} else {
|
|
1127
|
-
setAtomState(state, value, store);
|
|
1128
|
-
}
|
|
1129
|
-
};
|
|
1130
|
-
|
|
1131
|
-
// src/internal/selector/register-selector.ts
|
|
1132
|
-
var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
|
|
1133
|
-
get: (dependency) => {
|
|
1134
|
-
var _a, _b;
|
|
1135
|
-
const core = target(store);
|
|
1136
|
-
const alreadyRegistered = core.selectorGraph.getRelations(selectorKey).some(({ source }) => source === dependency.key);
|
|
1137
|
-
const dependencyState = withdraw(dependency, store);
|
|
1138
|
-
if (dependencyState === null) {
|
|
1139
|
-
throw new Error(
|
|
1140
|
-
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1141
|
-
);
|
|
1142
|
-
}
|
|
1143
|
-
const dependencyValue = getState__INTERNAL(dependencyState, store);
|
|
1144
|
-
if (alreadyRegistered) {
|
|
1145
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1146
|
-
` || ${selectorKey} <- ${dependency.key} =`,
|
|
1147
|
-
dependencyValue
|
|
1148
|
-
);
|
|
1149
|
-
} else {
|
|
1150
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1151
|
-
`\u{1F50C} registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
|
|
1152
|
-
dependencyValue,
|
|
1153
|
-
`)`
|
|
1154
|
-
);
|
|
1155
|
-
core.selectorGraph = core.selectorGraph.set(
|
|
1156
|
-
{ from: dependency.key, to: selectorKey },
|
|
1157
|
-
{
|
|
1158
|
-
source: dependency.key
|
|
1159
|
-
}
|
|
1160
|
-
);
|
|
1161
|
-
}
|
|
1162
|
-
updateSelectorAtoms(selectorKey, dependency, store);
|
|
1163
|
-
return dependencyValue;
|
|
1164
|
-
},
|
|
1165
|
-
set: (stateToken, newValue) => {
|
|
1166
|
-
const state = withdraw(stateToken, store);
|
|
1167
|
-
if (state === null) {
|
|
1168
|
-
throw new Error(
|
|
1169
|
-
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1170
|
-
);
|
|
1171
|
-
}
|
|
1172
|
-
setState__INTERNAL(state, newValue, store);
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
|
|
1176
|
-
// src/internal/selector/create-readonly-selector.ts
|
|
1177
|
-
var createReadonlySelector = (options, family, store, core) => {
|
|
1178
|
-
var _a;
|
|
1179
|
-
const subject = new Subject();
|
|
1180
|
-
const { get } = registerSelector(options.key, store);
|
|
1181
|
-
const getSelf = () => {
|
|
1182
|
-
const value = options.get({ get });
|
|
1183
|
-
cacheValue(options.key, value, store);
|
|
1184
|
-
return value;
|
|
1185
|
-
};
|
|
1186
|
-
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1187
|
-
subject,
|
|
1188
|
-
install: (s) => selector__INTERNAL(options, family, s),
|
|
1189
|
-
get: getSelf,
|
|
1190
|
-
type: `readonly_selector`
|
|
1191
|
-
}), family && { family });
|
|
1192
|
-
core.readonlySelectors.set(options.key, readonlySelector);
|
|
1193
|
-
const initialValue = getSelf();
|
|
1194
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
|
|
1195
|
-
const token = {
|
|
1196
|
-
key: options.key,
|
|
1197
|
-
type: `readonly_selector`,
|
|
1198
|
-
family
|
|
1199
|
-
};
|
|
1200
|
-
store.subject.selectorCreation.next(token);
|
|
1201
|
-
return token;
|
|
1202
|
-
};
|
|
1203
|
-
|
|
1204
|
-
// src/internal/selector-internal.ts
|
|
1205
|
-
function selector__INTERNAL(options, family, store = IMPLICIT.STORE) {
|
|
1206
|
-
var _a;
|
|
1207
|
-
const core = target(store);
|
|
1208
|
-
if (core.selectors.has(options.key)) {
|
|
1209
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
1210
|
-
`Key "${options.key}" already exists in the store.`
|
|
1211
|
-
);
|
|
1212
|
-
}
|
|
1213
|
-
if (!(`set` in options)) {
|
|
1214
|
-
return createReadonlySelector(options, family, store, core);
|
|
1215
|
-
}
|
|
1216
|
-
return createReadWriteSelector(options, family, store, core);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
// src/internal/subject.ts
|
|
1220
|
-
var Subject = class {
|
|
1221
|
-
constructor() {
|
|
1222
|
-
this.subscribers = [];
|
|
1223
|
-
}
|
|
1224
|
-
subscribe(subscriber) {
|
|
1225
|
-
this.subscribers.push(subscriber);
|
|
1226
|
-
const unsubscribe = () => this.unsubscribe(subscriber);
|
|
1227
|
-
return { unsubscribe };
|
|
1228
|
-
}
|
|
1229
|
-
unsubscribe(subscriber) {
|
|
1230
|
-
const subscriberIndex = this.subscribers.indexOf(subscriber);
|
|
1231
|
-
if (subscriberIndex !== -1) {
|
|
1232
|
-
this.subscribers.splice(subscriberIndex, 1);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
next(value) {
|
|
1236
|
-
for (const subscriber of this.subscribers) {
|
|
1237
|
-
subscriber(value);
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1241
|
-
|
|
1242
|
-
// src/internal/subscribe-internal.ts
|
|
1243
|
-
var prepareUpdate = (state, store) => {
|
|
1244
|
-
const oldValue = recallState(state, store);
|
|
1245
|
-
const newValue = getState__INTERNAL(state, store);
|
|
1246
|
-
return { newValue, oldValue };
|
|
1247
|
-
};
|
|
1248
|
-
var stowUpdate = (state, update, store) => {
|
|
1249
|
-
var _a;
|
|
1250
|
-
const { key } = state;
|
|
1251
|
-
const { logger } = store.config;
|
|
1252
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1253
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1254
|
-
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
1255
|
-
);
|
|
1256
|
-
return;
|
|
1257
|
-
}
|
|
1258
|
-
store.transactionStatus.atomUpdates.push(__spreadValues({ key }, update));
|
|
1259
|
-
logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
|
|
1260
|
-
};
|
|
1261
|
-
var emitUpdate = (state, update, store) => {
|
|
1262
|
-
const { key } = state;
|
|
1263
|
-
const { logger } = store.config;
|
|
1264
|
-
logger == null ? void 0 : logger.info(
|
|
1265
|
-
`\u{1F4E2} ${state.type} "${key}" went (`,
|
|
1266
|
-
update.oldValue,
|
|
1267
|
-
`->`,
|
|
1268
|
-
update.newValue,
|
|
1269
|
-
`)`
|
|
1270
|
-
);
|
|
1271
|
-
state.subject.next(update);
|
|
1272
|
-
};
|
|
1273
|
-
var subscribeToRootAtoms = (state, store) => {
|
|
1274
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
|
|
1275
|
-
const atom2 = withdraw(atomToken, store);
|
|
1276
|
-
if (atom2 === null) {
|
|
1277
|
-
throw new Error(
|
|
1278
|
-
`Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1279
|
-
);
|
|
1280
|
-
}
|
|
1281
|
-
return atom2.subject.subscribe((atomChange) => {
|
|
1282
|
-
var _a, _b;
|
|
1283
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1284
|
-
`\u{1F4E2} selector "${state.key}" saw root "${atomToken.key}" go (`,
|
|
1285
|
-
atomChange.oldValue,
|
|
1286
|
-
`->`,
|
|
1287
|
-
atomChange.newValue,
|
|
1288
|
-
`)`
|
|
1289
|
-
);
|
|
1290
|
-
const oldValue = recallState(state, store);
|
|
1291
|
-
const newValue = getState__INTERNAL(state, store);
|
|
1292
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1293
|
-
` <- "${state.key}" went (`,
|
|
1294
|
-
oldValue,
|
|
1295
|
-
`->`,
|
|
1296
|
-
newValue,
|
|
1297
|
-
`)`
|
|
1298
|
-
);
|
|
1299
|
-
state.subject.next({ newValue, oldValue });
|
|
1300
|
-
});
|
|
1301
|
-
});
|
|
1302
|
-
return dependencySubscriptions;
|
|
1303
|
-
};
|
|
1304
|
-
|
|
1305
|
-
// src/internal/time-travel-internal.ts
|
|
1306
|
-
var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1307
|
-
var _a, _b, _c, _d;
|
|
1308
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23E9 redo "${token.key}"`);
|
|
1309
|
-
const timelineData = store.timelines.get(token.key);
|
|
1310
|
-
if (!timelineData) {
|
|
1311
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1312
|
-
`Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1313
|
-
);
|
|
1314
|
-
return;
|
|
1315
|
-
}
|
|
1316
|
-
if (timelineData.at === timelineData.history.length) {
|
|
1317
|
-
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1318
|
-
`Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
|
|
1319
|
-
);
|
|
1320
|
-
return;
|
|
1321
|
-
}
|
|
1322
|
-
timelineData.timeTraveling = true;
|
|
1323
|
-
const update = timelineData.history[timelineData.at];
|
|
1324
|
-
switch (update.type) {
|
|
1325
|
-
case `atom_update`: {
|
|
1326
|
-
const { key, newValue } = update;
|
|
1327
|
-
setState({ key, type: `atom` }, newValue, store);
|
|
1328
|
-
break;
|
|
1329
|
-
}
|
|
1330
|
-
case `selector_update`:
|
|
1331
|
-
case `transaction_update`: {
|
|
1332
|
-
for (const atomUpdate of update.atomUpdates) {
|
|
1333
|
-
const { key, newValue } = atomUpdate;
|
|
1334
|
-
setState({ key, type: `atom` }, newValue, store);
|
|
1335
|
-
}
|
|
1336
|
-
break;
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
++timelineData.at;
|
|
1340
|
-
timelineData.subject.next(`redo`);
|
|
1341
|
-
timelineData.timeTraveling = false;
|
|
1342
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1343
|
-
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1344
|
-
);
|
|
1345
|
-
};
|
|
1346
|
-
var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
|
|
1347
|
-
var _a, _b, _c, _d;
|
|
1348
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u23EA undo "${token.key}"`);
|
|
1349
|
-
const timelineData = store.timelines.get(token.key);
|
|
1350
|
-
if (!timelineData) {
|
|
1351
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1352
|
-
`Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
|
|
1353
|
-
);
|
|
1354
|
-
return;
|
|
1355
|
-
}
|
|
1356
|
-
if (timelineData.at === 0) {
|
|
1357
|
-
(_c = store.config.logger) == null ? void 0 : _c.warn(
|
|
1358
|
-
`Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
|
|
1359
|
-
);
|
|
1360
|
-
return;
|
|
1361
|
-
}
|
|
1362
|
-
timelineData.timeTraveling = true;
|
|
1363
|
-
--timelineData.at;
|
|
1364
|
-
const update = timelineData.history[timelineData.at];
|
|
1365
|
-
switch (update.type) {
|
|
1366
|
-
case `atom_update`: {
|
|
1367
|
-
const { key, oldValue } = update;
|
|
1368
|
-
setState({ key, type: `atom` }, oldValue, store);
|
|
1369
|
-
break;
|
|
1370
|
-
}
|
|
1371
|
-
case `selector_update`:
|
|
1372
|
-
case `transaction_update`: {
|
|
1373
|
-
for (const atomUpdate of update.atomUpdates) {
|
|
1374
|
-
const { key, oldValue } = atomUpdate;
|
|
1375
|
-
setState({ key, type: `atom` }, oldValue, store);
|
|
1376
|
-
}
|
|
1377
|
-
break;
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
timelineData.subject.next(`undo`);
|
|
1381
|
-
timelineData.timeTraveling = false;
|
|
1382
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1383
|
-
`\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
|
|
1384
|
-
);
|
|
1385
|
-
};
|
|
1386
|
-
|
|
1387
|
-
// src/internal/timeline/add-atom-to-timeline.ts
|
|
1388
|
-
var addAtomToTimeline = (atomToken, atoms, tl, store = IMPLICIT.STORE) => {
|
|
1389
|
-
const atom2 = withdraw(atomToken, store);
|
|
1390
|
-
if (atom2 === null) {
|
|
1391
|
-
throw new Error(
|
|
1392
|
-
`Cannot subscribe to atom "${atomToken.key}" because it has not been initialized in store "${store.config.name}"`
|
|
1393
|
-
);
|
|
1394
|
-
}
|
|
1395
|
-
atom2.subject.subscribe((update) => {
|
|
1396
|
-
var _a, _b, _c, _d, _e;
|
|
1397
|
-
const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
|
|
1398
|
-
const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
|
|
1399
|
-
const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
|
|
1400
|
-
const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
|
|
1401
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1402
|
-
`\u23F3 timeline "${tl.key}" saw atom "${atomToken.key}" go (`,
|
|
1403
|
-
update.oldValue,
|
|
1404
|
-
`->`,
|
|
1405
|
-
update.newValue,
|
|
1406
|
-
currentTransactionKey ? `) in transaction "${currentTransactionKey}"` : currentSelectorKey ? `) in selector "${currentSelectorKey}"` : `)`
|
|
1407
|
-
);
|
|
1408
|
-
if (tl.timeTraveling === false) {
|
|
1409
|
-
if (tl.selectorTime && tl.selectorTime !== currentSelectorTime) {
|
|
1410
|
-
const mostRecentUpdate = tl.history.at(-1);
|
|
1411
|
-
if (mostRecentUpdate === void 0) {
|
|
1412
|
-
throw new Error(
|
|
1413
|
-
`Timeline "${tl.key}" has a selectorTime, but no history. This is most likely a bug in AtomIO.`
|
|
1414
|
-
);
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
if (currentTransactionKey && store.transactionStatus.phase === `applying`) {
|
|
1418
|
-
const currentTransaction = withdraw(
|
|
1419
|
-
{ key: currentTransactionKey, type: `transaction` },
|
|
1420
|
-
store
|
|
1421
|
-
);
|
|
1422
|
-
if (currentTransaction === null) {
|
|
1423
|
-
throw new Error(
|
|
1424
|
-
`Transaction "${currentTransactionKey}" not found in store "${store.config.name}". This is surprising, because we are in the application phase of "${currentTransactionKey}".`
|
|
1425
|
-
);
|
|
1426
|
-
}
|
|
1427
|
-
if (tl.transactionKey !== currentTransactionKey) {
|
|
1428
|
-
if (tl.transactionKey) {
|
|
1429
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1430
|
-
`Timeline "${tl.key}" was unable to resolve transaction "${tl.transactionKey}. This is probably a bug.`
|
|
1431
|
-
);
|
|
1432
|
-
}
|
|
1433
|
-
tl.transactionKey = currentTransactionKey;
|
|
1434
|
-
const subscription = currentTransaction.subject.subscribe((update2) => {
|
|
1435
|
-
var _a2;
|
|
1436
|
-
subscription.unsubscribe();
|
|
1437
|
-
if (tl.timeTraveling === false && currentTransactionTime) {
|
|
1438
|
-
if (tl.at !== tl.history.length) {
|
|
1439
|
-
tl.history.splice(tl.at);
|
|
1440
|
-
}
|
|
1441
|
-
const timelineTransactionUpdate = __spreadProps(__spreadValues({
|
|
1442
|
-
type: `transaction_update`,
|
|
1443
|
-
timestamp: currentTransactionTime
|
|
1444
|
-
}, update2), {
|
|
1445
|
-
atomUpdates: update2.atomUpdates.filter(
|
|
1446
|
-
(atomUpdate) => atoms.some((atom3) => atom3.key === atomUpdate.key)
|
|
1447
|
-
)
|
|
1448
|
-
});
|
|
1449
|
-
tl.history.push(timelineTransactionUpdate);
|
|
1450
|
-
tl.at = tl.history.length;
|
|
1451
|
-
tl.subject.next(timelineTransactionUpdate);
|
|
1452
|
-
}
|
|
1453
|
-
tl.transactionKey = null;
|
|
1454
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1455
|
-
`\u231B timeline "${tl.key}" got a transaction_update "${update2.key}"`
|
|
1456
|
-
);
|
|
1457
|
-
});
|
|
1458
|
-
}
|
|
1459
|
-
} else if (currentSelectorKey && currentSelectorTime) {
|
|
1460
|
-
let latestUpdate = tl.history.at(-1);
|
|
1461
|
-
if (currentSelectorTime !== tl.selectorTime) {
|
|
1462
|
-
latestUpdate = {
|
|
1463
|
-
type: `selector_update`,
|
|
1464
|
-
timestamp: currentSelectorTime,
|
|
1465
|
-
key: currentSelectorKey,
|
|
1466
|
-
atomUpdates: []
|
|
1467
|
-
};
|
|
1468
|
-
latestUpdate.atomUpdates.push(__spreadValues({
|
|
1469
|
-
key: atom2.key,
|
|
1470
|
-
type: `atom_update`
|
|
1471
|
-
}, update));
|
|
1472
|
-
if (tl.at !== tl.history.length) {
|
|
1473
|
-
tl.history.splice(tl.at);
|
|
1474
|
-
}
|
|
1475
|
-
tl.history.push(latestUpdate);
|
|
1476
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(
|
|
1477
|
-
`\u231B timeline "${tl.key}" got a selector_update "${currentSelectorKey}" with`,
|
|
1478
|
-
latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1479
|
-
);
|
|
1480
|
-
tl.at = tl.history.length;
|
|
1481
|
-
tl.selectorTime = currentSelectorTime;
|
|
1482
|
-
} else {
|
|
1483
|
-
if ((latestUpdate == null ? void 0 : latestUpdate.type) === `selector_update`) {
|
|
1484
|
-
latestUpdate.atomUpdates.push(__spreadValues({
|
|
1485
|
-
key: atom2.key,
|
|
1486
|
-
type: `atom_update`
|
|
1487
|
-
}, update));
|
|
1488
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(
|
|
1489
|
-
` \u231B timeline "${tl.key}" set selector_update "${currentSelectorKey}" to`,
|
|
1490
|
-
latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
|
|
1491
|
-
);
|
|
1492
|
-
}
|
|
1493
|
-
}
|
|
1494
|
-
if (latestUpdate)
|
|
1495
|
-
tl.subject.next(latestUpdate);
|
|
1496
|
-
} else {
|
|
1497
|
-
const timestamp = Date.now();
|
|
1498
|
-
tl.selectorTime = null;
|
|
1499
|
-
if (tl.at !== tl.history.length) {
|
|
1500
|
-
tl.history.splice(tl.at);
|
|
1501
|
-
}
|
|
1502
|
-
const atomUpdate = {
|
|
1503
|
-
type: `atom_update`,
|
|
1504
|
-
timestamp,
|
|
1505
|
-
key: atom2.key,
|
|
1506
|
-
oldValue: update.oldValue,
|
|
1507
|
-
newValue: update.newValue
|
|
1508
|
-
};
|
|
1509
|
-
tl.history.push(atomUpdate);
|
|
1510
|
-
tl.subject.next(atomUpdate);
|
|
1511
|
-
(_e = store.config.logger) == null ? void 0 : _e.info(
|
|
1512
|
-
`\u231B timeline "${tl.key}" got an atom_update to "${atom2.key}"`
|
|
1513
|
-
);
|
|
1514
|
-
tl.at = tl.history.length;
|
|
1515
|
-
}
|
|
1516
|
-
}
|
|
1517
|
-
});
|
|
1518
|
-
};
|
|
1519
|
-
|
|
1520
|
-
// src/internal/timeline-internal.ts
|
|
1521
|
-
function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
|
|
1522
|
-
var _a, _b, _c;
|
|
1523
|
-
const tl = __spreadProps(__spreadValues({
|
|
1524
|
-
key: options.key,
|
|
1525
|
-
at: 0,
|
|
1526
|
-
timeTraveling: false,
|
|
1527
|
-
selectorTime: null,
|
|
1528
|
-
transactionKey: null
|
|
1529
|
-
}, data), {
|
|
1530
|
-
history: (_a = data == null ? void 0 : data.history.map((update) => __spreadValues({}, update))) != null ? _a : [],
|
|
1531
|
-
install: (store2) => timeline__INTERNAL(options, store2, tl),
|
|
1532
|
-
subject: new Subject()
|
|
1533
|
-
});
|
|
1534
|
-
const core = target(store);
|
|
1535
|
-
for (const tokenOrFamily of options.atoms) {
|
|
1536
|
-
const timelineKey = core.timelineAtoms.getRelatedId(tokenOrFamily.key);
|
|
1537
|
-
if (timelineKey) {
|
|
1538
|
-
(_b = store.config.logger) == null ? void 0 : _b.error(
|
|
1539
|
-
`\u274C Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`
|
|
1540
|
-
);
|
|
1541
|
-
continue;
|
|
1542
|
-
}
|
|
1543
|
-
if (tokenOrFamily.type === `atom_family`) {
|
|
1544
|
-
const family = tokenOrFamily;
|
|
1545
|
-
family.subject.subscribe(
|
|
1546
|
-
(token2) => addAtomToTimeline(token2, options.atoms, tl, store)
|
|
1547
|
-
);
|
|
1548
|
-
} else {
|
|
1549
|
-
const token2 = tokenOrFamily;
|
|
1550
|
-
if (`family` in token2 && token2.family) {
|
|
1551
|
-
const familyTimelineKey = core.timelineAtoms.getRelatedId(
|
|
1552
|
-
token2.family.key
|
|
1553
|
-
);
|
|
1554
|
-
if (familyTimelineKey) {
|
|
1555
|
-
(_c = store.config.logger) == null ? void 0 : _c.error(
|
|
1556
|
-
`\u274C Failed to add atom "${token2.key}" to timeline "${options.key}" because its family "${token2.family.key}" belongs to timeline "${familyTimelineKey}"`
|
|
1557
|
-
);
|
|
1558
|
-
continue;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
addAtomToTimeline(token2, options.atoms, tl, store);
|
|
1562
|
-
}
|
|
1563
|
-
core.timelineAtoms = core.timelineAtoms.set({
|
|
1564
|
-
atomKey: tokenOrFamily.key,
|
|
1565
|
-
timelineKey: options.key
|
|
1566
|
-
});
|
|
1567
|
-
}
|
|
1568
|
-
store.timelines.set(options.key, tl);
|
|
1569
|
-
const token = {
|
|
1570
|
-
key: options.key,
|
|
1571
|
-
type: `timeline`
|
|
1572
|
-
};
|
|
1573
|
-
store.subject.timelineCreation.next(token);
|
|
1574
|
-
return token;
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
// src/internal/transaction/abort-transaction.ts
|
|
1578
|
-
var abortTransaction = (store) => {
|
|
1579
|
-
var _a, _b;
|
|
1580
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
1581
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1582
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
1583
|
-
);
|
|
1584
|
-
return;
|
|
1585
|
-
}
|
|
1586
|
-
store.transactionStatus = { phase: `idle` };
|
|
1587
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
1588
|
-
};
|
|
1589
|
-
|
|
1590
|
-
// src/internal/transaction/apply-transaction.ts
|
|
1591
|
-
var applyTransaction = (output, store) => {
|
|
1592
|
-
var _a, _b, _c, _d;
|
|
1593
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
1594
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1595
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
1596
|
-
);
|
|
1597
|
-
return;
|
|
1598
|
-
}
|
|
1599
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1600
|
-
`\u{1F6C3} apply transaction "${store.transactionStatus.key}"`
|
|
1601
|
-
);
|
|
1602
|
-
store.transactionStatus.phase = `applying`;
|
|
1603
|
-
store.transactionStatus.output = output;
|
|
1604
|
-
const { atomUpdates } = store.transactionStatus;
|
|
1605
|
-
for (const { key, newValue } of atomUpdates) {
|
|
1606
|
-
const token = { key, type: `atom` };
|
|
1607
|
-
if (!store.valueMap.has(token.key)) {
|
|
1608
|
-
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
1609
|
-
if (!newAtom) {
|
|
1610
|
-
throw new Error(
|
|
1611
|
-
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
1612
|
-
);
|
|
1613
|
-
}
|
|
1614
|
-
store.atoms.set(newAtom.key, newAtom);
|
|
1615
|
-
store.valueMap.set(newAtom.key, newAtom.default);
|
|
1616
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
1617
|
-
}
|
|
1618
|
-
setState(token, newValue, store);
|
|
1619
|
-
}
|
|
1620
|
-
const myTransaction = withdraw(
|
|
1621
|
-
{ key: store.transactionStatus.key, type: `transaction` },
|
|
1622
|
-
store
|
|
1623
|
-
);
|
|
1624
|
-
if (myTransaction === null) {
|
|
1625
|
-
throw new Error(
|
|
1626
|
-
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
1627
|
-
);
|
|
1628
|
-
}
|
|
1629
|
-
myTransaction.subject.next({
|
|
1630
|
-
key: store.transactionStatus.key,
|
|
1631
|
-
atomUpdates,
|
|
1632
|
-
output,
|
|
1633
|
-
params: store.transactionStatus.params
|
|
1634
|
-
});
|
|
1635
|
-
store.transactionStatus = { phase: `idle` };
|
|
1636
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F6EC}`, `transaction done`);
|
|
1637
|
-
};
|
|
1638
|
-
|
|
1639
|
-
// src/internal/transaction/build-transaction.ts
|
|
1640
|
-
var buildTransaction = (key, params, store) => {
|
|
1641
|
-
var _a;
|
|
1642
|
-
store.transactionStatus = {
|
|
1643
|
-
key,
|
|
1644
|
-
phase: `building`,
|
|
1645
|
-
time: Date.now(),
|
|
1646
|
-
core: {
|
|
1647
|
-
atoms: new Map(store.atoms),
|
|
1648
|
-
atomsThatAreDefault: store.atomsThatAreDefault,
|
|
1649
|
-
operation: { open: false },
|
|
1650
|
-
readonlySelectors: new Map(store.readonlySelectors),
|
|
1651
|
-
timelines: new Map(store.timelines),
|
|
1652
|
-
timelineAtoms: store.timelineAtoms,
|
|
1653
|
-
transactions: new Map(store.transactions),
|
|
1654
|
-
selectorAtoms: store.selectorAtoms,
|
|
1655
|
-
selectorGraph: store.selectorGraph,
|
|
1656
|
-
selectors: new Map(store.selectors),
|
|
1657
|
-
valueMap: new Map(store.valueMap)
|
|
1658
|
-
},
|
|
1659
|
-
atomUpdates: [],
|
|
1660
|
-
params,
|
|
1661
|
-
output: void 0
|
|
1662
|
-
};
|
|
1663
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1664
|
-
`\u{1F6EB}`,
|
|
1665
|
-
`transaction "${key}" started in store "${store.config.name}"`
|
|
1666
|
-
);
|
|
1667
|
-
};
|
|
1668
|
-
|
|
1669
|
-
// src/internal/transaction/redo-transaction.ts
|
|
1670
|
-
var redoTransactionUpdate = (update, store) => {
|
|
1671
|
-
var _a;
|
|
1672
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23ED redo transaction "${update.key}" (redo)`);
|
|
1673
|
-
for (const { key, newValue } of update.atomUpdates) {
|
|
1674
|
-
const token = { key, type: `atom` };
|
|
1675
|
-
const state = withdraw(token, store);
|
|
1676
|
-
if (state === null) {
|
|
1677
|
-
throw new Error(
|
|
1678
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
1679
|
-
);
|
|
1680
|
-
}
|
|
1681
|
-
setState(state, newValue, store);
|
|
1682
|
-
}
|
|
1683
|
-
};
|
|
1684
|
-
|
|
1685
|
-
// src/internal/transaction/undo-transaction.ts
|
|
1686
|
-
var undoTransactionUpdate = (update, store) => {
|
|
1687
|
-
var _a;
|
|
1688
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(` \u23EE undo transaction "${update.key}" (undo)`);
|
|
1689
|
-
for (const { key, oldValue } of update.atomUpdates) {
|
|
1690
|
-
const token = { key, type: `atom` };
|
|
1691
|
-
const state = withdraw(token, store);
|
|
1692
|
-
if (state === null) {
|
|
1693
|
-
throw new Error(
|
|
1694
|
-
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
1695
|
-
);
|
|
1696
|
-
}
|
|
1697
|
-
setState(state, oldValue, store);
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
|
|
1701
|
-
// src/internal/transaction/index.ts
|
|
1702
|
-
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
1703
|
-
|
|
1704
|
-
// src/atom.ts
|
|
1705
|
-
function atom(options) {
|
|
1706
|
-
return atom__INTERNAL(options);
|
|
1707
|
-
}
|
|
1708
|
-
function atomFamily(options) {
|
|
1709
|
-
return atomFamily__INTERNAL(options);
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
// src/logger.ts
|
|
1713
|
-
var LOG_LEVELS = [
|
|
1714
|
-
`info`,
|
|
1715
|
-
`warn`,
|
|
1716
|
-
`error`
|
|
1717
|
-
];
|
|
1718
|
-
var setLogLevel = (preferredLevel, store = IMPLICIT.STORE) => {
|
|
1719
|
-
const { logger__INTERNAL } = store.config;
|
|
1720
|
-
if (preferredLevel === null) {
|
|
1721
|
-
store.config.logger = null;
|
|
1722
|
-
} else {
|
|
1723
|
-
store.config.logger = __spreadValues({}, console);
|
|
1724
|
-
LOG_LEVELS.forEach((logLevel) => {
|
|
1725
|
-
if (LOG_LEVELS.indexOf(logLevel) < LOG_LEVELS.indexOf(preferredLevel)) {
|
|
1726
|
-
store.config.logger[logLevel] = doNothing;
|
|
1727
|
-
} else {
|
|
1728
|
-
store.config.logger[logLevel] = logger__INTERNAL[logLevel];
|
|
1729
|
-
}
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
var useLogger = (logger, store = IMPLICIT.STORE) => {
|
|
1734
|
-
var _a;
|
|
1735
|
-
const currentLogLevel = store.config.logger === null ? null : (_a = LOG_LEVELS.find(
|
|
1736
|
-
(logLevel) => {
|
|
1737
|
-
var _a2;
|
|
1738
|
-
return ((_a2 = store.config.logger) == null ? void 0 : _a2[logLevel]) !== doNothing;
|
|
1739
|
-
}
|
|
1740
|
-
)) != null ? _a : null;
|
|
1741
|
-
store.config.logger__INTERNAL = __spreadValues({}, logger);
|
|
1742
|
-
setLogLevel(currentLogLevel, store);
|
|
1743
|
-
};
|
|
1744
|
-
|
|
1745
|
-
// src/selector.ts
|
|
1746
|
-
function selector(options) {
|
|
1747
|
-
return selector__INTERNAL(options);
|
|
1748
|
-
}
|
|
1749
|
-
function selectorFamily(options) {
|
|
1750
|
-
return selectorFamily__INTERNAL(options);
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
// src/silo.ts
|
|
1754
|
-
var silo = (name, fromStore = null) => {
|
|
1755
|
-
const store = createStore(name, fromStore);
|
|
1756
|
-
return {
|
|
1757
|
-
store,
|
|
1758
|
-
atom: (options) => atom__INTERNAL(options, void 0, store),
|
|
1759
|
-
atomFamily: (options) => atomFamily__INTERNAL(options, store),
|
|
1760
|
-
selector: (options) => selector__INTERNAL(options, void 0, store),
|
|
1761
|
-
selectorFamily: (options) => selectorFamily__INTERNAL(options, store),
|
|
1762
|
-
transaction: (options) => transaction__INTERNAL(options, store),
|
|
1763
|
-
timeline: (options) => timeline__INTERNAL(options, store),
|
|
1764
|
-
getState: (token) => getState(token, store),
|
|
1765
|
-
setState: (token, newValue) => setState(token, newValue, store),
|
|
1766
|
-
subscribe: (token, handler) => subscribe(token, handler, store),
|
|
1767
|
-
undo: (token) => undo__INTERNAL(token, store),
|
|
1768
|
-
redo: (token) => redo__INTERNAL(token, store)
|
|
1769
|
-
};
|
|
1770
|
-
};
|
|
1771
|
-
|
|
1772
|
-
// src/subscribe.ts
|
|
1773
|
-
var subscribe = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
1774
|
-
var _a;
|
|
1775
|
-
const state = withdraw(token, store);
|
|
1776
|
-
if (state === null) {
|
|
1777
|
-
throw new Error(
|
|
1778
|
-
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1779
|
-
);
|
|
1780
|
-
}
|
|
1781
|
-
const subscription = state.subject.subscribe(handleUpdate);
|
|
1782
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to "${state.key}"`);
|
|
1783
|
-
const dependencySubscriptions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1784
|
-
const unsubscribe = dependencySubscriptions === null ? () => {
|
|
1785
|
-
var _a2;
|
|
1786
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from "${state.key}"`);
|
|
1787
|
-
subscription.unsubscribe();
|
|
1788
|
-
} : () => {
|
|
1789
|
-
var _a2;
|
|
1790
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(
|
|
1791
|
-
`\u{1F648} unsubscribe from "${state.key}" and its dependencies`
|
|
1792
|
-
);
|
|
1793
|
-
subscription.unsubscribe();
|
|
1794
|
-
for (const dependencySubscription of dependencySubscriptions) {
|
|
1795
|
-
dependencySubscription.unsubscribe();
|
|
1796
|
-
}
|
|
1797
|
-
};
|
|
1798
|
-
return unsubscribe;
|
|
1799
|
-
};
|
|
1800
|
-
var subscribeToTransaction = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
1801
|
-
var _a;
|
|
1802
|
-
const tx = withdraw(token, store);
|
|
1803
|
-
if (tx === null) {
|
|
1804
|
-
throw new Error(
|
|
1805
|
-
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
1806
|
-
);
|
|
1807
|
-
}
|
|
1808
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to transaction "${token.key}"`);
|
|
1809
|
-
const subscription = tx.subject.subscribe(handleUpdate);
|
|
1810
|
-
const unsubscribe = () => {
|
|
1811
|
-
var _a2;
|
|
1812
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from transaction "${token.key}"`);
|
|
1813
|
-
subscription.unsubscribe();
|
|
1814
|
-
};
|
|
1815
|
-
return unsubscribe;
|
|
1816
|
-
};
|
|
1817
|
-
var subscribeToTimeline = (token, handleUpdate, store = IMPLICIT.STORE) => {
|
|
1818
|
-
var _a;
|
|
1819
|
-
const tl = withdraw(token, store);
|
|
1820
|
-
if (tl === null) {
|
|
1821
|
-
throw new Error(
|
|
1822
|
-
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
1823
|
-
);
|
|
1824
|
-
}
|
|
1825
|
-
(_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F440} subscribe to timeline "${token.key}"`);
|
|
1826
|
-
const subscription = tl.subject.subscribe(handleUpdate);
|
|
1827
|
-
const unsubscribe = () => {
|
|
1828
|
-
var _a2;
|
|
1829
|
-
(_a2 = store.config.logger) == null ? void 0 : _a2.info(`\u{1F648} unsubscribe from timeline "${token.key}"`);
|
|
1830
|
-
subscription.unsubscribe();
|
|
1831
|
-
};
|
|
1832
|
-
return unsubscribe;
|
|
1833
|
-
};
|
|
1834
|
-
|
|
1835
|
-
// src/timeline.ts
|
|
1836
|
-
var timeline = (options) => {
|
|
1837
|
-
return timeline__INTERNAL(options);
|
|
1838
|
-
};
|
|
1839
|
-
var redo = (token) => {
|
|
1840
|
-
redo__INTERNAL(token, IMPLICIT.STORE);
|
|
1841
|
-
};
|
|
1842
|
-
var undo = (token) => {
|
|
1843
|
-
undo__INTERNAL(token, IMPLICIT.STORE);
|
|
1844
|
-
};
|
|
1845
|
-
|
|
1846
|
-
// src/transaction.ts
|
|
1847
|
-
function transaction(options) {
|
|
1848
|
-
return transaction__INTERNAL(options);
|
|
1849
|
-
}
|
|
1850
|
-
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
1851
|
-
const tx = withdraw(token, store);
|
|
1852
|
-
if (tx) {
|
|
1853
|
-
return tx.run(...parameters);
|
|
1854
|
-
}
|
|
1855
|
-
throw new Error(
|
|
1856
|
-
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
1857
|
-
);
|
|
1858
|
-
};
|
|
1859
|
-
|
|
1860
|
-
// src/index.ts
|
|
1861
|
-
var getState = (token, store = IMPLICIT.STORE) => {
|
|
1862
|
-
const state = withdraw(token, store);
|
|
1863
|
-
if (state === null) {
|
|
1864
|
-
throw new Error(
|
|
1865
|
-
`${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
|
|
1866
|
-
);
|
|
1867
|
-
}
|
|
1868
|
-
return getState__INTERNAL(state, store);
|
|
1869
|
-
};
|
|
1870
|
-
var setState = (token, value, store = IMPLICIT.STORE) => {
|
|
1871
|
-
try {
|
|
1872
|
-
openOperation(token, store);
|
|
1873
|
-
} catch (thrown) {
|
|
1874
|
-
if (!(typeof thrown === `symbol`)) {
|
|
1875
|
-
throw thrown;
|
|
1876
|
-
}
|
|
1877
|
-
return;
|
|
1878
|
-
}
|
|
1879
|
-
const state = withdraw(token, store);
|
|
1880
|
-
if (state === null) {
|
|
1881
|
-
throw new Error(
|
|
1882
|
-
`${capitalize(token.type)} "${token.key}" not found in store "${store.config.name}".`
|
|
1883
|
-
);
|
|
1884
|
-
}
|
|
1885
|
-
setState__INTERNAL(state, value, store);
|
|
1886
|
-
closeOperation(store);
|
|
1887
|
-
};
|
|
1888
|
-
var isDefault = (token, store = IMPLICIT.STORE) => token.type === `atom` ? isAtomDefault(token.key, store) : isSelectorDefault(token.key, store);
|
|
1889
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1890
|
-
0 && (module.exports = {
|
|
1891
|
-
LOG_LEVELS,
|
|
1892
|
-
__INTERNAL__,
|
|
1893
|
-
atom,
|
|
1894
|
-
atomFamily,
|
|
1895
|
-
getState,
|
|
1896
|
-
isDefault,
|
|
1897
|
-
redo,
|
|
1898
|
-
runTransaction,
|
|
1899
|
-
selector,
|
|
1900
|
-
selectorFamily,
|
|
1901
|
-
setLogLevel,
|
|
1902
|
-
setState,
|
|
1903
|
-
silo,
|
|
1904
|
-
subscribe,
|
|
1905
|
-
subscribeToTimeline,
|
|
1906
|
-
subscribeToTransaction,
|
|
1907
|
-
timeline,
|
|
1908
|
-
transaction,
|
|
1909
|
-
undo,
|
|
1910
|
-
useLogger
|
|
1911
|
-
});
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var string = require('fp-ts/string');
|
|
4
|
+
var _function = require('fp-ts/function');
|
|
5
|
+
|
|
6
|
+
var we=Object.defineProperty,ze=Object.defineProperties;var Be=Object.getOwnPropertyDescriptors;var he=Object.getOwnPropertySymbols;var He=Object.prototype.hasOwnProperty,Ye=Object.prototype.propertyIsEnumerable;var Re=(o,e,t)=>e in o?we(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,d=(o,e)=>{for(var t in e||(e={}))He.call(e,t)&&Re(o,t,e[t]);if(he)for(var t of he(e))Ye.call(e,t)&&Re(o,t,e[t]);return o},h=(o,e)=>ze(o,Be(e));var Ge=(o,e)=>{for(var t in e)we(o,t,{get:e[t],enumerable:!0});};var Ve={};Ge(Ve,{IMPLICIT:()=>l,Store:()=>E,Subject:()=>T,TRANSACTION_PHASES:()=>ot,abortTransaction:()=>te,addAtomToTimeline:()=>j,applyTransaction:()=>oe,atomFamily__INTERNAL:()=>H,atom__INTERNAL:()=>K,buildTransaction:()=>ne,cacheValue:()=>_,clearStore:()=>rt,closeOperation:()=>le,deposit:()=>w,getState__INTERNAL:()=>I,isAtomDefault:()=>F,isDone:()=>ce,isSelectorDefault:()=>fe,isValueCached:()=>ae,lookup:()=>re,lookupSelectorSources:()=>P,markAtomAsDefault:()=>ye,markAtomAsNotDefault:()=>me,markDone:()=>N,openOperation:()=>se,readCachedValue:()=>ie,readonlySelectorFamily__INTERNAL:()=>de,redoTransactionUpdate:()=>et,redo__INTERNAL:()=>U,registerSelector:()=>B,selectorFamily__INTERNAL:()=>Y,selector__INTERNAL:()=>R,setState__INTERNAL:()=>D,subscribeToRootAtoms:()=>ue,target:()=>p,timeline__INTERNAL:()=>M,traceAllSelectorAtoms:()=>z,traceSelectorAtoms:()=>X,transaction__INTERNAL:()=>C,undoTransactionUpdate:()=>tt,undo__INTERNAL:()=>V,updateSelectorAtoms:()=>pe,withdraw:()=>S});var O=class{constructor(e,t){this.relations=new Map;this.contents=new Map;this.makeContentKey=(e,t)=>`${e}:${t}`;var n,r;if(this.a=e.between[0],this.b=e.between[1],this.cardinality=e.cardinality,this.relations=new Map((n=e.relations)==null?void 0:n.map(([i,a])=>[i,new Set(a)])),this.contents=new Map(e.contents),this.isContent=(r=t==null?void 0:t.isContent)!=null?r:null,t!=null&&t.makeContentKey&&(this.makeContentKey=t.makeContentKey),t!=null&&t.externalStore){let i=t.externalStore;this.has=(a,s)=>i.has(a,s),this.addRelation=(a,s)=>(i.addRelation(a,s),this),this.deleteRelation=(a,s)=>(i.deleteRelation(a,s),this),this.getRelatedKeys=a=>i.getRelatedKeys(a),i.getContent&&(this.getContentInternal=a=>i.getContent(a),this.setContent=(a,s)=>(i.setContent(a,s),this),this.deleteContent=a=>(i.deleteContent(a),this));}}getRelatedKeys(e){return this.relations.get(e)}addRelation(e,t){let n=this.relations.get(e),r=this.relations.get(t);n?n.add(t):this.relations.set(e,new Set([t])),r?r.add(e):this.relations.set(t,new Set([e]));}deleteRelation(e,t){let n=this.relations.get(e);if(n){n.delete(t),n.size===0&&this.relations.delete(e);let r=this.relations.get(t);r&&(r.delete(e),r.size===0&&this.relations.delete(t));}}getContentInternal(e){return this.contents.get(e)}setContent(e,t){this.contents.set(e,t);}deleteContent(e){this.contents.delete(e);}toJSON(){return {between:[this.a,this.b],cardinality:this.cardinality,relations:[...this.relations.entries()].map(([e,t])=>[e,[...t]]),contents:[...this.contents.entries()]}}set(e,...t){var i;let n=typeof t[0]=="string"?t[0]:e[this.b],r=((i=t[1])!=null?i:typeof t[0]=="string")?void 0:t[0];switch(e=typeof e=="string"?e:e[this.a],this.cardinality){case"1:1":{let a=this.getRelatedKey(e);a&&a!==n&&this.delete(a,e);}case"1:n":{let a=this.getRelatedKey(n);a&&a!==e&&this.delete(a,n);}}if(this.addRelation(e,n),r){let a=this.makeContentKey(e,n);this.setContent(a,r);}return this}delete(e,t){t=typeof t=="string"?t:e[this.b];let n=typeof e=="string"?e:e[this.a];if(n===void 0&&typeof t=="string"){let r=this.getRelatedKeys(t);r&&r.forEach(i=>this.delete(i,t));}if(typeof n=="string"&&t===void 0){let r=this.getRelatedKeys(n);r&&r.forEach(i=>{this.delete(n,i);});}if(typeof n=="string"&&typeof t=="string"){this.deleteRelation(n,t);let r=this.makeContentKey(n,t);this.deleteContent(r);}return this}getRelatedKey(e){let t=this.getRelatedKeys(e);if(t)return t.size>1&&console.warn(`Multiple related keys were found for key "${e}": (${[...t].map(n=>`"${n}"`).join(", ")}). Only one related key was expected.`),[...t][0]}getContent(e,t){let n=this.makeContentKey(e,t);return this.getContentInternal(n)}getRelationEntries(e){let t=e[this.a],n=e[this.b];if(t!==void 0&&n===void 0){let r=this.getRelatedKeys(t);if(r)return [...r].map(i=>{var a;return [i,(a=this.getContent(t,i))!=null?a:null]})}if(t===void 0&&n!==void 0){let r=this.getRelatedKeys(n);if(r)return [...r].map(i=>{var a;return [i,(a=this.getContent(i,n))!=null?a:null]})}return []}has(e,t){var n;if(t){let r=this.getRelatedKeys(e);return (n=r==null?void 0:r.has(t))!=null?n:!1}return this.relations.has(e)}};var $=()=>{},v=o=>e=>o instanceof Function?o(e instanceof Function?e():e):o;var Ae=(...o)=>e=>e(...o);var Ie=o=>e=>e.map(o);var Z=(o=Boolean)=>e=>e.every(o),Oe=Z(o=>o===!0);var _e=o=>e=>e!=null?e:o;var Ee=o=>Object.assign(e=>e[o],{in:e=>e[o]});var G=o=>Object.entries(o),Ne=o=>Object.fromEntries(o);var Xe=(o,e)=>_function.pipe(o,G,Ie(([t,n])=>[t,e(n,t)]),Ne),Ke=o=>e=>Xe(e,o);var qe=o=>typeof o=="object"&&o!==null,Qe=o=>qe(o)&&Object.getPrototypeOf(o)===Object.prototype;var Ze=(o,e={allowExtraProperties:!1})=>{let t=`{${G(o).map(([r,i])=>String(r)+":"+i.name).join(",")}}`;return {[t]:r=>Qe(r)&&_function.pipe(o,Object.entries,Z(([i,a])=>i in r||a(void 0)))&&_function.pipe(r,Ke((i,a)=>_function.pipe(o,Ee(a),_e(()=>e.allowExtraProperties),Ae(i))),Object.values,Oe)}[t]};var $e=o=>Ze(o,{allowExtraProperties:!1});var T=class{constructor(){this.subscribers=new Map;}subscribe(e,t){return this.subscribers.set(e,t),()=>this.unsubscribe(e)}unsubscribe(e){this.subscribers.delete(e);}next(e){for(let t of this.subscribers.values())t(e);}};function w(o){return d({key:o.key,type:o.type},"family"in o&&{family:o.family})}var te=o=>{var e,t;if(o.transactionStatus.phase==="idle"){(e=o.config.logger)==null||e.warn("abortTransaction called outside of a transaction. This is probably a bug.");return}o.transactionStatus={phase:"idle"},(t=o.config.logger)==null||t.info("\u{1FA82}","transaction fail");};var oe=(o,e)=>{var r,i,a,s,m;if(e.transactionStatus.phase!=="building"){(r=e.config.logger)==null||r.warn("abortTransaction called outside of a transaction. This is probably a bug.");return}e.transactionStatus.phase="applying",e.transactionStatus.output=o;let{atomUpdates:t}=e.transactionStatus;(i=e.config.logger)==null||i.info(`\u{1F6C3} applying transaction "${e.transactionStatus.key}" with ${t.length} updates.`),(a=e.config.logger)==null||a.info("\u{1F6C3} the updates are:",t);for(let{key:c,newValue:f}of t){let y={key:c,type:"atom"};if(!e.valueMap.has(y.key)){let g=e.transactionStatus.core.atoms.get(y.key);if(!g)throw new Error(`Absurd Error: Atom "${y.key}" not found while copying updates from transaction "${e.transactionStatus.key}" to store "${e.config.name}"`);e.atoms.set(g.key,g),e.valueMap.set(g.key,g.default),(s=e.config.logger)==null||s.info("\u{1F527}",`add atom "${g.key}"`);}k(y,f,e);}let n=S({key:e.transactionStatus.key,type:"transaction"},e);if(n===null)throw new Error(`Transaction "${e.transactionStatus.key}" not found. Absurd. How is this running?`);n.subject.next({key:e.transactionStatus.key,atomUpdates:t,output:o,params:e.transactionStatus.params}),e.transactionStatus={phase:"idle"},(m=e.config.logger)==null||m.info("\u{1F6EC}","transaction done");};var ne=(o,e,t)=>{var n;t.transactionStatus={key:o,phase:"building",time:Date.now(),core:{atoms:new Map(t.atoms),atomsThatAreDefault:new Set(t.atomsThatAreDefault),operation:{open:!1},readonlySelectors:new Map(t.readonlySelectors),timelines:new Map(t.timelines),timelineAtoms:new O(t.timelineAtoms.toJSON()),transactions:new Map(t.transactions),selectorAtoms:new O(t.selectorAtoms.toJSON()),selectorGraph:new O(t.selectorGraph.toJSON(),{makeContentKey:(...r)=>r.sort().join(":")}),selectors:new Map(t.selectors),valueMap:new Map(t.valueMap)},atomUpdates:[],params:e,output:void 0},(n=t.config.logger)==null||n.info("\u{1F6EB}",`transaction "${o}" started in store "${t.config.name}"`);};function C(o,e=l.STORE){let t={key:o.key,type:"transaction",run:(...i)=>{var a;ne(o.key,i,e);try{let s=o.do({get:m=>W(m,e),set:(m,c)=>k(m,c,e)},...i);return oe(s,e),s}catch(s){throw te(e),(a=e.config.logger)==null||a.error(`Transaction ${o.key} failed`,s),s}},install:i=>C(o,i),subject:new T};p(e).transactions.set(t.key,t);let r=w(t);return e.subject.transactionCreation.next(r),r}var p=(o=l.STORE)=>o.transactionStatus.phase==="building"?o.transactionStatus.core:o;var et=(o,e)=>{var t;(t=e.config.logger)==null||t.info(` \u23ED redo transaction "${o.key}" (redo)`);for(let{key:n,newValue:r}of o.atomUpdates){let i={key:n,type:"atom"},a=S(i,e);if(a===null)throw new Error(`State "${i.key}" not found in this store. This is surprising, because we are navigating the history of the store.`);k(a,r,e);}};var tt=(o,e)=>{var t;(t=e.config.logger)==null||t.info(` \u23EE undo transaction "${o.key}" (undo)`);for(let{key:n,oldValue:r}of o.atomUpdates){let i={key:n,type:"atom"},a=S(i,e);if(a===null)throw new Error(`State "${i.key}" not found in this store. This is surprising, because we are navigating the history of the store.`);k(a,r,e);}};var ot=["idle","building","applying"];function re(o,e){var r;let t=p(e),n=t.atoms.has(o)?"atom":t.selectors.has(o)?"selector":t.readonlySelectors.has(o)?"readonly_selector":"";if(!n){let i=Math.random().toString(36);n=`\u{1F6A8} This state could not be found by lookup! Check the console for "${i}"`,(r=e.config.logger)==null||r.error(`${i}: Key "${o}" does not exist in the store.`);}return {key:o,type:n}}var j=(o,e,t=l.STORE)=>{let n=S(o,t);if(n===null)throw new Error(`Cannot subscribe to atom "${o.key}" because it has not been initialized in store "${t.config.name}"`);n.subject.subscribe("timeline",r=>{var c,f,y,g,x;let i=t.operation.open&&t.operation.token.type==="selector"?t.operation.token.key:null,a=t.operation.open&&t.operation.token.type==="selector"?t.operation.time:null,s=t.transactionStatus.phase==="applying"?t.transactionStatus.key:null,m=t.transactionStatus.phase==="applying"?t.transactionStatus.time:null;if((c=t.config.logger)==null||c.info(`\u23F3 timeline "${e.key}" saw atom "${o.key}" go (`,r.oldValue,"->",r.newValue,s?`) in transaction "${s}"`:i?`) in selector "${i}"`:")"),e.timeTraveling===null){if(e.selectorTime&&e.selectorTime!==a&&e.history.at(-1)===void 0)throw new Error(`Timeline "${e.key}" has a selectorTime, but no history. This is most likely a bug in AtomIO.`);if(s&&t.transactionStatus.phase==="applying"){let u=S({key:s,type:"transaction"},t);if(u===null)throw new Error(`Transaction "${s}" not found in store "${t.config.name}". This is surprising, because we are in the application phase of "${s}".`);if(e.transactionKey!==s){e.transactionKey&&((f=t.config.logger)==null||f.error(`Timeline "${e.key}" was unable to resolve transaction "${e.transactionKey}. This is probably a bug.`)),e.transactionKey=s;let b=u.subject.subscribe(`timeline:${e.key}`,A=>{var L;if(b(),e.timeTraveling===null&&m){e.at!==e.history.length&&e.history.splice(e.at);let De=A.atomUpdates.filter(ge=>{let ke=p(t).timelineAtoms.getRelatedKeys(e.key);return ke?[...ke].some(be=>{var xe;return be===ge.key||be===((xe=ge.family)==null?void 0:xe.key)}):!1}),Se=h(d({type:"transaction_update",timestamp:m},A),{atomUpdates:De});e.history.push(Se),e.at=e.history.length,e.subject.next(Se);}e.transactionKey=null,(L=t.config.logger)==null||L.info(`\u231B timeline "${e.key}" got a transaction_update "${A.key}"`);});}}else if(i&&a){let u=e.history.at(-1);a!==e.selectorTime?(u={type:"selector_update",timestamp:a,key:i,atomUpdates:[]},u.atomUpdates.push(d({key:n.key,type:"atom_update"},r)),e.at!==e.history.length&&e.history.splice(e.at),e.history.push(u),(y=t.config.logger)==null||y.info(`\u231B timeline "${e.key}" got a selector_update "${i}" with`,u.atomUpdates.map(b=>b.key)),e.at=e.history.length,e.selectorTime=a):(u==null?void 0:u.type)==="selector_update"&&(u.atomUpdates.push(d({key:n.key,type:"atom_update"},r)),(g=t.config.logger)==null||g.info(` \u231B timeline "${e.key}" set selector_update "${i}" to`,u==null?void 0:u.atomUpdates.map(b=>b.key))),u&&e.subject.next(u);}else {let u=Date.now();e.selectorTime=null,e.at!==e.history.length&&e.history.splice(e.at);let b={type:"atom_update",timestamp:u,key:n.key,oldValue:r.oldValue,newValue:r.newValue};n.family&&(b.family=n.family),e.history.push(b),e.subject.next(b),(x=t.config.logger)==null||x.info(`\u231B timeline "${e.key}" got an atom_update to "${n.key}"`),e.at=e.history.length;}}});};var U=(o,e=l.STORE)=>{var r,i,a,s;(r=e.config.logger)==null||r.info(`\u23E9 redo "${o.key}"`);let t=e.timelines.get(o.key);if(!t){(i=e.config.logger)==null||i.error(`Failed to redo on timeline "${o.key}". This timeline has not been initialized.`);return}if(t.at===t.history.length){(a=e.config.logger)==null||a.warn(`Failed to redo at the end of timeline "${o.key}". There is nothing to redo.`);return}t.timeTraveling="into_future";let n=t.history[t.at];switch(n.type){case"atom_update":{let{key:m,newValue:c}=n;k({key:m,type:"atom"},c,e);break}case"selector_update":case"transaction_update":{for(let m of n.atomUpdates){let{key:c,newValue:f}=m;k({key:c,type:"atom"},f,e);}break}}++t.at,t.subject.next("redo"),t.timeTraveling=null,(s=e.config.logger)==null||s.info(`\u23F9\uFE0F "${o.key}" is now at ${t.at} / ${t.history.length}`);},V=(o,e=l.STORE)=>{var r,i,a,s;(r=e.config.logger)==null||r.info(`\u23EA undo "${o.key}"`);let t=e.timelines.get(o.key);if(!t){(i=e.config.logger)==null||i.error(`Failed to undo on timeline "${o.key}". This timeline has not been initialized.`);return}if(t.at===0){(a=e.config.logger)==null||a.warn(`Failed to undo at the beginning of timeline "${o.key}". There is nothing to undo.`);return}t.timeTraveling="into_past",--t.at;let n=t.history[t.at];switch(n.type){case"atom_update":{let{key:m,oldValue:c}=n;k({key:m,type:"atom"},c,e);break}case"selector_update":case"transaction_update":{for(let m of [...n.atomUpdates].reverse()){let{key:c,oldValue:f}=m;k({key:c,type:"atom"},f,e);}break}}t.subject.next("undo"),t.timeTraveling=null,(s=e.config.logger)==null||s.info(`\u23F9\uFE0F "${o.key}" is now at ${t.at} / ${t.history.length}`);};function M(o,e=l.STORE,t=null){var a,s,m;let n=h(d({type:"timeline",key:o.key,at:0,timeTraveling:null,selectorTime:null,transactionKey:null},t),{history:(a=t==null?void 0:t.history.map(c=>d({},c)))!=null?a:[],install:c=>M(o,c,n),subject:new T}),r=p(e);for(let c of o.atoms){let f=r.timelineAtoms.getRelatedKey(c.key);if(f){(s=e.config.logger)==null||s.error(`\u274C Failed to add atom "${c.key}" to timeline "${o.key}" because it belongs to timeline "${f}"`);continue}if(c.type==="atom_family")c.subject.subscribe(`timeline:${o.key}`,g=>{r.atoms.has(g.key)||j(g,n,e);});else {let y=c;if("family"in y&&y.family){let g=r.timelineAtoms.getRelatedKey(y.family.key);if(g){(m=e.config.logger)==null||m.error(`\u274C Failed to add atom "${y.key}" to timeline "${o.key}" because its family "${y.family.key}" belongs to timeline "${g}"`);continue}}j(y,n,e);}r.timelineAtoms=r.timelineAtoms.set({atomKey:c.key,timelineKey:o.key});}e.timelines.set(o.key,n);let i={key:o.key,type:"timeline"};return e.subject.timelineCreation.next(i),i}function S(o,e){var r,i,a,s,m,c,f,y,g,x;let t=p(e),n=(s=(a=(i=(r=t.atoms.get(o.key))!=null?r:t.selectors.get(o.key))!=null?i:t.readonlySelectors.get(o.key))!=null?a:t.transactions.get(o.key))!=null?s:t.timelines.get(o.key);if(n)return n;if(e.transactionStatus.phase==="applying"&&(t=e.transactionStatus.core,n=(y=(f=(c=(m=t.atoms.get(o.key))!=null?m:t.selectors.get(o.key))!=null?c:t.readonlySelectors.get(o.key))!=null?f:t.transactions.get(o.key))!=null?y:t.timelines.get(o.key),n)){switch((g=e.config.logger)==null||g.info(`\u{1F6E0}\uFE0F add ${o.type} "${o.key}"`),n.type){case"atom":{e.atoms.set(o.key,n),e.valueMap.set(o.key,n.default);let u=n.key,b=(x=n.family)==null?void 0:x.key,A=t.timelineAtoms.getRelatedKey(u);A===void 0&&typeof b=="string"&&(A=t.timelineAtoms.getRelatedKey(b));let L=typeof A=="string"?e.timelines.get(A):void 0;L&&j(n,L,e);break}case"selector":t.selectors.set(o.key,n);break;case"readonly_selector":t.readonlySelectors.set(o.key,n);break;case"transaction":t.transactions.set(o.key,n);break;case"timeline":t.timelines.set(o.key,n);break}return n}return null}var E=class{constructor(e,t=null){this.valueMap=new Map;this.atoms=new Map;this.selectors=new Map;this.readonlySelectors=new Map;this.timelines=new Map;this.transactions=new Map;this.atomsThatAreDefault=new Set;this.timelineAtoms=new O({between:["timelineKey","atomKey"],cardinality:"1:n"});this.selectorAtoms=new O({between:["selectorKey","atomKey"],cardinality:"n:n"});this.selectorGraph=new O({between:["upstreamSelectorKey","downstreamSelectorKey"],cardinality:"n:n"},{isContent:$e({source:string.isString}),makeContentKey:(...e)=>e.sort().join(":")});this.subject={atomCreation:new T,selectorCreation:new T,transactionCreation:new T,timelineCreation:new T,operationStatus:new T};this.operation={open:!1};this.transactionStatus={phase:"idle"};this.config={name:"DEFAULT",logger:h(d({},console),{info:$}),logger__INTERNAL:console};var n;t!==null&&(this.valueMap=new Map(t==null?void 0:t.valueMap),this.operation=d({},t==null?void 0:t.operation),this.transactionStatus=d({},t==null?void 0:t.transactionStatus),this.config=h(d({},t==null?void 0:t.config),{logger__INTERNAL:console,logger:d(h(d({},console),{info:$}),(n=t==null?void 0:t.config)==null?void 0:n.logger),name:e})),t==null||t.atoms.forEach(r=>{let i=h(d({},r),{subject:new T});this.atoms.set(r.key,i);}),t==null||t.readonlySelectors.forEach(r=>{r.install(this);}),t==null||t.selectors.forEach(r=>{r.install(this);}),t==null||t.transactions.forEach(r=>{r.install(this);}),t==null||t.timelines.forEach(r=>{r.install(this);});}},l={STORE_INTERNAL:void 0,get STORE(){var o;return (o=this.STORE_INTERNAL)!=null?o:this.STORE_INTERNAL=new E("DEFAULT")}},rt=(o=l.STORE)=>{let{config:e}=o;Object.assign(o,new E(e.name)),o.config=e;};var _=(o,e,t=l.STORE)=>{p(t).valueMap.set(o,e);},ie=(o,e=l.STORE)=>p(e).valueMap.get(o),ae=(o,e=l.STORE)=>p(e).valueMap.has(o);var P=(o,e)=>p(e).selectorGraph.getRelationEntries({downstreamSelectorKey:o}).filter(([n,{source:r}])=>r!==o).map(([n,{source:r}])=>re(r,e));var I=(o,e=l.STORE)=>{var t,n,r;return ae(o.key,e)?((t=e.config.logger)==null||t.info(`>> read "${o.key}"`),ie(o.key,e)):o.type!=="atom"?((n=e.config.logger)==null||n.info(`-> calc "${o.key}"`),o.get()):((r=e.config.logger)==null||r.error(`Attempted to get atom "${o.key}", which was never initialized in store "${e.config.name}".`),o.default)};var se=(o,e)=>{var n,r;let t=p(e);if(t.operation.open)throw (n=e.config.logger)==null||n.error(`\u274C failed to setState to "${o.key}" during a setState for "${t.operation.token.key}"`),Symbol("violation");t.operation={open:!0,done:new Set,prev:new Map(e.valueMap),time:Date.now(),token:o},(r=e.config.logger)==null||r.info(`\u2B55 operation start from "${o.key}" in store "${e.config.name}"${e.transactionStatus.phase==="idle"?"":` ${e.transactionStatus.phase} "${e.transactionStatus.key}"`}`);},le=o=>{var t;let e=p(o);e.operation={open:!1},(t=o.config.logger)==null||t.info("\u{1F534} operation done"),o.subject.operationStatus.next(e.operation);},ce=(o,e=l.STORE)=>{var n;let t=p(e);return t.operation.open?t.operation.done.has(o):((n=e.config.logger)==null||n.warn("isDone called outside of an operation. This is probably a bug."),!0)},N=(o,e=l.STORE)=>{var n;let t=p(e);if(!t.operation.open){(n=e.config.logger)==null||n.warn("markDone called outside of an operation. This is probably a bug.");return}t.operation.done.add(o);};var ve=(o,e,t)=>{let{key:n}=o,{logger:r}=t.config;r==null||r.info(`\u{1F4E2} ${o.type} "${n}" went (`,e.oldValue,"->",e.newValue,")"),o.subject.next(e);};var Ce=(o,e=l.STORE)=>{var r,i,a,s,m,c,f;let t=p(e),n=t.selectorAtoms.getRelatedKeys(o.key);if((i=e.config.logger)==null||i.info(` || ${(r=n==null?void 0:n.size)!=null?r:"none"} downstream:`,n),t.operation.open&&((a=e.config.logger)==null||a.info(" ||",[...t.operation.done],"already done")),n)for(let y of n){if(ce(y,e)){(s=e.config.logger)==null||s.info(` || ${y} already done`);continue}if(!((m=t.selectors.get(y))!=null?m:t.readonlySelectors.get(y))){(c=e.config.logger)==null||c.info(` || ${y} was not found in selectors or readonlySelectors`);return}t.valueMap.delete(y),(f=e.config.logger)==null||f.info(` xx evicted "${y}"`),N(y,e);}};var je=(o,e,t)=>{var a;let{key:n}=o,{logger:r}=t.config;if(t.transactionStatus.phase!=="building"){(a=t.config.logger)==null||a.warn("stowUpdate called outside of a transaction. This is probably a bug.");return}let i=d({key:n},e);o.family&&(i.family=o.family),t.transactionStatus.atomUpdates.push(i),r==null||r.info(`\u{1F4DD} ${n} stowed (`,e.oldValue,"->",e.newValue,")");};var Me=(o,e,t=l.STORE)=>{var a,s;let n=I(o,t),r=v(e)(n);(a=t.config.logger)==null||a.info(`<< setting atom "${o.key}" to`,r),_(o.key,r,t),F(o.key,t)&&me(o.key,t),N(o.key,t),(s=t.config.logger)==null||s.info(` || evicting caches downstream from "${o.key}"`),Ce(o,t);let i={oldValue:n,newValue:r};t.transactionStatus.phase!=="building"?ve(o,i,t):je(o,i,t);};var Fe=(o,e,t=l.STORE)=>{var i,a;let n=I(o,t),r=v(e)(n);(i=t.config.logger)==null||i.info(`<< setting selector "${o.key}" to`,r),(a=t.config.logger)==null||a.info(` || propagating change made to "${o.key}"`),o.set(r);};var D=(o,e,t=l.STORE)=>{"set"in o?Fe(o,e,t):Me(o,e,t);};var X=(o,e,t)=>{let n=[],r=P(e.key,t),i=0;for(;r.length>0;){let a=r.shift();if(++i,i>999)throw new Error(`Maximum selector dependency depth exceeded in selector "${o}".`);a.type!=="atom"?r.push(...P(a.key,t)):n.push(a);}return n},z=(o,e)=>P(o,e).flatMap(n=>n.type==="atom"?n:X(o,n,e));var pe=(o,e,t)=>{var i,a;let n=p(t);if(e.type==="atom"){n.selectorAtoms=n.selectorAtoms.set({selectorKey:o,atomKey:e.key}),(i=t.config.logger)==null||i.info(` || adding root for "${o}": ${e.key}`);return}let r=X(o,e,t);(a=t.config.logger)==null||a.info(` || adding roots for "${o}":`,r.map(s=>s.key));for(let s of r)n.selectorAtoms=n.selectorAtoms.set({selectorKey:o,atomKey:s.key});};var B=(o,e=l.STORE)=>({get:t=>{var s,m;let n=p(e),r=n.selectorGraph.getRelationEntries({downstreamSelectorKey:o}).some(([c,{source:f}])=>f===t.key),i=S(t,e);if(i===null)throw new Error(`State "${t.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`);let a=I(i,e);return r?(s=e.config.logger)==null||s.info(` || ${o} <- ${t.key} =`,a):((m=e.config.logger)==null||m.info(`\u{1F50C} registerSelector "${o}" <- ( "${t.key}" =`,a,")"),n.selectorGraph=n.selectorGraph.set({upstreamSelectorKey:t.key,downstreamSelectorKey:o},{source:t.key})),pe(o,t,e),a},set:(t,n)=>{let r=S(t,e);if(r===null)throw new Error(`State "${t.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`);D(r,n,e);}});var Je=(o,e,t,n)=>{var g;let r=new T,{get:i,set:a}=B(o.key,t),s=()=>{let x=o.get({get:i});return _(o.key,x,t),x},m=x=>{var A;let u=s();(A=t.config.logger)==null||A.info(` <- "${o.key}" went (`,u,"->",x,")");let b=v(x)(u);_(o.key,b,t),N(o.key,t),t.transactionStatus.phase==="idle"&&r.next({newValue:b,oldValue:u}),o.set({get:i,set:a},b);},c=d(h(d({},o),{subject:r,install:x=>R(o,e,x),get:s,set:m,type:"selector"}),e&&{family:e});n.selectors.set(o.key,c);let f=s();(g=t.config.logger)==null||g.info(` \u2728 "${o.key}" =`,f);let y={key:o.key,type:"selector"};return e&&(y.family=e),t.subject.selectorCreation.next(y),y};var Le=(o,e,t,n)=>{var f;let r=new T,{get:i}=B(o.key,t),a=()=>{let y=o.get({get:i});return _(o.key,y,t),y},s=d(h(d({},o),{subject:r,install:y=>R(o,e,y),get:a,type:"readonly_selector"}),e&&{family:e});n.readonlySelectors.set(o.key,s);let m=a();(f=t.config.logger)==null||f.info(` \u2728 "${o.key}" =`,m);let c={key:o.key,type:"readonly_selector"};return e&&(c.family=e),t.subject.selectorCreation.next(c),c};function R(o,e,t=l.STORE){var r;let n=p(t);return n.selectors.has(o.key)&&((r=t.config.logger)==null||r.error(`Key "${o.key}" already exists in the store.`)),"set"in o?Je(o,e,t,n):Le(o,e,t,n)}var F=(o,e=l.STORE)=>p(e).atomsThatAreDefault.has(o),ye=(o,e=l.STORE)=>{let t=p(e);t.atomsThatAreDefault=new Set(t.atomsThatAreDefault).add(o);},me=(o,e=l.STORE)=>{let t=p(e);t.atomsThatAreDefault=new Set(p(e).atomsThatAreDefault),t.atomsThatAreDefault.delete(o);},fe=(o,e=l.STORE)=>z(o,e).every(n=>F(n.key,e));function K(o,e,t=l.STORE){var c,f,y;let n=p(t),r=n.atoms.get(o.key);if(r)return (f=(c=t.config.logger)==null?void 0:c.info)==null||f.call(c,`Key "${o.key}" already exists in the store.`),w(r);let i=new T,a=d(h(d({},o),{subject:i,type:"atom"}),e&&{family:e}),s=o.default instanceof Function?o.default():o.default;n.atoms.set(a.key,a),ye(o.key,t),_(o.key,s,t);let m=w(a);return (y=o.effects)==null||y.forEach((g,x)=>g({setSelf:u=>k(m,u,t),onSet:u=>q(m,u,`effects[${x}]`,t)})),t.subject.atomCreation.next(m),m}var J=o=>JSON.stringify(o);function H(o,e=l.STORE){let t=new T;return Object.assign(n=>{let r=J(n),i={key:o.key,subKey:r},a=`${o.key}(${r})`,s=S({key:a,type:"atom"},e),m;if(s)m=w(s);else {let c={key:a,default:o.default instanceof Function?o.default(n):o.default};o.effects&&(c.effects=o.effects(n)),m=K(c,i,e),t.next(m);}return m},{key:o.key,type:"atom_family",subject:t})}function de(o,e){let t=p(e),n=new T;return Object.assign(r=>{let i=J(r),a={key:o.key,subKey:i},s=`${o.key}(${i})`,m=t.readonlySelectors.get(s);return m?w(m):R({key:s,get:o.get(r)},a,e)},{key:o.key,type:"readonly_selector_family",subject:n})}function Y(o,e=l.STORE){if(!("set"in o))return de(o,e);let n=p(e),r=new T;return Object.assign(i=>{let a=J(i),s={key:o.key,subKey:a},m=`${o.key}(${a})`,c=n.selectors.get(m);if(c)return w(c);let f=R({key:m,get:o.get(i),set:o.set(i)},s,e);return r.next(f),f},{key:o.key,type:"selector_family"})}var Ue=(o,e=l.STORE)=>{var n;let t=p(e);return t.operation.open?t.operation.prev.get(o.key):((n=e.config.logger)==null||n.warn("recall called outside of an operation. This is probably a bug."),t.valueMap.get(o.key))};var ue=(o,e)=>"default"in o?null:z(o.key,e).map(n=>{let r=S(n,e);if(r===null)throw new Error(`Atom "${n.key}", a dependency of selector "${o.key}", not found in store "${e.config.name}".`);return r.subject.subscribe(`${o.type}:${o.key}`,i=>{var m,c;(m=e.config.logger)==null||m.info(`\u{1F4E2} selector "${o.key}" saw root "${n.key}" go (`,i.oldValue,"->",i.newValue,")");let a=Ue(o,e),s=I(o,e);(c=e.config.logger)==null||c.info(` <- "${o.key}" went (`,a,"->",s,")"),o.subject.next({newValue:s,oldValue:a});})});var Te=o=>o[0].toUpperCase()+o.slice(1);function wi(o){return K(o)}function Ai(o){return H(o)}var Q=["info","warn","error"],it=(o,e=l.STORE)=>{let{logger__INTERNAL:t}=e.config;o===null?e.config.logger=null:(e.config.logger=d({},console),Q.forEach(n=>{Q.indexOf(n)<Q.indexOf(o)?e.config.logger[n]=$:e.config.logger[n]=t[n];}));},Ei=(o,e=l.STORE)=>{var n;let t=e.config.logger===null?null:(n=Q.find(r=>{var i;return ((i=e.config.logger)==null?void 0:i[r])!==$}))!=null?n:null;e.config.logger__INTERNAL=d({},o),it(t,e);};function vi(o){return R(o)}function Ci(o){return Y(o)}var Pe=class{constructor(e,t=null){let n=new E(e,t);this.store=n,this.atom=r=>K(r,void 0,n),this.atomFamily=r=>H(r,n),this.selector=r=>R(r,void 0,n),this.selectorFamily=r=>Y(r,n),this.transaction=r=>C(r,n),this.timeline=r=>M(r,n),this.getState=r=>W(r,n),this.setState=(r,i)=>k(r,i,n),this.subscribe=(r,i,a)=>q(r,i,a,n),this.undo=r=>V(r,n),this.redo=r=>U(r,n);}};var q=(o,e,t=Math.random().toString(36).slice(2),n=l.STORE)=>{var m;let r=S(o,n);if(r===null)throw new Error(`State "${o.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`);let i=r.subject.subscribe(t,e);(m=n.config.logger)==null||m.info(`\u{1F440} subscribe to "${r.key}"`);let a=r.type!=="atom"?ue(r,n):null;return a===null?()=>{var c;(c=n.config.logger)==null||c.info(`\u{1F648} unsubscribe from "${r.key}"`),i();}:()=>{var c;(c=n.config.logger)==null||c.info(`\u{1F648} unsubscribe from "${r.key}" and its dependencies`),i();for(let f of a)f();}},Ui=(o,e,t=Math.random().toString(36).slice(2),n=l.STORE)=>{var a;let r=S(o,n);if(r===null)throw new Error(`Cannot subscribe to transaction "${o.key}": transaction not found in store "${n.config.name}".`);(a=n.config.logger)==null||a.info(`\u{1F440} subscribe to transaction "${o.key}"`);let i=r.subject.subscribe(t,e);return ()=>{var s;(s=n.config.logger)==null||s.info(`\u{1F648} unsubscribe from transaction "${o.key}"`),i();}},Vi=(o,e,t=Math.random().toString(36).slice(2),n=l.STORE)=>{var a;let r=S(o,n);if(r===null)throw new Error(`Cannot subscribe to timeline "${o.key}": timeline not found in store "${n.config.name}".`);(a=n.config.logger)==null||a.info(`\u{1F440} subscribe to timeline "${o.key}"`);let i=r.subject.subscribe(t,e);return ()=>{var s;(s=n.config.logger)==null||s.info(`\u{1F648} unsubscribe from timeline "${o.key}"`),i();}};var Bi=o=>M(o),Hi=o=>{U(o,l.STORE);},Yi=o=>{V(o,l.STORE);};function Xi(o){return C(o)}var qi=(o,e=l.STORE)=>(...t)=>{let n=S(o,e);if(n)return n.run(...t);throw new Error(`Cannot run transaction "${o.key}": transaction not found in store "${e.config.name}".`)};var W=(o,e=l.STORE)=>{let t=S(o,e);if(t===null)throw new Error(`${Te(o.type)} "${o.key}" not found in store "${e.config.name}".`);return I(t,e)},k=(o,e,t=l.STORE)=>{try{se(o,t);}catch(r){if(typeof r!="symbol")throw r;return}let n=S(o,t);if(n===null)throw new Error(`${Te(o.type)} "${o.key}" not found in store "${t.config.name}".`);D(n,e,t),le(t);},ta=(o,e=l.STORE)=>o.type==="atom"?F(o.key,e):fe(o.key,e);
|
|
7
|
+
|
|
8
|
+
exports.LOG_LEVELS = Q;
|
|
9
|
+
exports.Silo = Pe;
|
|
10
|
+
exports.__INTERNAL__ = Ve;
|
|
11
|
+
exports.atom = wi;
|
|
12
|
+
exports.atomFamily = Ai;
|
|
13
|
+
exports.getState = W;
|
|
14
|
+
exports.isDefault = ta;
|
|
15
|
+
exports.redo = Hi;
|
|
16
|
+
exports.runTransaction = qi;
|
|
17
|
+
exports.selector = vi;
|
|
18
|
+
exports.selectorFamily = Ci;
|
|
19
|
+
exports.setLogLevel = it;
|
|
20
|
+
exports.setState = k;
|
|
21
|
+
exports.subscribe = q;
|
|
22
|
+
exports.subscribeToTimeline = Vi;
|
|
23
|
+
exports.subscribeToTransaction = Ui;
|
|
24
|
+
exports.timeline = Bi;
|
|
25
|
+
exports.transaction = Xi;
|
|
26
|
+
exports.undo = Yi;
|
|
27
|
+
exports.useLogger = Ei;
|
|
28
|
+
//# sourceMappingURL=out.js.map
|
|
1912
29
|
//# sourceMappingURL=index.js.map
|