atom.io 0.14.4 → 0.14.6
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/data/dist/index.cjs +47 -1416
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +16 -317
- package/data/dist/index.d.ts +16 -317
- package/data/dist/index.js +4 -6
- package/data/dist/index.js.map +1 -1
- package/dist/chunk-NYTGCPHB.js +261 -0
- package/dist/chunk-NYTGCPHB.js.map +1 -0
- package/dist/chunk-PZLG2HP3.js +36 -0
- package/dist/chunk-PZLG2HP3.js.map +1 -0
- package/dist/chunk-XACXFU3B.js +46 -0
- package/dist/chunk-XACXFU3B.js.map +1 -0
- package/dist/index.cjs +55 -2330
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -269
- package/dist/index.d.ts +21 -269
- package/dist/index.js +152 -1
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/dist/metafile-esm.json +1 -1
- package/internal/dist/index.cjs +30 -159
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +28 -229
- package/internal/dist/index.d.ts +28 -229
- package/internal/dist/index.js +2027 -1
- package/internal/dist/index.js.map +1 -1
- package/introspection/dist/index.cjs +45 -1565
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +4 -376
- package/introspection/dist/index.d.ts +4 -376
- package/introspection/dist/index.js +298 -2
- package/introspection/dist/index.js.map +1 -1
- package/json/dist/index.cjs +5 -1502
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +7 -373
- package/json/dist/index.d.ts +7 -373
- package/json/dist/index.js +37 -1
- package/json/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/react/dist/index.cjs +14 -1549
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +4 -377
- package/react/dist/index.d.ts +4 -377
- package/react/dist/index.js +62 -2
- package/react/dist/index.js.map +1 -1
- package/react-devtools/dist/index.cjs +135 -2153
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.cts +24 -149
- package/react-devtools/dist/index.d.ts +24 -149
- package/react-devtools/dist/index.js +5 -3
- package/react-devtools/dist/index.js.map +1 -1
- package/realtime-client/dist/index.cjs +34 -1529
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +12 -384
- package/realtime-client/dist/index.d.ts +12 -384
- package/realtime-client/dist/index.js +165 -2
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-react/dist/index.cjs +35 -1727
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.cts +9 -49
- package/realtime-react/dist/index.d.ts +9 -49
- package/realtime-react/dist/index.js +66 -4
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-server/dist/index.cjs +57 -1548
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +11 -394
- package/realtime-server/dist/index.d.ts +11 -394
- package/realtime-server/dist/index.js +21 -27
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-testing/dist/index.cjs +15 -2376
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +3 -489
- package/realtime-testing/dist/index.d.ts +3 -489
- package/realtime-testing/dist/index.js +10 -9
- package/realtime-testing/dist/index.js.map +1 -1
- package/transceivers/set-rtx/dist/index.cjs +9 -31
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.d.cts +3 -29
- package/transceivers/set-rtx/dist/index.d.ts +3 -29
- package/transceivers/set-rtx/dist/index.js +3 -2
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/dist/chunk-GMN5KH6A.js +0 -309
- package/dist/chunk-GMN5KH6A.js.map +0 -1
- package/dist/chunk-HQWWV67P.js +0 -62
- package/dist/chunk-HQWWV67P.js.map +0 -1
- package/dist/chunk-MK4OJD24.js +0 -67
- package/dist/chunk-MK4OJD24.js.map +0 -1
- package/dist/chunk-N7ADBQJG.js +0 -176
- package/dist/chunk-N7ADBQJG.js.map +0 -1
- package/dist/chunk-PURABO5G.js +0 -2581
- package/dist/chunk-PURABO5G.js.map +0 -1
package/data/dist/index.cjs
CHANGED
|
@@ -1,498 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var internal = require('atom.io/internal');
|
|
4
|
+
var atom_io = require('atom.io');
|
|
3
5
|
var setRtx = require('atom.io/transceivers/set-rtx');
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
-
var __spreadValues = (a, b) => {
|
|
13
|
-
for (var prop in b || (b = {}))
|
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
if (__getOwnPropSymbols)
|
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
-
if (__propIsEnum.call(b, prop))
|
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
|
20
|
-
}
|
|
21
|
-
return a;
|
|
22
|
-
};
|
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
-
|
|
25
|
-
// src/get-state.ts
|
|
26
|
-
function getState(token, store = IMPLICIT.STORE) {
|
|
27
|
-
var _a;
|
|
28
|
-
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
29
|
-
if (state === void 0) {
|
|
30
|
-
throw new NotFoundError(token, store);
|
|
31
|
-
}
|
|
32
|
-
return readOrComputeValue(state, store);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// src/logger.ts
|
|
36
|
-
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
37
|
-
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
38
|
-
};
|
|
39
|
-
var simpleLogger = {
|
|
40
|
-
error: simpleLog(`error`),
|
|
41
|
-
info: simpleLog(`info`),
|
|
42
|
-
warn: simpleLog(`warn`)
|
|
43
|
-
};
|
|
44
|
-
var AtomIOLogger = class {
|
|
45
|
-
constructor(logLevel, filter, logger = simpleLogger) {
|
|
46
|
-
this.logLevel = logLevel;
|
|
47
|
-
this.filter = filter;
|
|
48
|
-
this.logger = logger;
|
|
49
|
-
this.error = (...args) => {
|
|
50
|
-
var _a, _b;
|
|
51
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
52
|
-
this.logger.error(...args);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
this.info = (...args) => {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
58
|
-
this.logger.info(...args);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
this.warn = (...args) => {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
64
|
-
this.logger.warn(...args);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// src/set-state.ts
|
|
71
|
-
function setState(token, value, store = IMPLICIT.STORE) {
|
|
72
|
-
var _a;
|
|
73
|
-
const rejection = openOperation(token, store);
|
|
74
|
-
if (rejection) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
78
|
-
if (state === void 0) {
|
|
79
|
-
throw new NotFoundError(token, store);
|
|
80
|
-
}
|
|
81
|
-
setAtomOrSelector(state, value, store);
|
|
82
|
-
closeOperation(store);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// internal/src/future.ts
|
|
86
|
-
var Future = class extends Promise {
|
|
87
|
-
constructor(executor) {
|
|
88
|
-
super((resolve, reject) => {
|
|
89
|
-
const pass = (value) => this.isCanceled ? reject(`canceled`) : resolve(value);
|
|
90
|
-
const fail = (reason) => this.isCanceled ? reject(`canceled`) : reject(reason);
|
|
91
|
-
if (typeof executor === `function`) {
|
|
92
|
-
executor(pass, fail);
|
|
93
|
-
} else {
|
|
94
|
-
executor.then(pass, fail);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
this.isCanceled = false;
|
|
98
|
-
}
|
|
99
|
-
cancel() {
|
|
100
|
-
this.isCanceled = true;
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
// internal/src/lineage.ts
|
|
105
|
-
function newest(scion) {
|
|
106
|
-
while (scion.child !== null) {
|
|
107
|
-
scion = scion.child;
|
|
108
|
-
}
|
|
109
|
-
return scion;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// internal/src/caching.ts
|
|
113
|
-
function cacheValue(key, value, subject, store) {
|
|
114
|
-
const target = newest(store);
|
|
115
|
-
const currentValue = target.valueMap.get(key);
|
|
116
|
-
if (currentValue instanceof Future) {
|
|
117
|
-
currentValue.cancel();
|
|
118
|
-
}
|
|
119
|
-
if (value instanceof Promise) {
|
|
120
|
-
const future = new Future(value);
|
|
121
|
-
newest(store).valueMap.set(key, future);
|
|
122
|
-
future.then((resolved) => {
|
|
123
|
-
if (future.isCanceled) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
cacheValue(key, resolved, subject, store);
|
|
127
|
-
subject.next({ newValue: resolved, oldValue: future });
|
|
128
|
-
}).catch((thrown) => {
|
|
129
|
-
if (thrown !== `canceled`) {
|
|
130
|
-
store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
return future;
|
|
134
|
-
}
|
|
135
|
-
target.valueMap.set(key, value);
|
|
136
|
-
return value;
|
|
137
|
-
}
|
|
138
|
-
var readCachedValue = (key, store) => {
|
|
139
|
-
return newest(store).valueMap.get(key);
|
|
140
|
-
};
|
|
141
|
-
var isValueCached = (key, store) => {
|
|
142
|
-
return newest(store).valueMap.has(key);
|
|
143
|
-
};
|
|
144
|
-
var evictCachedValue = (key, store) => {
|
|
145
|
-
const core = newest(store);
|
|
146
|
-
const currentValue = core.valueMap.get(key);
|
|
147
|
-
if (currentValue instanceof Future) {
|
|
148
|
-
currentValue.cancel();
|
|
149
|
-
}
|
|
150
|
-
if (core.operation.open) {
|
|
151
|
-
core.operation.prev.set(key, currentValue);
|
|
152
|
-
}
|
|
153
|
-
core.valueMap.delete(key);
|
|
154
|
-
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
// ../anvl/src/json/index.ts
|
|
158
|
-
var parseJson = (str) => JSON.parse(str);
|
|
159
|
-
var stringifyJson = (json) => JSON.stringify(json);
|
|
160
|
-
|
|
161
|
-
// json/src/select-json.ts
|
|
162
|
-
var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
|
|
163
|
-
return createSelector(
|
|
7
|
+
// data/src/dict.ts
|
|
8
|
+
function dict(findState, index, store = internal.IMPLICIT.STORE) {
|
|
9
|
+
return internal.createSelector(
|
|
164
10
|
{
|
|
165
|
-
key: `${
|
|
166
|
-
get: ({ get }) =>
|
|
167
|
-
|
|
11
|
+
key: `${findState.key}Dict`,
|
|
12
|
+
get: ({ get }) => {
|
|
13
|
+
const keys = get(index);
|
|
14
|
+
return keys.reduce((acc, key) => {
|
|
15
|
+
acc[key] = get(findState(key));
|
|
16
|
+
return acc;
|
|
17
|
+
}, {});
|
|
18
|
+
}
|
|
168
19
|
},
|
|
169
20
|
void 0,
|
|
170
21
|
store
|
|
171
22
|
);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// json/src/select-json-family.ts
|
|
175
|
-
var selectJsonFamily = (atomFamily, transform, store = IMPLICIT.STORE) => {
|
|
176
|
-
const jsonFamily = createSelectorFamily(
|
|
177
|
-
{
|
|
178
|
-
key: `${atomFamily.key}:JSON`,
|
|
179
|
-
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
180
|
-
set: (key) => ({ set }, newValue) => set(atomFamily(key), transform.fromJson(newValue))
|
|
181
|
-
},
|
|
182
|
-
store
|
|
183
|
-
);
|
|
184
|
-
atomFamily.subject.subscribe(
|
|
185
|
-
`store=${store.config.name}::json-selector-family`,
|
|
186
|
-
(token) => {
|
|
187
|
-
if (token.family) {
|
|
188
|
-
jsonFamily(parseJson(token.family.subKey));
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
);
|
|
192
|
-
return jsonFamily;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// internal/src/read-or-compute-value.ts
|
|
196
|
-
var readOrComputeValue = (state, store) => {
|
|
197
|
-
if (isValueCached(state.key, store)) {
|
|
198
|
-
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
199
|
-
return readCachedValue(state.key, store);
|
|
200
|
-
}
|
|
201
|
-
if (state.type !== `atom`) {
|
|
202
|
-
store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
|
|
203
|
-
return state.get();
|
|
204
|
-
}
|
|
205
|
-
const fallback = state.default instanceof Function ? state.default() : state.default;
|
|
206
|
-
store.logger.info(
|
|
207
|
-
`\u{1F481}`,
|
|
208
|
-
`atom`,
|
|
209
|
-
state.key,
|
|
210
|
-
`could not find cached value; using default`,
|
|
211
|
-
fallback
|
|
212
|
-
);
|
|
213
|
-
return state.default instanceof Function ? state.default() : state.default;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
// internal/src/operation.ts
|
|
217
|
-
var openOperation = (token, store) => {
|
|
218
|
-
const target = newest(store);
|
|
219
|
-
if (target.operation.open) {
|
|
220
|
-
store.logger.error(
|
|
221
|
-
`\u274C`,
|
|
222
|
-
token.type,
|
|
223
|
-
token.key,
|
|
224
|
-
`failed to setState during a setState for "${target.operation.token.key}"`
|
|
225
|
-
);
|
|
226
|
-
return `rejection`;
|
|
227
|
-
}
|
|
228
|
-
target.operation = {
|
|
229
|
-
open: true,
|
|
230
|
-
done: /* @__PURE__ */ new Set(),
|
|
231
|
-
prev: /* @__PURE__ */ new Map(),
|
|
232
|
-
time: Date.now(),
|
|
233
|
-
token
|
|
234
|
-
};
|
|
235
|
-
store.logger.info(
|
|
236
|
-
`\u2B55`,
|
|
237
|
-
token.type,
|
|
238
|
-
token.key,
|
|
239
|
-
`operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
|
|
240
|
-
);
|
|
241
|
-
};
|
|
242
|
-
var closeOperation = (store) => {
|
|
243
|
-
const target = newest(store);
|
|
244
|
-
if (target.operation.open) {
|
|
245
|
-
store.logger.info(
|
|
246
|
-
`\u{1F534}`,
|
|
247
|
-
target.operation.token.type,
|
|
248
|
-
target.operation.token.key,
|
|
249
|
-
`operation done in store "${store.config.name}"`
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
target.operation = { open: false };
|
|
253
|
-
store.subject.operationStatus.next(target.operation);
|
|
254
|
-
};
|
|
255
|
-
var isDone = (key, store) => {
|
|
256
|
-
const target = newest(store);
|
|
257
|
-
if (!target.operation.open) {
|
|
258
|
-
store.logger.warn(
|
|
259
|
-
`\u{1F41E}`,
|
|
260
|
-
`unknown`,
|
|
261
|
-
key,
|
|
262
|
-
`isDone called outside of an operation. This is probably a bug.`
|
|
263
|
-
);
|
|
264
|
-
return true;
|
|
265
|
-
}
|
|
266
|
-
return target.operation.done.has(key);
|
|
267
|
-
};
|
|
268
|
-
var markDone = (key, store) => {
|
|
269
|
-
const target = newest(store);
|
|
270
|
-
if (!target.operation.open) {
|
|
271
|
-
store.logger.warn(
|
|
272
|
-
`\u{1F41E}`,
|
|
273
|
-
`unknown`,
|
|
274
|
-
key,
|
|
275
|
-
`markDone called outside of an operation. This is probably a bug.`
|
|
276
|
-
);
|
|
277
|
-
return;
|
|
278
|
-
}
|
|
279
|
-
target.operation.done.add(key);
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// internal/src/set-state/become.ts
|
|
283
|
-
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
284
|
-
originalThing instanceof Function ? originalThing() : originalThing
|
|
285
|
-
) : nextVersionOfThing;
|
|
286
|
-
|
|
287
|
-
// internal/src/subject.ts
|
|
288
|
-
var Subject = class {
|
|
289
|
-
constructor() {
|
|
290
|
-
this.subscribers = /* @__PURE__ */ new Map();
|
|
291
|
-
}
|
|
292
|
-
subscribe(key, subscriber) {
|
|
293
|
-
this.subscribers.set(key, subscriber);
|
|
294
|
-
const unsubscribe = () => this.unsubscribe(key);
|
|
295
|
-
return unsubscribe;
|
|
296
|
-
}
|
|
297
|
-
unsubscribe(key) {
|
|
298
|
-
this.subscribers.delete(key);
|
|
299
|
-
}
|
|
300
|
-
next(value) {
|
|
301
|
-
const subscribers = this.subscribers.values();
|
|
302
|
-
for (const subscriber of subscribers) {
|
|
303
|
-
subscriber(value);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
var StatefulSubject = class extends Subject {
|
|
308
|
-
constructor(initialState) {
|
|
309
|
-
super();
|
|
310
|
-
this.state = initialState;
|
|
311
|
-
}
|
|
312
|
-
next(value) {
|
|
313
|
-
this.state = value;
|
|
314
|
-
super.next(value);
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
319
|
-
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
320
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
321
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
322
|
-
if (originValue === targetValue) {
|
|
323
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
324
|
-
const jsonValue = transform.toJson(originValue);
|
|
325
|
-
const copiedValue = transform.fromJson(jsonValue);
|
|
326
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
327
|
-
new Tracker(atom, origin);
|
|
328
|
-
return copiedValue;
|
|
329
|
-
}
|
|
330
|
-
return targetValue;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
334
|
-
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
335
|
-
const target = newest(store);
|
|
336
|
-
const parent = target.parent;
|
|
337
|
-
if (parent !== null) {
|
|
338
|
-
if (`toJson` in atom && `fromJson` in atom) {
|
|
339
|
-
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
340
|
-
return copiedValue;
|
|
341
|
-
}
|
|
342
|
-
if (`family` in atom) {
|
|
343
|
-
const family = parent.families.get(atom.family.key);
|
|
344
|
-
if (family && family.type === `atom_family`) {
|
|
345
|
-
const result = copyMutableFamilyMemberWithinTransaction(
|
|
346
|
-
atom,
|
|
347
|
-
family,
|
|
348
|
-
parent,
|
|
349
|
-
target
|
|
350
|
-
);
|
|
351
|
-
if (result) {
|
|
352
|
-
return result;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return oldValue;
|
|
358
|
-
}
|
|
359
|
-
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
360
|
-
if (`toJson` in family && `fromJson` in family) {
|
|
361
|
-
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
362
|
-
return copyCreated;
|
|
363
|
-
}
|
|
364
|
-
return null;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// internal/src/set-state/emit-update.ts
|
|
368
|
-
var emitUpdate = (state, update, store) => {
|
|
369
|
-
store.logger.info(
|
|
370
|
-
`\u{1F4E2}`,
|
|
371
|
-
state.type,
|
|
372
|
-
state.key,
|
|
373
|
-
`went (`,
|
|
374
|
-
update.oldValue,
|
|
375
|
-
`->`,
|
|
376
|
-
update.newValue,
|
|
377
|
-
`) subscribers:`,
|
|
378
|
-
state.subject.subscribers
|
|
379
|
-
);
|
|
380
|
-
state.subject.next(update);
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
// internal/src/set-state/evict-downstream.ts
|
|
384
|
-
var evictDownStream = (atom, store) => {
|
|
385
|
-
const target = newest(store);
|
|
386
|
-
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
|
|
387
|
-
store.logger.info(
|
|
388
|
-
`\u{1F9F9}`,
|
|
389
|
-
atom.type,
|
|
390
|
-
atom.key,
|
|
391
|
-
downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
|
|
392
|
-
downstreamKeys != null ? downstreamKeys : `to evict`
|
|
393
|
-
);
|
|
394
|
-
if (downstreamKeys) {
|
|
395
|
-
if (target.operation.open) {
|
|
396
|
-
store.logger.info(
|
|
397
|
-
`\u{1F9F9}`,
|
|
398
|
-
atom.type,
|
|
399
|
-
atom.key,
|
|
400
|
-
`[ ${[...target.operation.done].join(`, `)} ] already done`
|
|
401
|
-
);
|
|
402
|
-
}
|
|
403
|
-
for (const key of downstreamKeys) {
|
|
404
|
-
if (isDone(key, store)) {
|
|
405
|
-
continue;
|
|
406
|
-
}
|
|
407
|
-
evictCachedValue(key, store);
|
|
408
|
-
markDone(key, store);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
// internal/src/set-state/stow-update.ts
|
|
414
|
-
function shouldUpdateBeStowed(key, update) {
|
|
415
|
-
if (isTransceiver(update.newValue)) {
|
|
416
|
-
return false;
|
|
417
|
-
}
|
|
418
|
-
if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
419
|
-
return false;
|
|
420
|
-
}
|
|
421
|
-
return true;
|
|
422
|
-
}
|
|
423
|
-
var stowUpdate = (state, update, store) => {
|
|
424
|
-
const { key } = state;
|
|
425
|
-
const target = newest(store);
|
|
426
|
-
if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
|
|
427
|
-
store.logger.error(
|
|
428
|
-
`\u{1F41E}`,
|
|
429
|
-
`atom`,
|
|
430
|
-
key,
|
|
431
|
-
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
432
|
-
);
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
const shouldStow = shouldUpdateBeStowed(key, update);
|
|
436
|
-
if (!shouldStow) {
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
const atomUpdate = __spreadValues({ key }, update);
|
|
440
|
-
if (state.family) {
|
|
441
|
-
atomUpdate.family = state.family;
|
|
442
|
-
}
|
|
443
|
-
target.transactionMeta.update.updates.push(atomUpdate);
|
|
444
|
-
store.logger.info(
|
|
445
|
-
`\u{1F4C1}`,
|
|
446
|
-
`atom`,
|
|
447
|
-
key,
|
|
448
|
-
`stowed (`,
|
|
449
|
-
update.oldValue,
|
|
450
|
-
`->`,
|
|
451
|
-
update.newValue,
|
|
452
|
-
`)`
|
|
453
|
-
);
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
// internal/src/set-state/set-atom.ts
|
|
457
|
-
var setAtom = (atom, next, store) => {
|
|
458
|
-
const target = newest(store);
|
|
459
|
-
const oldValue = readOrComputeValue(atom, store);
|
|
460
|
-
let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
|
|
461
|
-
newValue = become(next)(newValue);
|
|
462
|
-
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
463
|
-
newValue = cacheValue(atom.key, newValue, atom.subject, store);
|
|
464
|
-
if (isAtomDefault(atom.key, store)) {
|
|
465
|
-
markAtomAsNotDefault(atom.key, store);
|
|
466
|
-
}
|
|
467
|
-
markDone(atom.key, store);
|
|
468
|
-
evictDownStream(atom, store);
|
|
469
|
-
const update = { oldValue, newValue };
|
|
470
|
-
if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
|
|
471
|
-
emitUpdate(atom, update, store);
|
|
472
|
-
} else {
|
|
473
|
-
stowUpdate(atom, update, store);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
// internal/src/set-state/set-atom-or-selector.ts
|
|
478
|
-
var setAtomOrSelector = (state, value, store) => {
|
|
479
|
-
if (state.type === `selector`) {
|
|
480
|
-
state.set(value);
|
|
481
|
-
} else {
|
|
482
|
-
setAtom(state, value, store);
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
// internal/src/store/deposit.ts
|
|
487
|
-
function deposit(state) {
|
|
488
|
-
const token = {
|
|
489
|
-
key: state.key,
|
|
490
|
-
type: state.type
|
|
491
|
-
};
|
|
492
|
-
if (`family` in state) {
|
|
493
|
-
token.family = state.family;
|
|
494
|
-
}
|
|
495
|
-
return token;
|
|
496
23
|
}
|
|
497
24
|
|
|
498
25
|
// ../rel8/junction/src/junction.ts
|
|
@@ -753,907 +280,15 @@ var Junction = class {
|
|
|
753
280
|
}
|
|
754
281
|
};
|
|
755
282
|
|
|
756
|
-
//
|
|
757
|
-
var
|
|
758
|
-
|
|
759
|
-
this.parent = null;
|
|
760
|
-
this.child = null;
|
|
761
|
-
this.valueMap = /* @__PURE__ */ new Map();
|
|
762
|
-
this.atoms = /* @__PURE__ */ new Map();
|
|
763
|
-
this.selectors = /* @__PURE__ */ new Map();
|
|
764
|
-
this.readonlySelectors = /* @__PURE__ */ new Map();
|
|
765
|
-
this.trackers = /* @__PURE__ */ new Map();
|
|
766
|
-
this.families = /* @__PURE__ */ new Map();
|
|
767
|
-
this.timelines = /* @__PURE__ */ new Map();
|
|
768
|
-
this.transactions = /* @__PURE__ */ new Map();
|
|
769
|
-
this.atomsThatAreDefault = /* @__PURE__ */ new Set();
|
|
770
|
-
this.timelineAtoms = new Junction({
|
|
771
|
-
between: [`timelineKey`, `atomKey`],
|
|
772
|
-
cardinality: `1:n`
|
|
773
|
-
});
|
|
774
|
-
this.selectorAtoms = new Junction({
|
|
775
|
-
between: [`selectorKey`, `atomKey`],
|
|
776
|
-
cardinality: `n:n`
|
|
777
|
-
});
|
|
778
|
-
this.selectorGraph = new Junction(
|
|
779
|
-
{
|
|
780
|
-
between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
|
|
781
|
-
cardinality: `n:n`
|
|
782
|
-
},
|
|
783
|
-
{
|
|
784
|
-
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
785
|
-
}
|
|
786
|
-
);
|
|
787
|
-
this.subject = {
|
|
788
|
-
atomCreation: new Subject(),
|
|
789
|
-
selectorCreation: new Subject(),
|
|
790
|
-
transactionCreation: new Subject(),
|
|
791
|
-
timelineCreation: new Subject(),
|
|
792
|
-
transactionApplying: new StatefulSubject(null),
|
|
793
|
-
operationStatus: new Subject()
|
|
794
|
-
};
|
|
795
|
-
this.operation = { open: false };
|
|
796
|
-
this.transactionMeta = null;
|
|
797
|
-
this.config = {
|
|
798
|
-
name: `IMPLICIT_STORE`
|
|
799
|
-
};
|
|
800
|
-
this.loggers = [
|
|
801
|
-
new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
802
|
-
];
|
|
803
|
-
this.logger = {
|
|
804
|
-
error: (...messages) => {
|
|
805
|
-
for (const logger of this.loggers)
|
|
806
|
-
logger.error(...messages);
|
|
807
|
-
},
|
|
808
|
-
info: (...messages) => {
|
|
809
|
-
for (const logger of this.loggers)
|
|
810
|
-
logger.info(...messages);
|
|
811
|
-
},
|
|
812
|
-
warn: (...messages) => {
|
|
813
|
-
for (const logger of this.loggers)
|
|
814
|
-
logger.warn(...messages);
|
|
815
|
-
}
|
|
816
|
-
};
|
|
817
|
-
if (store !== null) {
|
|
818
|
-
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
819
|
-
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
820
|
-
this.transactionMeta = (store == null ? void 0 : store.transactionMeta) ? __spreadValues({}, store == null ? void 0 : store.transactionMeta) : null;
|
|
821
|
-
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
822
|
-
name
|
|
823
|
-
});
|
|
824
|
-
for (const [, atom] of store.atoms) {
|
|
825
|
-
atom.install(this);
|
|
826
|
-
}
|
|
827
|
-
for (const [, selector] of store.readonlySelectors) {
|
|
828
|
-
selector.install(this);
|
|
829
|
-
}
|
|
830
|
-
for (const [, selector] of store.selectors) {
|
|
831
|
-
selector.install(this);
|
|
832
|
-
}
|
|
833
|
-
for (const [, tx] of store.transactions) {
|
|
834
|
-
tx.install(this);
|
|
835
|
-
}
|
|
836
|
-
for (const [, timeline] of store.timelines) {
|
|
837
|
-
timeline.install(this);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
var IMPLICIT = {
|
|
843
|
-
STORE_INTERNAL: void 0,
|
|
844
|
-
get STORE() {
|
|
845
|
-
var _a;
|
|
846
|
-
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
|
|
847
|
-
}
|
|
848
|
-
};
|
|
849
|
-
|
|
850
|
-
// internal/src/store/withdraw.ts
|
|
851
|
-
function withdraw(token, store) {
|
|
852
|
-
var _a, _b, _c, _d;
|
|
853
|
-
const target = newest(store);
|
|
854
|
-
const state = (_d = (_c = (_b = (_a = target.atoms.get(token.key)) != null ? _a : target.selectors.get(token.key)) != null ? _b : target.readonlySelectors.get(token.key)) != null ? _c : target.transactions.get(token.key)) != null ? _d : target.timelines.get(token.key);
|
|
855
|
-
if (state) {
|
|
856
|
-
return state;
|
|
857
|
-
}
|
|
858
|
-
return void 0;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
|
-
// internal/src/store/withdraw-new-family-member.ts
|
|
862
|
-
function withdrawNewFamilyMember(token, store) {
|
|
863
|
-
if (token.family) {
|
|
864
|
-
store.logger.info(
|
|
865
|
-
`\u{1F46A}`,
|
|
866
|
-
token.type,
|
|
867
|
-
token.key,
|
|
868
|
-
`creating new family member in store "${store.config.name}"`
|
|
869
|
-
);
|
|
870
|
-
const target = newest(store);
|
|
871
|
-
const family = target.families.get(token.family.key);
|
|
872
|
-
if (family) {
|
|
873
|
-
const jsonSubKey = JSON.parse(token.family.subKey);
|
|
874
|
-
family(jsonSubKey);
|
|
875
|
-
const state = withdraw(token, store);
|
|
876
|
-
return state;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
return void 0;
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
// internal/src/keys.ts
|
|
883
|
-
var isAtomKey = (key, store) => newest(store).atoms.has(key);
|
|
884
|
-
var isSelectorKey = (key, store) => newest(store).selectors.has(key);
|
|
885
|
-
var isReadonlySelectorKey = (key, store) => newest(store).readonlySelectors.has(key);
|
|
886
|
-
var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
|
|
887
|
-
|
|
888
|
-
// internal/src/selector/get-selector-dependency-keys.ts
|
|
889
|
-
var getSelectorDependencyKeys = (key, store) => {
|
|
890
|
-
const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
|
|
891
|
-
return sources;
|
|
892
|
-
};
|
|
893
|
-
|
|
894
|
-
// internal/src/selector/trace-selector-atoms.ts
|
|
895
|
-
var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
|
|
896
|
-
const rootKeys = [];
|
|
897
|
-
const indirectDependencyKeys = getSelectorDependencyKeys(
|
|
898
|
-
directDependencyKey,
|
|
899
|
-
store
|
|
900
|
-
);
|
|
901
|
-
let depth = 0;
|
|
902
|
-
while (indirectDependencyKeys.length > 0) {
|
|
903
|
-
const indirectDependencyKey = indirectDependencyKeys.shift();
|
|
904
|
-
++depth;
|
|
905
|
-
if (depth > 99999) {
|
|
906
|
-
throw new Error(
|
|
907
|
-
`Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
|
|
908
|
-
);
|
|
909
|
-
}
|
|
910
|
-
if (!isAtomKey(indirectDependencyKey, store)) {
|
|
911
|
-
indirectDependencyKeys.push(
|
|
912
|
-
...getSelectorDependencyKeys(indirectDependencyKey, store)
|
|
913
|
-
);
|
|
914
|
-
} else if (!rootKeys.includes(indirectDependencyKey)) {
|
|
915
|
-
rootKeys.push(indirectDependencyKey);
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
return rootKeys;
|
|
919
|
-
};
|
|
920
|
-
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
921
|
-
const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
|
|
922
|
-
return directDependencyKeys.flatMap(
|
|
923
|
-
(depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
|
|
924
|
-
);
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
// internal/src/selector/update-selector-atoms.ts
|
|
928
|
-
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
929
|
-
const target = newest(store);
|
|
930
|
-
if (dependency.type === `atom`) {
|
|
931
|
-
target.selectorAtoms.set({
|
|
932
|
-
selectorKey,
|
|
933
|
-
atomKey: dependency.key
|
|
934
|
-
});
|
|
935
|
-
store.logger.info(
|
|
936
|
-
`\u{1F50D}`,
|
|
937
|
-
`selector`,
|
|
938
|
-
selectorKey,
|
|
939
|
-
`discovers root atom "${dependency.key}"`
|
|
940
|
-
);
|
|
941
|
-
} else {
|
|
942
|
-
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
943
|
-
store.logger.info(
|
|
944
|
-
`\u{1F50D}`,
|
|
945
|
-
`selector`,
|
|
946
|
-
selectorKey,
|
|
947
|
-
`discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
|
|
948
|
-
);
|
|
949
|
-
for (const atomKey of rootKeys) {
|
|
950
|
-
target.selectorAtoms = target.selectorAtoms.set({
|
|
951
|
-
selectorKey,
|
|
952
|
-
atomKey
|
|
953
|
-
});
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
|
|
958
|
-
// internal/src/selector/register-selector.ts
|
|
959
|
-
var registerSelector = (selectorKey, store) => ({
|
|
960
|
-
get: (dependency) => {
|
|
961
|
-
const target = newest(store);
|
|
962
|
-
const alreadyRegistered = target.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
|
|
963
|
-
const dependencyState = withdraw(dependency, store);
|
|
964
|
-
if (dependencyState === void 0) {
|
|
965
|
-
throw new Error(
|
|
966
|
-
`State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
967
|
-
);
|
|
968
|
-
}
|
|
969
|
-
const dependencyValue = readOrComputeValue(dependencyState, store);
|
|
970
|
-
store.logger.info(
|
|
971
|
-
`\u{1F50C}`,
|
|
972
|
-
`selector`,
|
|
973
|
-
selectorKey,
|
|
974
|
-
`registers dependency ( "${dependency.key}" =`,
|
|
975
|
-
dependencyValue,
|
|
976
|
-
`)`
|
|
977
|
-
);
|
|
978
|
-
if (!alreadyRegistered) {
|
|
979
|
-
target.selectorGraph.set(
|
|
980
|
-
{
|
|
981
|
-
upstreamSelectorKey: dependency.key,
|
|
982
|
-
downstreamSelectorKey: selectorKey
|
|
983
|
-
},
|
|
984
|
-
{
|
|
985
|
-
source: dependency.key
|
|
986
|
-
}
|
|
987
|
-
);
|
|
988
|
-
}
|
|
989
|
-
updateSelectorAtoms(selectorKey, dependency, store);
|
|
990
|
-
return dependencyValue;
|
|
991
|
-
},
|
|
992
|
-
set: (stateToken, newValue) => {
|
|
993
|
-
const state = withdraw(stateToken, store);
|
|
994
|
-
if (state === void 0) {
|
|
995
|
-
throw new Error(
|
|
996
|
-
`State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
997
|
-
);
|
|
998
|
-
}
|
|
999
|
-
setAtomOrSelector(state, newValue, store);
|
|
1000
|
-
}
|
|
1001
|
-
});
|
|
1002
|
-
|
|
1003
|
-
// internal/src/selector/create-read-write-selector.ts
|
|
1004
|
-
var createReadWriteSelector = (options, family, store) => {
|
|
1005
|
-
const target = newest(store);
|
|
1006
|
-
const subject = new Subject();
|
|
1007
|
-
const { get, set } = registerSelector(options.key, store);
|
|
1008
|
-
const getSelf = () => {
|
|
1009
|
-
const value = options.get({ get });
|
|
1010
|
-
cacheValue(options.key, value, subject, store);
|
|
1011
|
-
return value;
|
|
1012
|
-
};
|
|
1013
|
-
const setSelf = (next) => {
|
|
1014
|
-
const oldValue = getSelf();
|
|
1015
|
-
const newValue = become(next)(oldValue);
|
|
1016
|
-
store.logger.info(
|
|
1017
|
-
`\u{1F4DD}`,
|
|
1018
|
-
`selector`,
|
|
1019
|
-
options.key,
|
|
1020
|
-
`set (`,
|
|
1021
|
-
oldValue,
|
|
1022
|
-
`->`,
|
|
1023
|
-
newValue,
|
|
1024
|
-
`)`
|
|
1025
|
-
);
|
|
1026
|
-
cacheValue(options.key, newValue, subject, store);
|
|
1027
|
-
markDone(options.key, store);
|
|
1028
|
-
if (target.transactionMeta === null) {
|
|
1029
|
-
subject.next({ newValue, oldValue });
|
|
1030
|
-
}
|
|
1031
|
-
options.set({ get, set }, newValue);
|
|
1032
|
-
};
|
|
1033
|
-
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1034
|
-
subject,
|
|
1035
|
-
install: (s) => createSelector(options, family, s),
|
|
1036
|
-
get: getSelf,
|
|
1037
|
-
set: setSelf,
|
|
1038
|
-
type: `selector`
|
|
1039
|
-
}), family && { family });
|
|
1040
|
-
target.selectors.set(options.key, mySelector);
|
|
1041
|
-
const initialValue = getSelf();
|
|
1042
|
-
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1043
|
-
const token = {
|
|
1044
|
-
key: options.key,
|
|
1045
|
-
type: `selector`
|
|
1046
|
-
};
|
|
1047
|
-
if (family) {
|
|
1048
|
-
token.family = family;
|
|
1049
|
-
}
|
|
1050
|
-
store.subject.selectorCreation.next(token);
|
|
1051
|
-
return token;
|
|
1052
|
-
};
|
|
1053
|
-
|
|
1054
|
-
// internal/src/selector/create-readonly-selector.ts
|
|
1055
|
-
var createReadonlySelector = (options, family, store) => {
|
|
1056
|
-
const target = newest(store);
|
|
1057
|
-
const subject = new Subject();
|
|
1058
|
-
const { get } = registerSelector(options.key, store);
|
|
1059
|
-
const getSelf = () => {
|
|
1060
|
-
const value = options.get({ get });
|
|
1061
|
-
cacheValue(options.key, value, subject, store);
|
|
1062
|
-
return value;
|
|
1063
|
-
};
|
|
1064
|
-
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1065
|
-
subject,
|
|
1066
|
-
install: (s) => createSelector(options, family, s),
|
|
1067
|
-
get: getSelf,
|
|
1068
|
-
type: `readonly_selector`
|
|
1069
|
-
}), family && { family });
|
|
1070
|
-
target.readonlySelectors.set(options.key, readonlySelector);
|
|
1071
|
-
const initialValue = getSelf();
|
|
1072
|
-
store.logger.info(
|
|
1073
|
-
`\u2728`,
|
|
1074
|
-
readonlySelector.type,
|
|
1075
|
-
readonlySelector.key,
|
|
1076
|
-
`=`,
|
|
1077
|
-
initialValue
|
|
1078
|
-
);
|
|
1079
|
-
const token = {
|
|
1080
|
-
key: options.key,
|
|
1081
|
-
type: `readonly_selector`
|
|
1082
|
-
};
|
|
1083
|
-
if (family) {
|
|
1084
|
-
token.family = family;
|
|
1085
|
-
}
|
|
1086
|
-
store.subject.selectorCreation.next(token);
|
|
1087
|
-
return token;
|
|
1088
|
-
};
|
|
1089
|
-
|
|
1090
|
-
// internal/src/selector/create-selector.ts
|
|
1091
|
-
function createSelector(options, family, store) {
|
|
1092
|
-
const target = newest(store);
|
|
1093
|
-
const existingWritable = target.selectors.get(options.key);
|
|
1094
|
-
const existingReadonly = target.readonlySelectors.get(options.key);
|
|
1095
|
-
if (existingWritable || existingReadonly) {
|
|
1096
|
-
store.logger.error(
|
|
1097
|
-
`\u274C`,
|
|
1098
|
-
existingReadonly ? `readonly_selector` : `selector`,
|
|
1099
|
-
options.key,
|
|
1100
|
-
`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
|
|
1101
|
-
);
|
|
1102
|
-
}
|
|
1103
|
-
if (`set` in options) {
|
|
1104
|
-
return createReadWriteSelector(options, family, store);
|
|
1105
|
-
}
|
|
1106
|
-
return createReadonlySelector(options, family, store);
|
|
1107
|
-
}
|
|
1108
|
-
|
|
1109
|
-
// internal/src/subscribe/recall-state.ts
|
|
1110
|
-
var recallState = (state, store) => {
|
|
1111
|
-
const target = newest(store);
|
|
1112
|
-
if (!target.operation.open) {
|
|
1113
|
-
return target.valueMap.get(state.key);
|
|
1114
|
-
}
|
|
1115
|
-
return target.operation.prev.get(state.key);
|
|
1116
|
-
};
|
|
1117
|
-
|
|
1118
|
-
// internal/src/subscribe/subscribe-to-root-atoms.ts
|
|
1119
|
-
var subscribeToRootAtoms = (state, store) => {
|
|
1120
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1121
|
-
const atom = store.atoms.get(atomKey);
|
|
1122
|
-
if (atom === void 0) {
|
|
1123
|
-
throw new Error(
|
|
1124
|
-
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1125
|
-
);
|
|
1126
|
-
}
|
|
1127
|
-
return atom.subject.subscribe(
|
|
1128
|
-
`${state.type}:${state.key}`,
|
|
1129
|
-
(atomChange) => {
|
|
1130
|
-
store.logger.info(
|
|
1131
|
-
`\u{1F4E2}`,
|
|
1132
|
-
state.type,
|
|
1133
|
-
state.key,
|
|
1134
|
-
`root`,
|
|
1135
|
-
atomKey,
|
|
1136
|
-
`went`,
|
|
1137
|
-
atomChange.oldValue,
|
|
1138
|
-
`->`,
|
|
1139
|
-
atomChange.newValue
|
|
1140
|
-
);
|
|
1141
|
-
const oldValue = recallState(state, store);
|
|
1142
|
-
const newValue = readOrComputeValue(state, store);
|
|
1143
|
-
store.logger.info(
|
|
1144
|
-
`\u2728`,
|
|
1145
|
-
state.type,
|
|
1146
|
-
state.key,
|
|
1147
|
-
`went`,
|
|
1148
|
-
oldValue,
|
|
1149
|
-
`->`,
|
|
1150
|
-
newValue
|
|
1151
|
-
);
|
|
1152
|
-
state.subject.next({ newValue, oldValue });
|
|
1153
|
-
}
|
|
1154
|
-
);
|
|
1155
|
-
});
|
|
1156
|
-
return dependencySubscriptions;
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
// internal/src/subscribe/subscribe-to-state.ts
|
|
1160
|
-
function subscribeToState(token, handleUpdate, key, store) {
|
|
1161
|
-
const state = withdraw(token, store);
|
|
1162
|
-
if (state === void 0) {
|
|
1163
|
-
throw new Error(
|
|
1164
|
-
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1168
|
-
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1169
|
-
const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1170
|
-
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
1171
|
-
store.logger.info(
|
|
1172
|
-
`\u{1F648}`,
|
|
1173
|
-
state.type,
|
|
1174
|
-
state.key,
|
|
1175
|
-
`Removing subscription "${key}"`
|
|
1176
|
-
);
|
|
1177
|
-
unsubFunction();
|
|
1178
|
-
} : () => {
|
|
1179
|
-
store.logger.info(
|
|
1180
|
-
`\u{1F648}`,
|
|
1181
|
-
state.type,
|
|
1182
|
-
state.key,
|
|
1183
|
-
`Removing subscription "${key}"`
|
|
1184
|
-
);
|
|
1185
|
-
unsubFunction();
|
|
1186
|
-
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
1187
|
-
unsubFromDependency();
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
return unsubscribe;
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
// internal/src/subscribe/subscribe-to-timeline.ts
|
|
1194
|
-
var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
1195
|
-
const tl = withdraw(token, store);
|
|
1196
|
-
if (tl === void 0) {
|
|
1197
|
-
throw new Error(
|
|
1198
|
-
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
store.logger.info(`\u{1F440}`, `timeline`, token.key, `Adding subscription "${key}"`);
|
|
1202
|
-
const unsubscribe = tl.subject.subscribe(key, handleUpdate);
|
|
1203
|
-
return () => {
|
|
1204
|
-
store.logger.info(
|
|
1205
|
-
`\u{1F648}`,
|
|
1206
|
-
`timeline`,
|
|
1207
|
-
token.key,
|
|
1208
|
-
`Removing subscription "${key}" from timeline`
|
|
1209
|
-
);
|
|
1210
|
-
unsubscribe();
|
|
1211
|
-
};
|
|
1212
|
-
};
|
|
1213
|
-
|
|
1214
|
-
// internal/src/mutable/tracker.ts
|
|
1215
|
-
var Tracker = class {
|
|
1216
|
-
constructor(mutableState, store) {
|
|
1217
|
-
this.unsubscribeFromInnerValue = null;
|
|
1218
|
-
this.mutableState = mutableState;
|
|
1219
|
-
const target = newest(store);
|
|
1220
|
-
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
1221
|
-
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
1222
|
-
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
1223
|
-
target.trackers.set(mutableState.key, this);
|
|
1224
|
-
}
|
|
1225
|
-
initializeState(mutableState, store) {
|
|
1226
|
-
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
1227
|
-
store.atoms.delete(latestUpdateStateKey);
|
|
1228
|
-
store.valueMap.delete(latestUpdateStateKey);
|
|
1229
|
-
const familyMetaData = mutableState.family ? {
|
|
1230
|
-
key: `*${mutableState.family.key}`,
|
|
1231
|
-
subKey: mutableState.family.subKey
|
|
1232
|
-
} : void 0;
|
|
1233
|
-
const latestUpdateState = createAtom(
|
|
1234
|
-
{
|
|
1235
|
-
key: latestUpdateStateKey,
|
|
1236
|
-
default: null
|
|
1237
|
-
},
|
|
1238
|
-
familyMetaData,
|
|
1239
|
-
store
|
|
1240
|
-
);
|
|
1241
|
-
if (store.parent) {
|
|
1242
|
-
const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
|
|
1243
|
-
store.valueMap.set(latestUpdateStateKey, parentValue);
|
|
1244
|
-
}
|
|
1245
|
-
return latestUpdateState;
|
|
1246
|
-
}
|
|
1247
|
-
observeCore(mutableState, latestUpdateState, store) {
|
|
1248
|
-
const originalInnerValue = getState(mutableState, store);
|
|
1249
|
-
const target = newest(store);
|
|
1250
|
-
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1251
|
-
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
1252
|
-
(update) => {
|
|
1253
|
-
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1254
|
-
mutableState.key,
|
|
1255
|
-
() => {
|
|
1256
|
-
unsubscribe();
|
|
1257
|
-
setState(latestUpdateState, update, store);
|
|
1258
|
-
}
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
|
-
);
|
|
1262
|
-
subscribeToState(
|
|
1263
|
-
mutableState,
|
|
1264
|
-
(update) => {
|
|
1265
|
-
var _a;
|
|
1266
|
-
if (update.newValue !== update.oldValue) {
|
|
1267
|
-
(_a = this.unsubscribeFromInnerValue) == null ? void 0 : _a.call(this);
|
|
1268
|
-
const target2 = newest(store);
|
|
1269
|
-
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
1270
|
-
`tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
|
|
1271
|
-
(update2) => {
|
|
1272
|
-
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1273
|
-
mutableState.key,
|
|
1274
|
-
() => {
|
|
1275
|
-
unsubscribe();
|
|
1276
|
-
setState(latestUpdateState, update2, store);
|
|
1277
|
-
}
|
|
1278
|
-
);
|
|
1279
|
-
}
|
|
1280
|
-
);
|
|
1281
|
-
}
|
|
1282
|
-
},
|
|
1283
|
-
`${store.config.name}: tracker observing inner value`,
|
|
1284
|
-
store
|
|
1285
|
-
);
|
|
1286
|
-
}
|
|
1287
|
-
updateCore(mutableState, latestUpdateState, store) {
|
|
1288
|
-
subscribeToState(
|
|
1289
|
-
latestUpdateState,
|
|
1290
|
-
({ newValue, oldValue }) => {
|
|
1291
|
-
const timelineId = store.timelineAtoms.getRelatedKey(
|
|
1292
|
-
latestUpdateState.key
|
|
1293
|
-
);
|
|
1294
|
-
if (timelineId) {
|
|
1295
|
-
const timelineData = store.timelines.get(timelineId);
|
|
1296
|
-
if (timelineData == null ? void 0 : timelineData.timeTraveling) {
|
|
1297
|
-
const unsubscribe2 = subscribeToTimeline(
|
|
1298
|
-
{ key: timelineId, type: `timeline` },
|
|
1299
|
-
(update) => {
|
|
1300
|
-
unsubscribe2();
|
|
1301
|
-
setState(
|
|
1302
|
-
mutableState,
|
|
1303
|
-
(transceiver) => {
|
|
1304
|
-
if (update === `redo` && newValue) {
|
|
1305
|
-
transceiver.do(newValue);
|
|
1306
|
-
} else if (update === `undo` && oldValue) {
|
|
1307
|
-
transceiver.undo(oldValue);
|
|
1308
|
-
}
|
|
1309
|
-
return transceiver;
|
|
1310
|
-
},
|
|
1311
|
-
store
|
|
1312
|
-
);
|
|
1313
|
-
},
|
|
1314
|
-
`${mutableState.key}: tracker observing timeline`,
|
|
1315
|
-
store
|
|
1316
|
-
);
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1321
|
-
latestUpdateState.key,
|
|
1322
|
-
() => {
|
|
1323
|
-
unsubscribe();
|
|
1324
|
-
const mutable = getState(mutableState, store);
|
|
1325
|
-
const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
|
|
1326
|
-
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1327
|
-
if (newValue && eventOffset === 1) {
|
|
1328
|
-
setState(
|
|
1329
|
-
mutableState,
|
|
1330
|
-
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1331
|
-
store
|
|
1332
|
-
);
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
);
|
|
1336
|
-
},
|
|
1337
|
-
`${store.config.name}: tracker observing latest update`,
|
|
1338
|
-
store
|
|
1339
|
-
);
|
|
1340
|
-
}
|
|
1341
|
-
};
|
|
1342
|
-
|
|
1343
|
-
// internal/src/mutable/create-mutable-atom.ts
|
|
1344
|
-
function createMutableAtom(options, store) {
|
|
1345
|
-
store.logger.info(
|
|
1346
|
-
`\u{1F527}`,
|
|
1347
|
-
`atom`,
|
|
1348
|
-
options.key,
|
|
1349
|
-
`creating in store "${store.config.name}"`
|
|
1350
|
-
);
|
|
1351
|
-
const coreState = createAtom(options, void 0, store);
|
|
1352
|
-
new Tracker(coreState, store);
|
|
1353
|
-
const jsonState = selectJson(coreState, options, store);
|
|
1354
|
-
const target = newest(store);
|
|
1355
|
-
subscribeToState(
|
|
1356
|
-
jsonState,
|
|
1357
|
-
() => {
|
|
1358
|
-
const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
|
|
1359
|
-
if (!trackerHasBeenInitialized) {
|
|
1360
|
-
new Tracker(coreState, store);
|
|
1361
|
-
}
|
|
1362
|
-
},
|
|
1363
|
-
`tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`,
|
|
1364
|
-
store
|
|
1365
|
-
);
|
|
1366
|
-
return coreState;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
// internal/src/families/create-atom-family.ts
|
|
1370
|
-
function createAtomFamily(options, store) {
|
|
1371
|
-
const subject = new Subject();
|
|
1372
|
-
const atomFamily = Object.assign(
|
|
1373
|
-
(key) => {
|
|
1374
|
-
const subKey = stringifyJson(key);
|
|
1375
|
-
const family = { key: options.key, subKey };
|
|
1376
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1377
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
1378
|
-
let token;
|
|
1379
|
-
if (existing) {
|
|
1380
|
-
token = deposit(existing);
|
|
1381
|
-
} else {
|
|
1382
|
-
const individualOptions = {
|
|
1383
|
-
key: fullKey,
|
|
1384
|
-
default: options.default instanceof Function ? options.default(key) : options.default
|
|
1385
|
-
};
|
|
1386
|
-
if (options.effects) {
|
|
1387
|
-
individualOptions.effects = options.effects(key);
|
|
1388
|
-
}
|
|
1389
|
-
token = createAtom(individualOptions, family, store);
|
|
1390
|
-
subject.next(token);
|
|
1391
|
-
}
|
|
1392
|
-
return token;
|
|
1393
|
-
},
|
|
1394
|
-
{
|
|
1395
|
-
key: options.key,
|
|
1396
|
-
type: `atom_family`,
|
|
1397
|
-
subject
|
|
1398
|
-
}
|
|
1399
|
-
);
|
|
1400
|
-
if (`mutable` in options && typeof options.mutable === `boolean`) {
|
|
1401
|
-
Object.assign(atomFamily, { mutable: options.mutable });
|
|
1402
|
-
}
|
|
1403
|
-
const target = newest(store);
|
|
1404
|
-
target.families.set(options.key, atomFamily);
|
|
1405
|
-
return atomFamily;
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
// internal/src/families/create-readonly-selector-family.ts
|
|
1409
|
-
function createReadonlySelectorFamily(options, store) {
|
|
1410
|
-
const subject = new Subject();
|
|
1411
|
-
return Object.assign(
|
|
1412
|
-
(key) => {
|
|
1413
|
-
const target = newest(store);
|
|
1414
|
-
const subKey = stringifyJson(key);
|
|
1415
|
-
const family = { key: options.key, subKey };
|
|
1416
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1417
|
-
const existing = target.readonlySelectors.get(fullKey);
|
|
1418
|
-
if (existing) {
|
|
1419
|
-
return deposit(existing);
|
|
1420
|
-
}
|
|
1421
|
-
return createSelector(
|
|
1422
|
-
{
|
|
1423
|
-
key: fullKey,
|
|
1424
|
-
get: options.get(key)
|
|
1425
|
-
},
|
|
1426
|
-
family,
|
|
1427
|
-
store
|
|
1428
|
-
);
|
|
1429
|
-
},
|
|
1430
|
-
{
|
|
1431
|
-
key: options.key,
|
|
1432
|
-
type: `readonly_selector_family`,
|
|
1433
|
-
subject
|
|
1434
|
-
}
|
|
1435
|
-
);
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
// internal/src/families/create-selector-family.ts
|
|
1439
|
-
function createSelectorFamily(options, store) {
|
|
1440
|
-
const isReadonly = !(`set` in options);
|
|
1441
|
-
if (isReadonly) {
|
|
1442
|
-
return createReadonlySelectorFamily(options, store);
|
|
1443
|
-
}
|
|
1444
|
-
const target = newest(store);
|
|
1445
|
-
const subject = new Subject();
|
|
1446
|
-
const selectorFamily = Object.assign(
|
|
1447
|
-
(key) => {
|
|
1448
|
-
const subKey = stringifyJson(key);
|
|
1449
|
-
const family = { key: options.key, subKey };
|
|
1450
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
1451
|
-
const existing = target.selectors.get(fullKey);
|
|
1452
|
-
if (existing) {
|
|
1453
|
-
return deposit(existing);
|
|
1454
|
-
}
|
|
1455
|
-
const token = createSelector(
|
|
1456
|
-
{
|
|
1457
|
-
key: fullKey,
|
|
1458
|
-
get: options.get(key),
|
|
1459
|
-
set: options.set(key)
|
|
1460
|
-
},
|
|
1461
|
-
family,
|
|
1462
|
-
store
|
|
1463
|
-
);
|
|
1464
|
-
subject.next(token);
|
|
1465
|
-
return token;
|
|
1466
|
-
},
|
|
1467
|
-
{
|
|
1468
|
-
key: options.key,
|
|
1469
|
-
type: `selector_family`
|
|
1470
|
-
}
|
|
1471
|
-
);
|
|
1472
|
-
target.families.set(options.key, selectorFamily);
|
|
1473
|
-
return selectorFamily;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
// internal/src/mutable/tracker-family.ts
|
|
1477
|
-
var FamilyTracker = class {
|
|
1478
|
-
constructor(findMutableState, store) {
|
|
1479
|
-
this.findLatestUpdateState = createAtomFamily(
|
|
1480
|
-
{
|
|
1481
|
-
key: `*${findMutableState.key}`,
|
|
1482
|
-
default: null
|
|
1483
|
-
},
|
|
1484
|
-
store
|
|
1485
|
-
);
|
|
1486
|
-
this.findMutableState = findMutableState;
|
|
1487
|
-
this.findMutableState.subject.subscribe(
|
|
1488
|
-
`store=${store.config.name}::tracker-atom-family`,
|
|
1489
|
-
(atomToken) => {
|
|
1490
|
-
if (atomToken.family) {
|
|
1491
|
-
const key = parseJson(atomToken.family.subKey);
|
|
1492
|
-
this.findLatestUpdateState(key);
|
|
1493
|
-
new Tracker(atomToken, store);
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
);
|
|
1497
|
-
this.findLatestUpdateState.subject.subscribe(
|
|
1498
|
-
`store=${store.config.name}::tracker-atom-family`,
|
|
1499
|
-
(atomToken) => {
|
|
1500
|
-
if (atomToken.family) {
|
|
1501
|
-
const key = parseJson(atomToken.family.subKey);
|
|
1502
|
-
const mutableAtomToken = this.findMutableState(key);
|
|
1503
|
-
new Tracker(mutableAtomToken, store);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
);
|
|
1507
|
-
}
|
|
1508
|
-
};
|
|
1509
|
-
|
|
1510
|
-
// internal/src/mutable/create-mutable-atom-family.ts
|
|
1511
|
-
function createMutableAtomFamily(options, store) {
|
|
1512
|
-
const coreFamily = Object.assign(
|
|
1513
|
-
createAtomFamily(options, store),
|
|
1514
|
-
options
|
|
1515
|
-
);
|
|
1516
|
-
selectJsonFamily(coreFamily, options);
|
|
1517
|
-
new FamilyTracker(coreFamily, store);
|
|
1518
|
-
return coreFamily;
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
// internal/src/mutable/get-json-family.ts
|
|
1522
|
-
var getJsonFamily = (mutableAtomFamily, store) => {
|
|
1523
|
-
const target = newest(store);
|
|
1524
|
-
const key = `${mutableAtomFamily.key}:JSON`;
|
|
1525
|
-
const jsonFamily = target.families.get(
|
|
1526
|
-
key
|
|
1527
|
-
);
|
|
1528
|
-
return jsonFamily;
|
|
1529
|
-
};
|
|
1530
|
-
|
|
1531
|
-
// internal/src/mutable/transceiver.ts
|
|
1532
|
-
function isTransceiver(value) {
|
|
1533
|
-
return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
// internal/src/atom/is-default.ts
|
|
1537
|
-
var isAtomDefault = (key, store) => {
|
|
1538
|
-
const core = newest(store);
|
|
1539
|
-
return core.atomsThatAreDefault.has(key);
|
|
1540
|
-
};
|
|
1541
|
-
var markAtomAsDefault = (key, store) => {
|
|
1542
|
-
const core = newest(store);
|
|
1543
|
-
core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key);
|
|
1544
|
-
};
|
|
1545
|
-
var markAtomAsNotDefault = (key, store) => {
|
|
1546
|
-
const core = newest(store);
|
|
1547
|
-
core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault);
|
|
1548
|
-
core.atomsThatAreDefault.delete(key);
|
|
1549
|
-
};
|
|
1550
|
-
|
|
1551
|
-
// internal/src/atom/create-atom.ts
|
|
1552
|
-
function createAtom(options, family, store) {
|
|
1553
|
-
store.logger.info(
|
|
1554
|
-
`\u{1F528}`,
|
|
1555
|
-
`atom`,
|
|
1556
|
-
options.key,
|
|
1557
|
-
`creating in store "${store.config.name}"`
|
|
1558
|
-
);
|
|
1559
|
-
const target = newest(store);
|
|
1560
|
-
const existing = target.atoms.get(options.key);
|
|
1561
|
-
if (existing) {
|
|
1562
|
-
store.logger.error(
|
|
1563
|
-
`\u274C`,
|
|
1564
|
-
`atom`,
|
|
1565
|
-
options.key,
|
|
1566
|
-
`Tried to create atom, but it already exists in the store.`,
|
|
1567
|
-
`(Ignore if you are in development using hot module replacement.)`
|
|
1568
|
-
);
|
|
1569
|
-
return deposit(existing);
|
|
1570
|
-
}
|
|
1571
|
-
const subject = new Subject();
|
|
1572
|
-
const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1573
|
-
type: `atom`,
|
|
1574
|
-
install: (store2) => {
|
|
1575
|
-
store2.logger.info(
|
|
1576
|
-
`\u{1F6E0}\uFE0F`,
|
|
1577
|
-
`atom`,
|
|
1578
|
-
options.key,
|
|
1579
|
-
`installing in store "${store2.config.name}"`
|
|
1580
|
-
);
|
|
1581
|
-
return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
|
|
1582
|
-
},
|
|
1583
|
-
subject
|
|
1584
|
-
}), family && { family });
|
|
1585
|
-
let initialValue = options.default;
|
|
1586
|
-
if (options.default instanceof Function) {
|
|
1587
|
-
initialValue = options.default();
|
|
1588
|
-
}
|
|
1589
|
-
target.atoms.set(newAtom.key, newAtom);
|
|
1590
|
-
markAtomAsDefault(options.key, store);
|
|
1591
|
-
cacheValue(options.key, initialValue, subject, store);
|
|
1592
|
-
const token = deposit(newAtom);
|
|
1593
|
-
if (options.effects) {
|
|
1594
|
-
let effectIndex = 0;
|
|
1595
|
-
const cleanupFunctions = [];
|
|
1596
|
-
for (const effect of options.effects) {
|
|
1597
|
-
const cleanup = effect({
|
|
1598
|
-
setSelf: (next) => setState(token, next, store),
|
|
1599
|
-
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1600
|
-
});
|
|
1601
|
-
if (cleanup) {
|
|
1602
|
-
cleanupFunctions.push(cleanup);
|
|
1603
|
-
}
|
|
1604
|
-
++effectIndex;
|
|
1605
|
-
}
|
|
1606
|
-
newAtom.cleanup = () => {
|
|
1607
|
-
for (const cleanup of cleanupFunctions) {
|
|
1608
|
-
cleanup();
|
|
1609
|
-
}
|
|
1610
|
-
};
|
|
1611
|
-
}
|
|
1612
|
-
store.subject.atomCreation.next(token);
|
|
1613
|
-
return token;
|
|
1614
|
-
}
|
|
1615
|
-
|
|
1616
|
-
// internal/src/not-found-error.ts
|
|
1617
|
-
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1618
|
-
function prettyPrintTokenType(token) {
|
|
1619
|
-
if (token.type === `readonly_selector`) {
|
|
1620
|
-
return `Readonly Selector`;
|
|
1621
|
-
}
|
|
1622
|
-
return capitalize(token.type);
|
|
1623
|
-
}
|
|
1624
|
-
var NotFoundError = class extends Error {
|
|
1625
|
-
constructor(token, store) {
|
|
1626
|
-
super(
|
|
1627
|
-
`${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
|
|
1628
|
-
);
|
|
1629
|
-
}
|
|
1630
|
-
};
|
|
1631
|
-
|
|
1632
|
-
// data/src/dict.ts
|
|
1633
|
-
function dict(findState, index, store = IMPLICIT.STORE) {
|
|
1634
|
-
return createSelector(
|
|
1635
|
-
{
|
|
1636
|
-
key: `${findState.key}Dict`,
|
|
1637
|
-
get: ({ get }) => {
|
|
1638
|
-
const keys = get(index);
|
|
1639
|
-
return keys.reduce((acc, key) => {
|
|
1640
|
-
acc[key] = get(findState(key));
|
|
1641
|
-
return acc;
|
|
1642
|
-
}, {});
|
|
1643
|
-
}
|
|
1644
|
-
},
|
|
1645
|
-
void 0,
|
|
1646
|
-
store
|
|
1647
|
-
);
|
|
1648
|
-
}
|
|
1649
|
-
var TRANSACTORS = { get: getState, set: setState };
|
|
1650
|
-
function capitalize2(string) {
|
|
283
|
+
// data/src/join.ts
|
|
284
|
+
var TRANSACTORS = { get: atom_io.getState, set: atom_io.setState };
|
|
285
|
+
function capitalize(string) {
|
|
1651
286
|
return string[0].toUpperCase() + string.slice(1);
|
|
1652
287
|
}
|
|
1653
|
-
function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
288
|
+
function join(options, defaultContent, store = internal.IMPLICIT.STORE) {
|
|
1654
289
|
const a = options.between[0];
|
|
1655
290
|
const b = options.between[1];
|
|
1656
|
-
const findRelatedKeysState = createMutableAtomFamily(
|
|
291
|
+
const findRelatedKeysState = internal.createMutableAtomFamily(
|
|
1657
292
|
{
|
|
1658
293
|
key: `${options.key}/relatedKeys`,
|
|
1659
294
|
default: () => new setRtx.SetRTX(),
|
|
@@ -1745,7 +380,7 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1745
380
|
let externalStore;
|
|
1746
381
|
let findContentState;
|
|
1747
382
|
if (defaultContent) {
|
|
1748
|
-
findContentState = createAtomFamily(
|
|
383
|
+
findContentState = internal.createAtomFamily(
|
|
1749
384
|
{
|
|
1750
385
|
key: `${options.key}/content`,
|
|
1751
386
|
default: defaultContent
|
|
@@ -1778,7 +413,7 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1778
413
|
externalStore,
|
|
1779
414
|
makeContentKey: (...args) => args.sort().join(`:`)
|
|
1780
415
|
});
|
|
1781
|
-
const createSingleKeyStateFamily = () => createSelectorFamily(
|
|
416
|
+
const createSingleKeyStateFamily = () => internal.createSelectorFamily(
|
|
1782
417
|
{
|
|
1783
418
|
key: `${options.key}/singleRelatedKey`,
|
|
1784
419
|
get: (key) => ({ get }) => {
|
|
@@ -1790,8 +425,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1790
425
|
},
|
|
1791
426
|
store
|
|
1792
427
|
);
|
|
1793
|
-
const getMultipleKeyStateFamily = () => getJsonFamily(findRelatedKeysState, store);
|
|
1794
|
-
const createSingleEntryStateFamily = () => createSelectorFamily(
|
|
428
|
+
const getMultipleKeyStateFamily = () => internal.getJsonFamily(findRelatedKeysState, store);
|
|
429
|
+
const createSingleEntryStateFamily = () => internal.createSelectorFamily(
|
|
1795
430
|
{
|
|
1796
431
|
key: `${options.key}/singleRelatedEntry`,
|
|
1797
432
|
get: (key) => ({ get }) => {
|
|
@@ -1804,7 +439,7 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1804
439
|
},
|
|
1805
440
|
store
|
|
1806
441
|
);
|
|
1807
|
-
const getMultipleEntryStateFamily = () => createSelectorFamily(
|
|
442
|
+
const getMultipleEntryStateFamily = () => internal.createSelectorFamily(
|
|
1808
443
|
{
|
|
1809
444
|
key: `${options.key}/multipleRelatedEntries`,
|
|
1810
445
|
get: (key) => ({ get }) => {
|
|
@@ -1820,8 +455,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1820
455
|
switch (options.cardinality) {
|
|
1821
456
|
case `1:1`: {
|
|
1822
457
|
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
1823
|
-
const stateKeyA = `${a}KeyOf${
|
|
1824
|
-
const stateKeyB = `${b}KeyOf${
|
|
458
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
459
|
+
const stateKeyB = `${b}KeyOf${capitalize(a)}`;
|
|
1825
460
|
const findStateBase = {
|
|
1826
461
|
[stateKeyA]: findSingleRelatedKeyState,
|
|
1827
462
|
[stateKeyB]: findSingleRelatedKeyState
|
|
@@ -1829,8 +464,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1829
464
|
let findState;
|
|
1830
465
|
if (defaultContent) {
|
|
1831
466
|
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
1832
|
-
const entriesStateKeyA = `${a}EntryOf${
|
|
1833
|
-
const entriesStateKeyB = `${b}EntryOf${
|
|
467
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
468
|
+
const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
|
|
1834
469
|
const findStateWithContent = {
|
|
1835
470
|
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
1836
471
|
[entriesStateKeyB]: findSingleRelatedEntryState
|
|
@@ -1847,8 +482,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1847
482
|
case `1:n`: {
|
|
1848
483
|
const findSingleRelatedKeyState = createSingleKeyStateFamily();
|
|
1849
484
|
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
1850
|
-
const stateKeyA = `${a}KeyOf${
|
|
1851
|
-
const stateKeyB = `${b}KeysOf${
|
|
485
|
+
const stateKeyA = `${a}KeyOf${capitalize(b)}`;
|
|
486
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
1852
487
|
const findStateBase = {
|
|
1853
488
|
[stateKeyA]: findSingleRelatedKeyState,
|
|
1854
489
|
[stateKeyB]: findMultipleRelatedKeysState
|
|
@@ -1857,8 +492,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1857
492
|
if (defaultContent) {
|
|
1858
493
|
const findSingleRelatedEntryState = createSingleEntryStateFamily();
|
|
1859
494
|
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
1860
|
-
const entriesStateKeyA = `${a}EntryOf${
|
|
1861
|
-
const entriesStateKeyB = `${b}EntriesOf${
|
|
495
|
+
const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
|
|
496
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
1862
497
|
const findStateWithContent = {
|
|
1863
498
|
[entriesStateKeyA]: findSingleRelatedEntryState,
|
|
1864
499
|
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
@@ -1874,8 +509,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1874
509
|
}
|
|
1875
510
|
case `n:n`: {
|
|
1876
511
|
const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
|
|
1877
|
-
const stateKeyA = `${a}KeysOf${
|
|
1878
|
-
const stateKeyB = `${b}KeysOf${
|
|
512
|
+
const stateKeyA = `${a}KeysOf${capitalize(b)}`;
|
|
513
|
+
const stateKeyB = `${b}KeysOf${capitalize(a)}`;
|
|
1879
514
|
const findStateBase = {
|
|
1880
515
|
[stateKeyA]: findMultipleRelatedKeysState,
|
|
1881
516
|
[stateKeyB]: findMultipleRelatedKeysState
|
|
@@ -1883,8 +518,8 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1883
518
|
let findState;
|
|
1884
519
|
if (defaultContent) {
|
|
1885
520
|
const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
|
|
1886
|
-
const entriesStateKeyA = `${a}EntriesOf${
|
|
1887
|
-
const entriesStateKeyB = `${b}EntriesOf${
|
|
521
|
+
const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
|
|
522
|
+
const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
|
|
1888
523
|
const findStateWithContent = {
|
|
1889
524
|
[entriesStateKeyA]: findMultipleRelatedEntriesState,
|
|
1890
525
|
[entriesStateKeyB]: findMultipleRelatedEntriesState
|
|
@@ -1902,13 +537,11 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
|
|
|
1902
537
|
throw new Error(`Invalid cardinality: ${options.cardinality}`);
|
|
1903
538
|
}
|
|
1904
539
|
}
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1908
|
-
function struct(options, store = IMPLICIT.STORE) {
|
|
540
|
+
var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
541
|
+
function struct(options, store = internal.IMPLICIT.STORE) {
|
|
1909
542
|
const atoms = Object.keys(options.default).reduce((acc, key) => {
|
|
1910
|
-
const atomName = options.key +
|
|
1911
|
-
acc[atomName] = createAtom(
|
|
543
|
+
const atomName = options.key + capitalize2(key) + `State`;
|
|
544
|
+
acc[atomName] = internal.createAtom(
|
|
1912
545
|
{
|
|
1913
546
|
key: `${options.key}.${key}`,
|
|
1914
547
|
default: options.default[key]
|
|
@@ -1918,12 +551,12 @@ function struct(options, store = IMPLICIT.STORE) {
|
|
|
1918
551
|
);
|
|
1919
552
|
return acc;
|
|
1920
553
|
}, {});
|
|
1921
|
-
const structState = createSelector(
|
|
554
|
+
const structState = internal.createSelector(
|
|
1922
555
|
{
|
|
1923
556
|
key: options.key,
|
|
1924
557
|
get: ({ get }) => {
|
|
1925
558
|
return Object.keys(options.default).reduce((acc, key) => {
|
|
1926
|
-
acc[key] = get(atoms[options.key +
|
|
559
|
+
acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
|
|
1927
560
|
return acc;
|
|
1928
561
|
}, {});
|
|
1929
562
|
}
|
|
@@ -1933,23 +566,21 @@ function struct(options, store = IMPLICIT.STORE) {
|
|
|
1933
566
|
);
|
|
1934
567
|
return [atoms, structState];
|
|
1935
568
|
}
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
var capitalize4 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1939
|
-
var nameFamily = (topKey, subKey) => `find` + capitalize4(topKey) + capitalize4(subKey) + `State`;
|
|
569
|
+
var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
|
|
570
|
+
var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
|
|
1940
571
|
function structFamily(options) {
|
|
1941
572
|
const atoms = Object.keys(options.default).reduce((acc, subKey) => {
|
|
1942
573
|
const atomFamilyName = nameFamily(options.key, subKey);
|
|
1943
|
-
acc[atomFamilyName] = createAtomFamily(
|
|
574
|
+
acc[atomFamilyName] = internal.createAtomFamily(
|
|
1944
575
|
{
|
|
1945
576
|
key: `${options.key}.${subKey}`,
|
|
1946
577
|
default: options.default[subKey]
|
|
1947
578
|
},
|
|
1948
|
-
IMPLICIT.STORE
|
|
579
|
+
internal.IMPLICIT.STORE
|
|
1949
580
|
);
|
|
1950
581
|
return acc;
|
|
1951
582
|
}, {});
|
|
1952
|
-
const findStructState = createSelectorFamily(
|
|
583
|
+
const findStructState = internal.createSelectorFamily(
|
|
1953
584
|
{
|
|
1954
585
|
key: options.key,
|
|
1955
586
|
get: (id) => ({ get }) => {
|
|
@@ -1961,7 +592,7 @@ function structFamily(options) {
|
|
|
1961
592
|
}, {});
|
|
1962
593
|
}
|
|
1963
594
|
},
|
|
1964
|
-
IMPLICIT.STORE
|
|
595
|
+
internal.IMPLICIT.STORE
|
|
1965
596
|
);
|
|
1966
597
|
return [atoms, findStructState];
|
|
1967
598
|
}
|