atom.io 0.13.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.cjs +1473 -52
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.cts +315 -16
- package/data/dist/index.js +10 -267
- package/data/dist/index.js.map +1 -1
- package/data/package.json +5 -5
- package/data/src/join.ts +3 -3
- package/dist/chunk-5VJ77LZE.js +176 -0
- package/dist/chunk-5VJ77LZE.js.map +1 -0
- package/dist/chunk-CK7GNCU5.js +309 -0
- package/dist/chunk-CK7GNCU5.js.map +1 -0
- package/dist/chunk-KW7RA7IM.js +67 -0
- package/dist/chunk-KW7RA7IM.js.map +1 -0
- package/dist/chunk-LFXB7Y6M.js +68 -0
- package/dist/chunk-LFXB7Y6M.js.map +1 -0
- package/dist/chunk-NYCVSXQB.js +181 -0
- package/dist/chunk-NYCVSXQB.js.map +1 -0
- package/dist/chunk-TE3ZSTQ6.js +2516 -0
- package/dist/chunk-TE3ZSTQ6.js.map +1 -0
- package/dist/index.cjs +2250 -126
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +272 -25
- package/dist/index.js +1 -215
- package/dist/index.js.map +1 -1
- package/dist/metafile-cjs.json +1 -1
- package/internal/dist/index.cjs +885 -684
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.cts +230 -24
- package/internal/dist/index.js +1 -2171
- package/internal/dist/index.js.map +1 -1
- package/internal/package.json +5 -5
- package/internal/src/atom/create-atom.ts +3 -2
- package/internal/src/mutable/create-mutable-atom.ts +3 -2
- package/internal/src/mutable/tracker.ts +6 -4
- package/internal/src/selector/register-selector.ts +1 -1
- package/internal/src/selector/update-selector-atoms.ts +3 -3
- package/internal/src/subscribe/index.ts +3 -0
- package/internal/src/subscribe/recall-state.ts +0 -6
- package/internal/src/subscribe/subscribe-to-state.ts +47 -0
- package/internal/src/subscribe/subscribe-to-timeline.ts +28 -0
- package/internal/src/subscribe/subscribe-to-transaction.ts +33 -0
- package/introspection/dist/index.cjs +1618 -46
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.cts +374 -4
- package/introspection/dist/index.js +2 -316
- package/introspection/dist/index.js.map +1 -1
- package/introspection/package.json +5 -5
- package/json/dist/index.cjs +1560 -8
- package/json/dist/index.cjs.map +1 -1
- package/json/dist/index.d.cts +371 -7
- package/json/dist/index.js +1 -76
- package/json/dist/index.js.map +1 -1
- package/json/package.json +5 -5
- package/package.json +10 -9
- package/react/dist/index.cjs +1638 -10
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.cts +383 -5
- package/react/dist/index.js +2 -31
- package/react/dist/index.js.map +1 -1
- package/react/package.json +5 -5
- package/react/src/store-hooks.ts +52 -3
- package/react-devtools/dist/index.cjs +2268 -198
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.css +2 -2
- package/react-devtools/dist/index.d.cts +148 -24
- package/react-devtools/dist/index.js +57 -297
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/package.json +5 -5
- package/realtime-client/dist/index.cjs +1585 -34
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.cts +382 -11
- package/realtime-client/dist/index.js +2 -164
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/package.json +5 -5
- package/realtime-client/src/use-push.ts +4 -4
- package/realtime-client/src/use-server-action.ts +4 -4
- package/realtime-react/dist/index.cjs +1782 -35
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.cts +49 -9
- package/realtime-react/dist/index.js +4 -66
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/package.json +5 -5
- package/realtime-server/dist/index.cjs +1627 -60
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.cts +391 -11
- package/realtime-server/dist/index.js +59 -32
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/package.json +6 -6
- package/realtime-server/src/hook-composition/expose-family.ts +7 -3
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +13 -5
- package/realtime-server/src/hook-composition/expose-mutable.ts +11 -3
- package/realtime-server/src/hook-composition/expose-single.ts +6 -2
- package/realtime-server/src/hook-composition/receive-transaction.ts +14 -5
- package/realtime-testing/dist/index.cjs +2352 -16
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.d.cts +486 -3
- package/realtime-testing/dist/index.js +10 -31
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/package.json +5 -5
- package/src/subscribe.ts +37 -91
- package/transceivers/set-rtx/dist/index.cjs +31 -10
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.d.cts +29 -3
- package/transceivers/set-rtx/dist/index.js +2 -3
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/package.json +6 -6
- package/data/dist/index.d.ts +0 -158
- package/data/dist/metafile-cjs.json +0 -1
- package/data/dist/metafile-esm.json +0 -1
- package/dist/index.d.ts +0 -243
- package/dist/metafile-esm.json +0 -1
- package/internal/dist/index.d.ts +0 -414
- package/internal/dist/metafile-cjs.json +0 -1
- package/internal/dist/metafile-esm.json +0 -1
- package/introspection/dist/index.d.ts +0 -24
- package/introspection/dist/metafile-cjs.json +0 -1
- package/introspection/dist/metafile-esm.json +0 -1
- package/json/dist/index.d.ts +0 -51
- package/json/dist/metafile-cjs.json +0 -1
- package/json/dist/metafile-esm.json +0 -1
- package/react/dist/index.d.ts +0 -16
- package/react/dist/metafile-cjs.json +0 -1
- package/react/dist/metafile-esm.json +0 -1
- package/react-devtools/dist/index.d.ts +0 -341
- package/react-devtools/dist/metafile-cjs.json +0 -1
- package/react-devtools/dist/metafile-esm.json +0 -1
- package/realtime-client/dist/index.d.ts +0 -21
- package/realtime-client/dist/metafile-cjs.json +0 -1
- package/realtime-client/dist/metafile-esm.json +0 -1
- package/realtime-react/dist/index.d.ts +0 -27
- package/realtime-react/dist/metafile-cjs.json +0 -1
- package/realtime-react/dist/metafile-esm.json +0 -1
- package/realtime-server/dist/index.d.ts +0 -25
- package/realtime-server/dist/metafile-cjs.json +0 -1
- package/realtime-server/dist/metafile-esm.json +0 -1
- package/realtime-testing/dist/index.d.ts +0 -49
- package/realtime-testing/dist/metafile-cjs.json +0 -1
- package/realtime-testing/dist/metafile-esm.json +0 -1
- package/transceivers/set-rtx/dist/index.d.ts +0 -40
- package/transceivers/set-rtx/dist/metafile-cjs.json +0 -1
- package/transceivers/set-rtx/dist/metafile-esm.json +0 -1
package/internal/dist/index.cjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var atom_io = require('atom.io');
|
|
4
|
-
var json = require('atom.io/json');
|
|
5
|
-
|
|
6
3
|
var __defProp = Object.defineProperty;
|
|
7
4
|
var __defProps = Object.defineProperties;
|
|
8
5
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -23,7 +20,78 @@ var __spreadValues = (a, b) => {
|
|
|
23
20
|
};
|
|
24
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
22
|
|
|
26
|
-
// src/
|
|
23
|
+
// src/get-state.ts
|
|
24
|
+
function getState(token, store = IMPLICIT.STORE) {
|
|
25
|
+
var _a;
|
|
26
|
+
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
27
|
+
if (state === void 0) {
|
|
28
|
+
throw new NotFoundError(token, store);
|
|
29
|
+
}
|
|
30
|
+
return readOrComputeValue(state, store);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/logger.ts
|
|
34
|
+
var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
|
|
35
|
+
console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
|
|
36
|
+
};
|
|
37
|
+
var simpleLogger = {
|
|
38
|
+
error: simpleLog(`error`),
|
|
39
|
+
info: simpleLog(`info`),
|
|
40
|
+
warn: simpleLog(`warn`)
|
|
41
|
+
};
|
|
42
|
+
var AtomIOLogger = class {
|
|
43
|
+
constructor(logLevel, filter, logger = simpleLogger) {
|
|
44
|
+
this.logLevel = logLevel;
|
|
45
|
+
this.filter = filter;
|
|
46
|
+
this.logger = logger;
|
|
47
|
+
this.error = (...args) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
|
|
50
|
+
this.logger.error(...args);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
this.info = (...args) => {
|
|
54
|
+
var _a, _b;
|
|
55
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
|
|
56
|
+
this.logger.info(...args);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
this.warn = (...args) => {
|
|
60
|
+
var _a, _b;
|
|
61
|
+
if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
|
|
62
|
+
this.logger.warn(...args);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/set-state.ts
|
|
69
|
+
function setState(token, value, store = IMPLICIT.STORE) {
|
|
70
|
+
var _a;
|
|
71
|
+
const rejection = openOperation(token, store);
|
|
72
|
+
if (rejection) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
|
|
76
|
+
if (state === void 0) {
|
|
77
|
+
throw new NotFoundError(token, store);
|
|
78
|
+
}
|
|
79
|
+
setAtomOrSelector(state, value, store);
|
|
80
|
+
closeOperation(store);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/transaction.ts
|
|
84
|
+
var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
|
|
85
|
+
const tx = withdraw(token, store);
|
|
86
|
+
if (tx) {
|
|
87
|
+
return tx.run(...parameters);
|
|
88
|
+
}
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// internal/src/future.ts
|
|
27
95
|
var Future = class extends Promise {
|
|
28
96
|
constructor(executor) {
|
|
29
97
|
super((resolve, reject) => {
|
|
@@ -42,7 +110,7 @@ var Future = class extends Promise {
|
|
|
42
110
|
}
|
|
43
111
|
};
|
|
44
112
|
|
|
45
|
-
// src/lineage.ts
|
|
113
|
+
// internal/src/lineage.ts
|
|
46
114
|
function newest(scion) {
|
|
47
115
|
while (scion.child !== null) {
|
|
48
116
|
scion = scion.child;
|
|
@@ -56,7 +124,7 @@ function eldest(scion) {
|
|
|
56
124
|
return scion;
|
|
57
125
|
}
|
|
58
126
|
|
|
59
|
-
// src/caching.ts
|
|
127
|
+
// internal/src/caching.ts
|
|
60
128
|
function cacheValue(key, value, subject, store) {
|
|
61
129
|
const target = newest(store);
|
|
62
130
|
const currentValue = target.valueMap.get(key);
|
|
@@ -100,165 +168,348 @@ var evictCachedValue = (key, store) => {
|
|
|
100
168
|
core.valueMap.delete(key);
|
|
101
169
|
store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
|
|
102
170
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
171
|
+
|
|
172
|
+
// ../anvl/src/json/index.ts
|
|
173
|
+
var parseJson = (str) => JSON.parse(str);
|
|
174
|
+
var stringifyJson = (json) => JSON.stringify(json);
|
|
175
|
+
|
|
176
|
+
// json/src/select-json.ts
|
|
177
|
+
var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
|
|
178
|
+
return createSelector(
|
|
179
|
+
{
|
|
180
|
+
key: `${atom.key}:JSON`,
|
|
181
|
+
get: ({ get }) => transform.toJson(get(atom)),
|
|
182
|
+
set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
|
|
183
|
+
},
|
|
184
|
+
void 0,
|
|
185
|
+
store
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
// json/src/select-json-family.ts
|
|
190
|
+
var selectJsonFamily = (atomFamily, transform, store = IMPLICIT.STORE) => {
|
|
191
|
+
const jsonFamily = createSelectorFamily(
|
|
192
|
+
{
|
|
193
|
+
key: `${atomFamily.key}:JSON`,
|
|
194
|
+
get: (key) => ({ get }) => transform.toJson(get(atomFamily(key))),
|
|
195
|
+
set: (key) => ({ set }, newValue) => set(atomFamily(key), transform.fromJson(newValue))
|
|
196
|
+
},
|
|
197
|
+
store
|
|
198
|
+
);
|
|
199
|
+
atomFamily.subject.subscribe(
|
|
200
|
+
`store=${store.config.name}::json-selector-family`,
|
|
201
|
+
(token) => {
|
|
202
|
+
if (token.family) {
|
|
203
|
+
jsonFamily(parseJson(token.family.subKey));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
return jsonFamily;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// internal/src/read-or-compute-value.ts
|
|
211
|
+
var readOrComputeValue = (state, store) => {
|
|
212
|
+
if (isValueCached(state.key, store)) {
|
|
213
|
+
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
214
|
+
return readCachedValue(state.key, store);
|
|
112
215
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
216
|
+
if (state.type !== `atom`) {
|
|
217
|
+
store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
|
|
218
|
+
return state.get();
|
|
219
|
+
}
|
|
220
|
+
const fallback = state.default instanceof Function ? state.default() : state.default;
|
|
221
|
+
store.logger.info(
|
|
222
|
+
`\u{1F481}`,
|
|
223
|
+
`atom`,
|
|
224
|
+
state.key,
|
|
225
|
+
`could not find cached value; using default`,
|
|
226
|
+
fallback
|
|
227
|
+
);
|
|
228
|
+
return state.default instanceof Function ? state.default() : state.default;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
// internal/src/operation.ts
|
|
232
|
+
var openOperation = (token, store) => {
|
|
233
|
+
const target = newest(store);
|
|
234
|
+
if (target.operation.open) {
|
|
235
|
+
store.logger.error(
|
|
236
|
+
`\u274C`,
|
|
237
|
+
token.type,
|
|
238
|
+
token.key,
|
|
239
|
+
`failed to setState during a setState for "${target.operation.token.key}"`
|
|
127
240
|
);
|
|
128
|
-
return
|
|
241
|
+
return `rejection`;
|
|
129
242
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
243
|
+
target.operation = {
|
|
244
|
+
open: true,
|
|
245
|
+
done: /* @__PURE__ */ new Set(),
|
|
246
|
+
prev: /* @__PURE__ */ new Map(),
|
|
247
|
+
time: Date.now(),
|
|
248
|
+
token
|
|
249
|
+
};
|
|
250
|
+
store.logger.info(
|
|
251
|
+
`\u2B55`,
|
|
252
|
+
token.type,
|
|
253
|
+
token.key,
|
|
254
|
+
`operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
|
|
255
|
+
);
|
|
256
|
+
};
|
|
257
|
+
var closeOperation = (store) => {
|
|
258
|
+
const target = newest(store);
|
|
259
|
+
if (target.operation.open) {
|
|
260
|
+
store.logger.info(
|
|
261
|
+
`\u{1F534}`,
|
|
262
|
+
target.operation.token.type,
|
|
263
|
+
target.operation.token.key,
|
|
264
|
+
`operation done in store "${store.config.name}"`
|
|
144
265
|
);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
() => {
|
|
158
|
-
unsubscribe();
|
|
159
|
-
atom_io.setState(latestUpdateState, update2, store);
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
`${store.config.name}: tracker observing inner value`,
|
|
167
|
-
store
|
|
266
|
+
}
|
|
267
|
+
target.operation = { open: false };
|
|
268
|
+
store.subject.operationStatus.next(target.operation);
|
|
269
|
+
};
|
|
270
|
+
var isDone = (key, store) => {
|
|
271
|
+
const target = newest(store);
|
|
272
|
+
if (!target.operation.open) {
|
|
273
|
+
store.logger.warn(
|
|
274
|
+
`\u{1F41E}`,
|
|
275
|
+
`unknown`,
|
|
276
|
+
key,
|
|
277
|
+
`isDone called outside of an operation. This is probably a bug.`
|
|
168
278
|
);
|
|
279
|
+
return true;
|
|
169
280
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
const unsubscribe2 = atom_io.subscribeToTimeline(
|
|
181
|
-
{ key: timelineId, type: `timeline` },
|
|
182
|
-
(update) => {
|
|
183
|
-
unsubscribe2();
|
|
184
|
-
atom_io.setState(
|
|
185
|
-
mutableState,
|
|
186
|
-
(transceiver) => {
|
|
187
|
-
if (update === `redo` && newValue) {
|
|
188
|
-
transceiver.do(newValue);
|
|
189
|
-
} else if (update === `undo` && oldValue) {
|
|
190
|
-
transceiver.undo(oldValue);
|
|
191
|
-
}
|
|
192
|
-
return transceiver;
|
|
193
|
-
},
|
|
194
|
-
store
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
);
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
202
|
-
latestUpdateState.key,
|
|
203
|
-
() => {
|
|
204
|
-
unsubscribe();
|
|
205
|
-
const mutable = atom_io.getState(mutableState, store);
|
|
206
|
-
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
207
|
-
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
208
|
-
if (newValue && eventOffset === 1) {
|
|
209
|
-
atom_io.setState(
|
|
210
|
-
mutableState,
|
|
211
|
-
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
212
|
-
store
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
);
|
|
217
|
-
},
|
|
218
|
-
`${store.config.name}: tracker observing latest update`,
|
|
219
|
-
store
|
|
281
|
+
return target.operation.done.has(key);
|
|
282
|
+
};
|
|
283
|
+
var markDone = (key, store) => {
|
|
284
|
+
const target = newest(store);
|
|
285
|
+
if (!target.operation.open) {
|
|
286
|
+
store.logger.warn(
|
|
287
|
+
`\u{1F41E}`,
|
|
288
|
+
`unknown`,
|
|
289
|
+
key,
|
|
290
|
+
`markDone called outside of an operation. This is probably a bug.`
|
|
220
291
|
);
|
|
292
|
+
return;
|
|
221
293
|
}
|
|
294
|
+
target.operation.done.add(key);
|
|
222
295
|
};
|
|
223
296
|
|
|
224
|
-
// src/
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
`atom`,
|
|
229
|
-
options.key,
|
|
230
|
-
`creating in store "${store.config.name}"`
|
|
231
|
-
);
|
|
232
|
-
const coreState = createAtom(options, void 0, store);
|
|
233
|
-
new Tracker(coreState, store);
|
|
234
|
-
const jsonState = json.selectJson(coreState, options, store);
|
|
235
|
-
const target = newest(store);
|
|
236
|
-
atom_io.subscribe(
|
|
237
|
-
jsonState,
|
|
238
|
-
() => {
|
|
239
|
-
const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
|
|
240
|
-
if (!trackerHasBeenInitialized) {
|
|
241
|
-
new Tracker(coreState, store);
|
|
242
|
-
}
|
|
243
|
-
},
|
|
244
|
-
`tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`
|
|
245
|
-
);
|
|
246
|
-
return coreState;
|
|
247
|
-
}
|
|
297
|
+
// internal/src/set-state/become.ts
|
|
298
|
+
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
299
|
+
originalThing instanceof Function ? originalThing() : originalThing
|
|
300
|
+
) : nextVersionOfThing;
|
|
248
301
|
|
|
249
|
-
// src/
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
type: state.type
|
|
254
|
-
};
|
|
255
|
-
if (`family` in state) {
|
|
256
|
-
token.family = state.family;
|
|
302
|
+
// internal/src/subject.ts
|
|
303
|
+
var Subject = class {
|
|
304
|
+
constructor() {
|
|
305
|
+
this.subscribers = /* @__PURE__ */ new Map();
|
|
257
306
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
307
|
+
subscribe(key, subscriber) {
|
|
308
|
+
this.subscribers.set(key, subscriber);
|
|
309
|
+
const unsubscribe = () => this.unsubscribe(key);
|
|
310
|
+
return unsubscribe;
|
|
311
|
+
}
|
|
312
|
+
unsubscribe(key) {
|
|
313
|
+
this.subscribers.delete(key);
|
|
314
|
+
}
|
|
315
|
+
next(value) {
|
|
316
|
+
for (const subscriber of this.subscribers.values()) {
|
|
317
|
+
subscriber(value);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var StatefulSubject = class extends Subject {
|
|
322
|
+
constructor(initialState) {
|
|
323
|
+
super();
|
|
324
|
+
this.state = initialState;
|
|
325
|
+
}
|
|
326
|
+
next(value) {
|
|
327
|
+
this.state = value;
|
|
328
|
+
super.next(value);
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
333
|
+
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
334
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
335
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
336
|
+
if (originValue === targetValue) {
|
|
337
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
338
|
+
const jsonValue = transform.toJson(originValue);
|
|
339
|
+
const copiedValue = transform.fromJson(jsonValue);
|
|
340
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
341
|
+
new Tracker(atom, origin);
|
|
342
|
+
return copiedValue;
|
|
343
|
+
}
|
|
344
|
+
return targetValue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
348
|
+
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
349
|
+
const target = newest(store);
|
|
350
|
+
const parent = target.parent;
|
|
351
|
+
if (parent !== null) {
|
|
352
|
+
if (`toJson` in atom && `fromJson` in atom) {
|
|
353
|
+
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
354
|
+
return copiedValue;
|
|
355
|
+
}
|
|
356
|
+
if (`family` in atom) {
|
|
357
|
+
const family = parent.families.get(atom.family.key);
|
|
358
|
+
if (family && family.type === `atom_family`) {
|
|
359
|
+
const result = copyMutableFamilyMemberWithinTransaction(
|
|
360
|
+
atom,
|
|
361
|
+
family,
|
|
362
|
+
parent,
|
|
363
|
+
target
|
|
364
|
+
);
|
|
365
|
+
if (result) {
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return oldValue;
|
|
372
|
+
}
|
|
373
|
+
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
374
|
+
if (`toJson` in family && `fromJson` in family) {
|
|
375
|
+
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
376
|
+
return copyCreated;
|
|
377
|
+
}
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// internal/src/set-state/emit-update.ts
|
|
382
|
+
var emitUpdate = (state, update, store) => {
|
|
383
|
+
store.logger.info(
|
|
384
|
+
`\u{1F4E2}`,
|
|
385
|
+
state.type,
|
|
386
|
+
state.key,
|
|
387
|
+
`went (`,
|
|
388
|
+
update.oldValue,
|
|
389
|
+
`->`,
|
|
390
|
+
update.newValue,
|
|
391
|
+
`) subscribers:`,
|
|
392
|
+
state.subject.subscribers
|
|
393
|
+
);
|
|
394
|
+
state.subject.next(update);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
// internal/src/set-state/evict-downstream.ts
|
|
398
|
+
var evictDownStream = (atom, store) => {
|
|
399
|
+
const target = newest(store);
|
|
400
|
+
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
|
|
401
|
+
store.logger.info(
|
|
402
|
+
`\u{1F9F9}`,
|
|
403
|
+
atom.type,
|
|
404
|
+
atom.key,
|
|
405
|
+
downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
|
|
406
|
+
downstreamKeys != null ? downstreamKeys : `to evict`
|
|
407
|
+
);
|
|
408
|
+
if (downstreamKeys) {
|
|
409
|
+
if (target.operation.open) {
|
|
410
|
+
store.logger.info(
|
|
411
|
+
`\u{1F9F9}`,
|
|
412
|
+
atom.type,
|
|
413
|
+
atom.key,
|
|
414
|
+
`[ ${[...target.operation.done].join(`, `)} ] already done`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
for (const key of downstreamKeys) {
|
|
418
|
+
if (isDone(key, store)) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
evictCachedValue(key, store);
|
|
422
|
+
markDone(key, store);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
// internal/src/set-state/stow-update.ts
|
|
428
|
+
function shouldUpdateBeStowed(key, update) {
|
|
429
|
+
if (isTransceiver(update.newValue)) {
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
433
|
+
return false;
|
|
434
|
+
}
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
var stowUpdate = (state, update, store) => {
|
|
438
|
+
const { key } = state;
|
|
439
|
+
const target = newest(store);
|
|
440
|
+
if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
|
|
441
|
+
store.logger.error(
|
|
442
|
+
`\u{1F41E}`,
|
|
443
|
+
`atom`,
|
|
444
|
+
key,
|
|
445
|
+
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
446
|
+
);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const shouldStow = shouldUpdateBeStowed(key, update);
|
|
450
|
+
if (!shouldStow) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const atomUpdate = __spreadValues({ key }, update);
|
|
454
|
+
if (state.family) {
|
|
455
|
+
atomUpdate.family = state.family;
|
|
456
|
+
}
|
|
457
|
+
target.transactionMeta.update.updates.push(atomUpdate);
|
|
458
|
+
store.logger.info(
|
|
459
|
+
`\u{1F4C1}`,
|
|
460
|
+
`atom`,
|
|
461
|
+
key,
|
|
462
|
+
`stowed (`,
|
|
463
|
+
update.oldValue,
|
|
464
|
+
`->`,
|
|
465
|
+
update.newValue,
|
|
466
|
+
`)`
|
|
467
|
+
);
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
// internal/src/set-state/set-atom.ts
|
|
471
|
+
var setAtom = (atom, next, store) => {
|
|
472
|
+
const target = newest(store);
|
|
473
|
+
const oldValue = readOrComputeValue(atom, store);
|
|
474
|
+
let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
|
|
475
|
+
newValue = become(next)(newValue);
|
|
476
|
+
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
477
|
+
newValue = cacheValue(atom.key, newValue, atom.subject, store);
|
|
478
|
+
if (isAtomDefault(atom.key, store)) {
|
|
479
|
+
markAtomAsNotDefault(atom.key, store);
|
|
480
|
+
}
|
|
481
|
+
markDone(atom.key, store);
|
|
482
|
+
evictDownStream(atom, store);
|
|
483
|
+
const update = { oldValue, newValue };
|
|
484
|
+
if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
|
|
485
|
+
emitUpdate(atom, update, store);
|
|
486
|
+
} else {
|
|
487
|
+
stowUpdate(atom, update, store);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
// internal/src/set-state/set-atom-or-selector.ts
|
|
492
|
+
var setAtomOrSelector = (state, value, store) => {
|
|
493
|
+
if (state.type === `selector`) {
|
|
494
|
+
state.set(value);
|
|
495
|
+
} else {
|
|
496
|
+
setAtom(state, value, store);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
// internal/src/store/deposit.ts
|
|
501
|
+
function deposit(state) {
|
|
502
|
+
const token = {
|
|
503
|
+
key: state.key,
|
|
504
|
+
type: state.type
|
|
505
|
+
};
|
|
506
|
+
if (`family` in state) {
|
|
507
|
+
token.family = state.family;
|
|
508
|
+
}
|
|
509
|
+
return token;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// ../rel8/junction/src/junction.ts
|
|
262
513
|
var Junction = class {
|
|
263
514
|
constructor(data, config) {
|
|
264
515
|
this.relations = /* @__PURE__ */ new Map();
|
|
@@ -516,37 +767,7 @@ var Junction = class {
|
|
|
516
767
|
}
|
|
517
768
|
};
|
|
518
769
|
|
|
519
|
-
// src/
|
|
520
|
-
var Subject = class {
|
|
521
|
-
constructor() {
|
|
522
|
-
this.subscribers = /* @__PURE__ */ new Map();
|
|
523
|
-
}
|
|
524
|
-
subscribe(key, subscriber) {
|
|
525
|
-
this.subscribers.set(key, subscriber);
|
|
526
|
-
const unsubscribe = () => this.unsubscribe(key);
|
|
527
|
-
return unsubscribe;
|
|
528
|
-
}
|
|
529
|
-
unsubscribe(key) {
|
|
530
|
-
this.subscribers.delete(key);
|
|
531
|
-
}
|
|
532
|
-
next(value) {
|
|
533
|
-
for (const subscriber of this.subscribers.values()) {
|
|
534
|
-
subscriber(value);
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
|
-
var StatefulSubject = class extends Subject {
|
|
539
|
-
constructor(initialState) {
|
|
540
|
-
super();
|
|
541
|
-
this.state = initialState;
|
|
542
|
-
}
|
|
543
|
-
next(value) {
|
|
544
|
-
this.state = value;
|
|
545
|
-
super.next(value);
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
// src/store/store.ts
|
|
770
|
+
// internal/src/store/store.ts
|
|
550
771
|
var Store = class {
|
|
551
772
|
constructor(name, store = null) {
|
|
552
773
|
this.parent = null;
|
|
@@ -591,7 +812,7 @@ var Store = class {
|
|
|
591
812
|
name: `IMPLICIT_STORE`
|
|
592
813
|
};
|
|
593
814
|
this.loggers = [
|
|
594
|
-
new
|
|
815
|
+
new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
|
|
595
816
|
];
|
|
596
817
|
this.logger = {
|
|
597
818
|
error: (...messages) => {
|
|
@@ -645,7 +866,7 @@ var clearStore = (store) => {
|
|
|
645
866
|
store.config = config;
|
|
646
867
|
};
|
|
647
868
|
|
|
648
|
-
// src/store/withdraw.ts
|
|
869
|
+
// internal/src/store/withdraw.ts
|
|
649
870
|
function withdraw(token, store) {
|
|
650
871
|
var _a, _b, _c, _d;
|
|
651
872
|
const target = newest(store);
|
|
@@ -656,7 +877,7 @@ function withdraw(token, store) {
|
|
|
656
877
|
return void 0;
|
|
657
878
|
}
|
|
658
879
|
|
|
659
|
-
// src/store/withdraw-new-family-member.ts
|
|
880
|
+
// internal/src/store/withdraw-new-family-member.ts
|
|
660
881
|
function withdrawNewFamilyMember(token, store) {
|
|
661
882
|
if (token.family) {
|
|
662
883
|
store.logger.info(
|
|
@@ -674,318 +895,22 @@ function withdrawNewFamilyMember(token, store) {
|
|
|
674
895
|
return state;
|
|
675
896
|
}
|
|
676
897
|
}
|
|
677
|
-
return void 0;
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// src/families/create-atom-family.ts
|
|
681
|
-
function createAtomFamily(options, store) {
|
|
682
|
-
const subject = new Subject();
|
|
683
|
-
const atomFamily = Object.assign(
|
|
684
|
-
(key) => {
|
|
685
|
-
const subKey = json.stringifyJson(key);
|
|
686
|
-
const family = { key: options.key, subKey };
|
|
687
|
-
const fullKey = `${options.key}(${subKey})`;
|
|
688
|
-
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
689
|
-
let token;
|
|
690
|
-
if (existing) {
|
|
691
|
-
token = deposit(existing);
|
|
692
|
-
} else {
|
|
693
|
-
const individualOptions = {
|
|
694
|
-
key: fullKey,
|
|
695
|
-
default: options.default instanceof Function ? options.default(key) : options.default
|
|
696
|
-
};
|
|
697
|
-
if (options.effects) {
|
|
698
|
-
individualOptions.effects = options.effects(key);
|
|
699
|
-
}
|
|
700
|
-
token = createAtom(individualOptions, family, store);
|
|
701
|
-
subject.next(token);
|
|
702
|
-
}
|
|
703
|
-
return token;
|
|
704
|
-
},
|
|
705
|
-
{
|
|
706
|
-
key: options.key,
|
|
707
|
-
type: `atom_family`,
|
|
708
|
-
subject
|
|
709
|
-
}
|
|
710
|
-
);
|
|
711
|
-
const target = newest(store);
|
|
712
|
-
target.families.set(options.key, atomFamily);
|
|
713
|
-
return atomFamily;
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
// src/operation.ts
|
|
717
|
-
var openOperation = (token, store) => {
|
|
718
|
-
const target = newest(store);
|
|
719
|
-
if (target.operation.open) {
|
|
720
|
-
store.logger.error(
|
|
721
|
-
`\u274C`,
|
|
722
|
-
token.type,
|
|
723
|
-
token.key,
|
|
724
|
-
`failed to setState during a setState for "${target.operation.token.key}"`
|
|
725
|
-
);
|
|
726
|
-
return `rejection`;
|
|
727
|
-
}
|
|
728
|
-
target.operation = {
|
|
729
|
-
open: true,
|
|
730
|
-
done: /* @__PURE__ */ new Set(),
|
|
731
|
-
prev: /* @__PURE__ */ new Map(),
|
|
732
|
-
time: Date.now(),
|
|
733
|
-
token
|
|
734
|
-
};
|
|
735
|
-
store.logger.info(
|
|
736
|
-
`\u2B55`,
|
|
737
|
-
token.type,
|
|
738
|
-
token.key,
|
|
739
|
-
`operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
|
|
740
|
-
);
|
|
741
|
-
};
|
|
742
|
-
var closeOperation = (store) => {
|
|
743
|
-
const target = newest(store);
|
|
744
|
-
if (target.operation.open) {
|
|
745
|
-
store.logger.info(
|
|
746
|
-
`\u{1F534}`,
|
|
747
|
-
target.operation.token.type,
|
|
748
|
-
target.operation.token.key,
|
|
749
|
-
`operation done in store "${store.config.name}"`
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
target.operation = { open: false };
|
|
753
|
-
store.subject.operationStatus.next(target.operation);
|
|
754
|
-
};
|
|
755
|
-
var isDone = (key, store) => {
|
|
756
|
-
const target = newest(store);
|
|
757
|
-
if (!target.operation.open) {
|
|
758
|
-
store.logger.warn(
|
|
759
|
-
`\u{1F41E}`,
|
|
760
|
-
`unknown`,
|
|
761
|
-
key,
|
|
762
|
-
`isDone called outside of an operation. This is probably a bug.`
|
|
763
|
-
);
|
|
764
|
-
return true;
|
|
765
|
-
}
|
|
766
|
-
return target.operation.done.has(key);
|
|
767
|
-
};
|
|
768
|
-
var markDone = (key, store) => {
|
|
769
|
-
const target = newest(store);
|
|
770
|
-
if (!target.operation.open) {
|
|
771
|
-
store.logger.warn(
|
|
772
|
-
`\u{1F41E}`,
|
|
773
|
-
`unknown`,
|
|
774
|
-
key,
|
|
775
|
-
`markDone called outside of an operation. This is probably a bug.`
|
|
776
|
-
);
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
target.operation.done.add(key);
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
// src/set-state/become.ts
|
|
783
|
-
var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
|
|
784
|
-
originalThing instanceof Function ? originalThing() : originalThing
|
|
785
|
-
) : nextVersionOfThing;
|
|
786
|
-
|
|
787
|
-
// src/read-or-compute-value.ts
|
|
788
|
-
var readOrComputeValue = (state, store) => {
|
|
789
|
-
if (isValueCached(state.key, store)) {
|
|
790
|
-
store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
791
|
-
return readCachedValue(state.key, store);
|
|
792
|
-
}
|
|
793
|
-
if (state.type !== `atom`) {
|
|
794
|
-
store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
|
|
795
|
-
return state.get();
|
|
796
|
-
}
|
|
797
|
-
const fallback = state.default instanceof Function ? state.default() : state.default;
|
|
798
|
-
store.logger.info(
|
|
799
|
-
`\u{1F481}`,
|
|
800
|
-
`atom`,
|
|
801
|
-
state.key,
|
|
802
|
-
`could not find cached value; using default`,
|
|
803
|
-
fallback
|
|
804
|
-
);
|
|
805
|
-
return state.default instanceof Function ? state.default() : state.default;
|
|
806
|
-
};
|
|
807
|
-
|
|
808
|
-
// src/set-state/copy-mutable-if-needed.ts
|
|
809
|
-
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
810
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
811
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
812
|
-
if (originValue === targetValue) {
|
|
813
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
814
|
-
const jsonValue = transform.toJson(originValue);
|
|
815
|
-
const copiedValue = transform.fromJson(jsonValue);
|
|
816
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
817
|
-
new Tracker(atom, origin);
|
|
818
|
-
return copiedValue;
|
|
819
|
-
}
|
|
820
|
-
return targetValue;
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
// src/set-state/copy-mutable-in-transaction.ts
|
|
824
|
-
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
825
|
-
const target = newest(store);
|
|
826
|
-
const parent = target.parent;
|
|
827
|
-
if (parent !== null) {
|
|
828
|
-
if (`toJson` in atom && `fromJson` in atom) {
|
|
829
|
-
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
830
|
-
return copiedValue;
|
|
831
|
-
}
|
|
832
|
-
if (`family` in atom) {
|
|
833
|
-
const family = parent.families.get(atom.family.key);
|
|
834
|
-
if (family && family.type === `atom_family`) {
|
|
835
|
-
const result = copyMutableFamilyMemberWithinTransaction(
|
|
836
|
-
atom,
|
|
837
|
-
family,
|
|
838
|
-
parent,
|
|
839
|
-
target
|
|
840
|
-
);
|
|
841
|
-
if (result) {
|
|
842
|
-
return result;
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
return oldValue;
|
|
848
|
-
}
|
|
849
|
-
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
850
|
-
if (`toJson` in family && `fromJson` in family) {
|
|
851
|
-
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
852
|
-
return copyCreated;
|
|
853
|
-
}
|
|
854
|
-
return null;
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
// src/set-state/emit-update.ts
|
|
858
|
-
var emitUpdate = (state, update, store) => {
|
|
859
|
-
store.logger.info(
|
|
860
|
-
`\u{1F4E2}`,
|
|
861
|
-
state.type,
|
|
862
|
-
state.key,
|
|
863
|
-
`went (`,
|
|
864
|
-
update.oldValue,
|
|
865
|
-
`->`,
|
|
866
|
-
update.newValue,
|
|
867
|
-
`) subscribers:`,
|
|
868
|
-
state.subject.subscribers
|
|
869
|
-
);
|
|
870
|
-
state.subject.next(update);
|
|
871
|
-
};
|
|
872
|
-
|
|
873
|
-
// src/set-state/evict-downstream.ts
|
|
874
|
-
var evictDownStream = (atom, store) => {
|
|
875
|
-
const target = newest(store);
|
|
876
|
-
const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
|
|
877
|
-
store.logger.info(
|
|
878
|
-
`\u{1F9F9}`,
|
|
879
|
-
atom.type,
|
|
880
|
-
atom.key,
|
|
881
|
-
downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
|
|
882
|
-
downstreamKeys != null ? downstreamKeys : `to evict`
|
|
883
|
-
);
|
|
884
|
-
if (downstreamKeys) {
|
|
885
|
-
if (target.operation.open) {
|
|
886
|
-
store.logger.info(
|
|
887
|
-
`\u{1F9F9}`,
|
|
888
|
-
atom.type,
|
|
889
|
-
atom.key,
|
|
890
|
-
`[ ${[...target.operation.done].join(`, `)} ] already done`
|
|
891
|
-
);
|
|
892
|
-
}
|
|
893
|
-
for (const key of downstreamKeys) {
|
|
894
|
-
if (isDone(key, store)) {
|
|
895
|
-
continue;
|
|
896
|
-
}
|
|
897
|
-
evictCachedValue(key, store);
|
|
898
|
-
markDone(key, store);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
};
|
|
902
|
-
|
|
903
|
-
// src/set-state/stow-update.ts
|
|
904
|
-
function shouldUpdateBeStowed(key, update) {
|
|
905
|
-
if (isTransceiver(update.newValue)) {
|
|
906
|
-
return false;
|
|
907
|
-
}
|
|
908
|
-
if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
|
|
909
|
-
return false;
|
|
910
|
-
}
|
|
911
|
-
return true;
|
|
912
|
-
}
|
|
913
|
-
var stowUpdate = (state, update, store) => {
|
|
914
|
-
const { key } = state;
|
|
915
|
-
const target = newest(store);
|
|
916
|
-
if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
|
|
917
|
-
store.logger.error(
|
|
918
|
-
`\u{1F41E}`,
|
|
919
|
-
`atom`,
|
|
920
|
-
key,
|
|
921
|
-
`stowUpdate called outside of a transaction. This is probably a bug.`
|
|
922
|
-
);
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
const shouldStow = shouldUpdateBeStowed(key, update);
|
|
926
|
-
if (!shouldStow) {
|
|
927
|
-
return;
|
|
928
|
-
}
|
|
929
|
-
const atomUpdate = __spreadValues({ key }, update);
|
|
930
|
-
if (state.family) {
|
|
931
|
-
atomUpdate.family = state.family;
|
|
932
|
-
}
|
|
933
|
-
target.transactionMeta.update.updates.push(atomUpdate);
|
|
934
|
-
store.logger.info(
|
|
935
|
-
`\u{1F4C1}`,
|
|
936
|
-
`atom`,
|
|
937
|
-
key,
|
|
938
|
-
`stowed (`,
|
|
939
|
-
update.oldValue,
|
|
940
|
-
`->`,
|
|
941
|
-
update.newValue,
|
|
942
|
-
`)`
|
|
943
|
-
);
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
// src/set-state/set-atom.ts
|
|
947
|
-
var setAtom = (atom, next, store) => {
|
|
948
|
-
const target = newest(store);
|
|
949
|
-
const oldValue = readOrComputeValue(atom, store);
|
|
950
|
-
let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
|
|
951
|
-
newValue = become(next)(newValue);
|
|
952
|
-
store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
|
|
953
|
-
newValue = cacheValue(atom.key, newValue, atom.subject, store);
|
|
954
|
-
if (isAtomDefault(atom.key, store)) {
|
|
955
|
-
markAtomAsNotDefault(atom.key, store);
|
|
956
|
-
}
|
|
957
|
-
markDone(atom.key, store);
|
|
958
|
-
evictDownStream(atom, store);
|
|
959
|
-
const update = { oldValue, newValue };
|
|
960
|
-
if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
|
|
961
|
-
emitUpdate(atom, update, store);
|
|
962
|
-
} else {
|
|
963
|
-
stowUpdate(atom, update, store);
|
|
964
|
-
}
|
|
965
|
-
};
|
|
966
|
-
|
|
967
|
-
// src/set-state/set-atom-or-selector.ts
|
|
968
|
-
var setAtomOrSelector = (state, value, store) => {
|
|
969
|
-
if (state.type === `selector`) {
|
|
970
|
-
state.set(value);
|
|
971
|
-
} else {
|
|
972
|
-
setAtom(state, value, store);
|
|
973
|
-
}
|
|
974
|
-
};
|
|
898
|
+
return void 0;
|
|
899
|
+
}
|
|
975
900
|
|
|
976
|
-
// src/keys.ts
|
|
901
|
+
// internal/src/keys.ts
|
|
977
902
|
var isAtomKey = (key, store) => newest(store).atoms.has(key);
|
|
978
903
|
var isSelectorKey = (key, store) => newest(store).selectors.has(key);
|
|
979
904
|
var isReadonlySelectorKey = (key, store) => newest(store).readonlySelectors.has(key);
|
|
980
905
|
var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
|
|
981
906
|
|
|
982
|
-
// src/selector/get-selector-dependency-keys.ts
|
|
907
|
+
// internal/src/selector/get-selector-dependency-keys.ts
|
|
983
908
|
var getSelectorDependencyKeys = (key, store) => {
|
|
984
909
|
const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
|
|
985
910
|
return sources;
|
|
986
911
|
};
|
|
987
912
|
|
|
988
|
-
// src/selector/trace-selector-atoms.ts
|
|
913
|
+
// internal/src/selector/trace-selector-atoms.ts
|
|
989
914
|
var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
|
|
990
915
|
const rootKeys = [];
|
|
991
916
|
const indirectDependencyKeys = getSelectorDependencyKeys(
|
|
@@ -1018,11 +943,11 @@ var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
|
1018
943
|
);
|
|
1019
944
|
};
|
|
1020
945
|
|
|
1021
|
-
// src/selector/update-selector-atoms.ts
|
|
946
|
+
// internal/src/selector/update-selector-atoms.ts
|
|
1022
947
|
var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
1023
|
-
const
|
|
948
|
+
const target = newest(store);
|
|
1024
949
|
if (dependency.type === `atom`) {
|
|
1025
|
-
|
|
950
|
+
target.selectorAtoms.set({
|
|
1026
951
|
selectorKey,
|
|
1027
952
|
atomKey: dependency.key
|
|
1028
953
|
});
|
|
@@ -1041,7 +966,7 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1041
966
|
`discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
|
|
1042
967
|
);
|
|
1043
968
|
for (const atomKey of rootKeys) {
|
|
1044
|
-
|
|
969
|
+
target.selectorAtoms = target.selectorAtoms.set({
|
|
1045
970
|
selectorKey,
|
|
1046
971
|
atomKey
|
|
1047
972
|
});
|
|
@@ -1049,7 +974,7 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1049
974
|
}
|
|
1050
975
|
};
|
|
1051
976
|
|
|
1052
|
-
// src/selector/register-selector.ts
|
|
977
|
+
// internal/src/selector/register-selector.ts
|
|
1053
978
|
var registerSelector = (selectorKey, store) => ({
|
|
1054
979
|
get: (dependency) => {
|
|
1055
980
|
const target = newest(store);
|
|
@@ -1070,7 +995,7 @@ var registerSelector = (selectorKey, store) => ({
|
|
|
1070
995
|
`)`
|
|
1071
996
|
);
|
|
1072
997
|
if (!alreadyRegistered) {
|
|
1073
|
-
target.selectorGraph
|
|
998
|
+
target.selectorGraph.set(
|
|
1074
999
|
{
|
|
1075
1000
|
upstreamSelectorKey: dependency.key,
|
|
1076
1001
|
downstreamSelectorKey: selectorKey
|
|
@@ -1094,7 +1019,7 @@ var registerSelector = (selectorKey, store) => ({
|
|
|
1094
1019
|
}
|
|
1095
1020
|
});
|
|
1096
1021
|
|
|
1097
|
-
// src/selector/create-read-write-selector.ts
|
|
1022
|
+
// internal/src/selector/create-read-write-selector.ts
|
|
1098
1023
|
var createReadWriteSelector = (options, family, store) => {
|
|
1099
1024
|
const target = newest(store);
|
|
1100
1025
|
const subject = new Subject();
|
|
@@ -1117,125 +1042,442 @@ var createReadWriteSelector = (options, family, store) => {
|
|
|
1117
1042
|
newValue,
|
|
1118
1043
|
`)`
|
|
1119
1044
|
);
|
|
1120
|
-
cacheValue(options.key, newValue, subject, store);
|
|
1121
|
-
markDone(options.key, store);
|
|
1122
|
-
if (target.transactionMeta === null) {
|
|
1123
|
-
subject.next({ newValue, oldValue });
|
|
1124
|
-
}
|
|
1125
|
-
options.set({ get, set }, newValue);
|
|
1126
|
-
};
|
|
1127
|
-
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1128
|
-
subject,
|
|
1129
|
-
install: (s) => createSelector(options, family, s),
|
|
1130
|
-
get: getSelf,
|
|
1131
|
-
set: setSelf,
|
|
1132
|
-
type: `selector`
|
|
1133
|
-
}), family && { family });
|
|
1134
|
-
target.selectors.set(options.key, mySelector);
|
|
1135
|
-
const initialValue = getSelf();
|
|
1136
|
-
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1137
|
-
const token = {
|
|
1138
|
-
key: options.key,
|
|
1139
|
-
type: `selector`
|
|
1140
|
-
};
|
|
1141
|
-
if (family) {
|
|
1142
|
-
token.family = family;
|
|
1045
|
+
cacheValue(options.key, newValue, subject, store);
|
|
1046
|
+
markDone(options.key, store);
|
|
1047
|
+
if (target.transactionMeta === null) {
|
|
1048
|
+
subject.next({ newValue, oldValue });
|
|
1049
|
+
}
|
|
1050
|
+
options.set({ get, set }, newValue);
|
|
1051
|
+
};
|
|
1052
|
+
const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1053
|
+
subject,
|
|
1054
|
+
install: (s) => createSelector(options, family, s),
|
|
1055
|
+
get: getSelf,
|
|
1056
|
+
set: setSelf,
|
|
1057
|
+
type: `selector`
|
|
1058
|
+
}), family && { family });
|
|
1059
|
+
target.selectors.set(options.key, mySelector);
|
|
1060
|
+
const initialValue = getSelf();
|
|
1061
|
+
store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
|
|
1062
|
+
const token = {
|
|
1063
|
+
key: options.key,
|
|
1064
|
+
type: `selector`
|
|
1065
|
+
};
|
|
1066
|
+
if (family) {
|
|
1067
|
+
token.family = family;
|
|
1068
|
+
}
|
|
1069
|
+
store.subject.selectorCreation.next(token);
|
|
1070
|
+
return token;
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
// internal/src/selector/create-readonly-selector.ts
|
|
1074
|
+
var createReadonlySelector = (options, family, store) => {
|
|
1075
|
+
const target = newest(store);
|
|
1076
|
+
const subject = new Subject();
|
|
1077
|
+
const { get } = registerSelector(options.key, store);
|
|
1078
|
+
const getSelf = () => {
|
|
1079
|
+
const value = options.get({ get });
|
|
1080
|
+
cacheValue(options.key, value, subject, store);
|
|
1081
|
+
return value;
|
|
1082
|
+
};
|
|
1083
|
+
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1084
|
+
subject,
|
|
1085
|
+
install: (s) => createSelector(options, family, s),
|
|
1086
|
+
get: getSelf,
|
|
1087
|
+
type: `readonly_selector`
|
|
1088
|
+
}), family && { family });
|
|
1089
|
+
target.readonlySelectors.set(options.key, readonlySelector);
|
|
1090
|
+
const initialValue = getSelf();
|
|
1091
|
+
store.logger.info(
|
|
1092
|
+
`\u2728`,
|
|
1093
|
+
readonlySelector.type,
|
|
1094
|
+
readonlySelector.key,
|
|
1095
|
+
`=`,
|
|
1096
|
+
initialValue
|
|
1097
|
+
);
|
|
1098
|
+
const token = {
|
|
1099
|
+
key: options.key,
|
|
1100
|
+
type: `readonly_selector`
|
|
1101
|
+
};
|
|
1102
|
+
if (family) {
|
|
1103
|
+
token.family = family;
|
|
1104
|
+
}
|
|
1105
|
+
store.subject.selectorCreation.next(token);
|
|
1106
|
+
return token;
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
// internal/src/selector/create-selector.ts
|
|
1110
|
+
function createSelector(options, family, store) {
|
|
1111
|
+
const target = newest(store);
|
|
1112
|
+
const existingWritable = target.selectors.get(options.key);
|
|
1113
|
+
const existingReadonly = target.readonlySelectors.get(options.key);
|
|
1114
|
+
if (existingWritable || existingReadonly) {
|
|
1115
|
+
store.logger.error(
|
|
1116
|
+
`\u274C`,
|
|
1117
|
+
existingReadonly ? `readonly_selector` : `selector`,
|
|
1118
|
+
options.key,
|
|
1119
|
+
`Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
if (`set` in options) {
|
|
1123
|
+
return createReadWriteSelector(options, family, store);
|
|
1124
|
+
}
|
|
1125
|
+
return createReadonlySelector(options, family, store);
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// internal/src/selector/delete-selector.ts
|
|
1129
|
+
function deleteSelector(selectorToken, store) {
|
|
1130
|
+
const target = newest(store);
|
|
1131
|
+
const { key } = selectorToken;
|
|
1132
|
+
switch (selectorToken.type) {
|
|
1133
|
+
case `selector`:
|
|
1134
|
+
target.selectors.delete(key);
|
|
1135
|
+
break;
|
|
1136
|
+
case `readonly_selector`:
|
|
1137
|
+
target.readonlySelectors.delete(key);
|
|
1138
|
+
break;
|
|
1139
|
+
}
|
|
1140
|
+
target.valueMap.delete(key);
|
|
1141
|
+
target.selectorAtoms.delete(key);
|
|
1142
|
+
const downstreamTokens = target.selectorGraph.getRelationEntries({ upstreamSelectorKey: key }).filter(([_, { source }]) => source === key).map(
|
|
1143
|
+
([downstreamSelectorKey]) => {
|
|
1144
|
+
var _a;
|
|
1145
|
+
return (_a = target.selectors.get(downstreamSelectorKey)) != null ? _a : target.readonlySelectors.get(downstreamSelectorKey);
|
|
1146
|
+
}
|
|
1147
|
+
);
|
|
1148
|
+
for (const downstreamToken of downstreamTokens) {
|
|
1149
|
+
if (downstreamToken) {
|
|
1150
|
+
deleteSelector(downstreamToken, store);
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
target.selectorGraph.delete(key);
|
|
1154
|
+
store.logger.info(`\u{1F525}`, selectorToken.type, `${key}`, `deleted`);
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
// internal/src/subscribe/recall-state.ts
|
|
1158
|
+
var recallState = (state, store) => {
|
|
1159
|
+
const target = newest(store);
|
|
1160
|
+
if (!target.operation.open) {
|
|
1161
|
+
return target.valueMap.get(state.key);
|
|
1162
|
+
}
|
|
1163
|
+
return target.operation.prev.get(state.key);
|
|
1164
|
+
};
|
|
1165
|
+
|
|
1166
|
+
// internal/src/subscribe/subscribe-to-root-atoms.ts
|
|
1167
|
+
var subscribeToRootAtoms = (state, store) => {
|
|
1168
|
+
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1169
|
+
const atom = store.atoms.get(atomKey);
|
|
1170
|
+
if (atom === void 0) {
|
|
1171
|
+
throw new Error(
|
|
1172
|
+
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
return atom.subject.subscribe(
|
|
1176
|
+
`${state.type}:${state.key}`,
|
|
1177
|
+
(atomChange) => {
|
|
1178
|
+
store.logger.info(
|
|
1179
|
+
`\u{1F4E2}`,
|
|
1180
|
+
state.type,
|
|
1181
|
+
state.key,
|
|
1182
|
+
`root`,
|
|
1183
|
+
atomKey,
|
|
1184
|
+
`went`,
|
|
1185
|
+
atomChange.oldValue,
|
|
1186
|
+
`->`,
|
|
1187
|
+
atomChange.newValue
|
|
1188
|
+
);
|
|
1189
|
+
const oldValue = recallState(state, store);
|
|
1190
|
+
const newValue = readOrComputeValue(state, store);
|
|
1191
|
+
store.logger.info(
|
|
1192
|
+
`\u2728`,
|
|
1193
|
+
state.type,
|
|
1194
|
+
state.key,
|
|
1195
|
+
`went`,
|
|
1196
|
+
oldValue,
|
|
1197
|
+
`->`,
|
|
1198
|
+
newValue
|
|
1199
|
+
);
|
|
1200
|
+
state.subject.next({ newValue, oldValue });
|
|
1201
|
+
}
|
|
1202
|
+
);
|
|
1203
|
+
});
|
|
1204
|
+
return dependencySubscriptions;
|
|
1205
|
+
};
|
|
1206
|
+
|
|
1207
|
+
// internal/src/subscribe/subscribe-to-state.ts
|
|
1208
|
+
function subscribeToState(token, handleUpdate, key, store) {
|
|
1209
|
+
const state = withdraw(token, store);
|
|
1210
|
+
if (state === void 0) {
|
|
1211
|
+
throw new Error(
|
|
1212
|
+
`State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
const unsubFunction = state.subject.subscribe(key, handleUpdate);
|
|
1216
|
+
store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
|
|
1217
|
+
const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
|
|
1218
|
+
const unsubscribe = dependencyUnsubFunctions === null ? () => {
|
|
1219
|
+
store.logger.info(
|
|
1220
|
+
`\u{1F648}`,
|
|
1221
|
+
state.type,
|
|
1222
|
+
state.key,
|
|
1223
|
+
`Removing subscription "${key}"`
|
|
1224
|
+
);
|
|
1225
|
+
unsubFunction();
|
|
1226
|
+
} : () => {
|
|
1227
|
+
store.logger.info(
|
|
1228
|
+
`\u{1F648}`,
|
|
1229
|
+
state.type,
|
|
1230
|
+
state.key,
|
|
1231
|
+
`Removing subscription "${key}"`
|
|
1232
|
+
);
|
|
1233
|
+
unsubFunction();
|
|
1234
|
+
for (const unsubFromDependency of dependencyUnsubFunctions) {
|
|
1235
|
+
unsubFromDependency();
|
|
1236
|
+
}
|
|
1237
|
+
};
|
|
1238
|
+
return unsubscribe;
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// internal/src/subscribe/subscribe-to-timeline.ts
|
|
1242
|
+
var subscribeToTimeline = (token, handleUpdate, key, store) => {
|
|
1243
|
+
const tl = withdraw(token, store);
|
|
1244
|
+
if (tl === void 0) {
|
|
1245
|
+
throw new Error(
|
|
1246
|
+
`Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
|
|
1247
|
+
);
|
|
1248
|
+
}
|
|
1249
|
+
store.logger.info(`\u{1F440}`, `timeline`, token.key, `Adding subscription "${key}"`);
|
|
1250
|
+
const unsubscribe = tl.subject.subscribe(key, handleUpdate);
|
|
1251
|
+
return () => {
|
|
1252
|
+
store.logger.info(
|
|
1253
|
+
`\u{1F648}`,
|
|
1254
|
+
`timeline`,
|
|
1255
|
+
token.key,
|
|
1256
|
+
`Removing subscription "${key}" from timeline`
|
|
1257
|
+
);
|
|
1258
|
+
unsubscribe();
|
|
1259
|
+
};
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1262
|
+
// internal/src/subscribe/subscribe-to-transaction.ts
|
|
1263
|
+
var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
1264
|
+
const tx = withdraw(token, store);
|
|
1265
|
+
if (tx === void 0) {
|
|
1266
|
+
throw new Error(
|
|
1267
|
+
`Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
|
|
1268
|
+
);
|
|
1269
|
+
}
|
|
1270
|
+
store.logger.info(
|
|
1271
|
+
`\u{1F440}`,
|
|
1272
|
+
`transaction`,
|
|
1273
|
+
token.key,
|
|
1274
|
+
`Adding subscription "${key}"`
|
|
1275
|
+
);
|
|
1276
|
+
const unsubscribe = tx.subject.subscribe(key, handleUpdate);
|
|
1277
|
+
return () => {
|
|
1278
|
+
store.logger.info(
|
|
1279
|
+
`\u{1F648}`,
|
|
1280
|
+
`transaction`,
|
|
1281
|
+
token.key,
|
|
1282
|
+
`Removing subscription "${key}"`
|
|
1283
|
+
);
|
|
1284
|
+
unsubscribe();
|
|
1285
|
+
};
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
// internal/src/mutable/tracker.ts
|
|
1289
|
+
var Tracker = class {
|
|
1290
|
+
constructor(mutableState, store) {
|
|
1291
|
+
this.unsubscribeFromInnerValue = null;
|
|
1292
|
+
this.mutableState = mutableState;
|
|
1293
|
+
const target = newest(store);
|
|
1294
|
+
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
1295
|
+
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
1296
|
+
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
1297
|
+
target.trackers.set(mutableState.key, this);
|
|
1298
|
+
}
|
|
1299
|
+
initializeState(mutableState, store) {
|
|
1300
|
+
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
1301
|
+
deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
|
|
1302
|
+
const familyMetaData = mutableState.family ? {
|
|
1303
|
+
key: `*${mutableState.family.key}`,
|
|
1304
|
+
subKey: mutableState.family.subKey
|
|
1305
|
+
} : void 0;
|
|
1306
|
+
const latestUpdateState = createAtom(
|
|
1307
|
+
{
|
|
1308
|
+
key: latestUpdateStateKey,
|
|
1309
|
+
default: null
|
|
1310
|
+
},
|
|
1311
|
+
familyMetaData,
|
|
1312
|
+
store
|
|
1313
|
+
);
|
|
1314
|
+
return latestUpdateState;
|
|
1315
|
+
}
|
|
1316
|
+
observeCore(mutableState, latestUpdateState, store) {
|
|
1317
|
+
const originalInnerValue = getState(mutableState, store);
|
|
1318
|
+
const target = newest(store);
|
|
1319
|
+
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1320
|
+
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
1321
|
+
(update) => {
|
|
1322
|
+
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1323
|
+
mutableState.key,
|
|
1324
|
+
() => {
|
|
1325
|
+
unsubscribe();
|
|
1326
|
+
setState(latestUpdateState, update, store);
|
|
1327
|
+
}
|
|
1328
|
+
);
|
|
1329
|
+
}
|
|
1330
|
+
);
|
|
1331
|
+
subscribeToState(
|
|
1332
|
+
mutableState,
|
|
1333
|
+
(update) => {
|
|
1334
|
+
var _a;
|
|
1335
|
+
if (update.newValue !== update.oldValue) {
|
|
1336
|
+
(_a = this.unsubscribeFromInnerValue) == null ? void 0 : _a.call(this);
|
|
1337
|
+
const target2 = newest(store);
|
|
1338
|
+
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
1339
|
+
`tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
|
|
1340
|
+
(update2) => {
|
|
1341
|
+
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1342
|
+
mutableState.key,
|
|
1343
|
+
() => {
|
|
1344
|
+
unsubscribe();
|
|
1345
|
+
setState(latestUpdateState, update2, store);
|
|
1346
|
+
}
|
|
1347
|
+
);
|
|
1348
|
+
}
|
|
1349
|
+
);
|
|
1350
|
+
}
|
|
1351
|
+
},
|
|
1352
|
+
`${store.config.name}: tracker observing inner value`,
|
|
1353
|
+
store
|
|
1354
|
+
);
|
|
1355
|
+
}
|
|
1356
|
+
updateCore(mutableState, latestUpdateState, store) {
|
|
1357
|
+
subscribeToState(
|
|
1358
|
+
latestUpdateState,
|
|
1359
|
+
({ newValue, oldValue }) => {
|
|
1360
|
+
const timelineId = store.timelineAtoms.getRelatedKey(
|
|
1361
|
+
latestUpdateState.key
|
|
1362
|
+
);
|
|
1363
|
+
if (timelineId) {
|
|
1364
|
+
const timelineData = store.timelines.get(timelineId);
|
|
1365
|
+
if (timelineData == null ? void 0 : timelineData.timeTraveling) {
|
|
1366
|
+
const unsubscribe2 = subscribeToTimeline(
|
|
1367
|
+
{ key: timelineId, type: `timeline` },
|
|
1368
|
+
(update) => {
|
|
1369
|
+
unsubscribe2();
|
|
1370
|
+
setState(
|
|
1371
|
+
mutableState,
|
|
1372
|
+
(transceiver) => {
|
|
1373
|
+
if (update === `redo` && newValue) {
|
|
1374
|
+
transceiver.do(newValue);
|
|
1375
|
+
} else if (update === `undo` && oldValue) {
|
|
1376
|
+
transceiver.undo(oldValue);
|
|
1377
|
+
}
|
|
1378
|
+
return transceiver;
|
|
1379
|
+
},
|
|
1380
|
+
store
|
|
1381
|
+
);
|
|
1382
|
+
},
|
|
1383
|
+
`${mutableState.key}: tracker observing timeline`,
|
|
1384
|
+
store
|
|
1385
|
+
);
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
const unsubscribe = store.subject.operationStatus.subscribe(
|
|
1390
|
+
latestUpdateState.key,
|
|
1391
|
+
() => {
|
|
1392
|
+
unsubscribe();
|
|
1393
|
+
const mutable = getState(mutableState, store);
|
|
1394
|
+
const updateNumber = mutable.getUpdateNumber(newValue);
|
|
1395
|
+
const eventOffset = updateNumber - mutable.cacheUpdateNumber;
|
|
1396
|
+
if (newValue && eventOffset === 1) {
|
|
1397
|
+
setState(
|
|
1398
|
+
mutableState,
|
|
1399
|
+
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
1400
|
+
store
|
|
1401
|
+
);
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
);
|
|
1405
|
+
},
|
|
1406
|
+
`${store.config.name}: tracker observing latest update`,
|
|
1407
|
+
store
|
|
1408
|
+
);
|
|
1143
1409
|
}
|
|
1144
|
-
store.subject.selectorCreation.next(token);
|
|
1145
|
-
return token;
|
|
1146
1410
|
};
|
|
1147
1411
|
|
|
1148
|
-
// src/
|
|
1149
|
-
|
|
1150
|
-
const target = newest(store);
|
|
1151
|
-
const subject = new Subject();
|
|
1152
|
-
const { get } = registerSelector(options.key, store);
|
|
1153
|
-
const getSelf = () => {
|
|
1154
|
-
const value = options.get({ get });
|
|
1155
|
-
cacheValue(options.key, value, subject, store);
|
|
1156
|
-
return value;
|
|
1157
|
-
};
|
|
1158
|
-
const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
|
|
1159
|
-
subject,
|
|
1160
|
-
install: (s) => createSelector(options, family, s),
|
|
1161
|
-
get: getSelf,
|
|
1162
|
-
type: `readonly_selector`
|
|
1163
|
-
}), family && { family });
|
|
1164
|
-
target.readonlySelectors.set(options.key, readonlySelector);
|
|
1165
|
-
const initialValue = getSelf();
|
|
1412
|
+
// internal/src/mutable/create-mutable-atom.ts
|
|
1413
|
+
function createMutableAtom(options, store) {
|
|
1166
1414
|
store.logger.info(
|
|
1167
|
-
`\
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
initialValue
|
|
1415
|
+
`\u{1F527}`,
|
|
1416
|
+
`atom`,
|
|
1417
|
+
options.key,
|
|
1418
|
+
`creating in store "${store.config.name}"`
|
|
1172
1419
|
);
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
};
|
|
1177
|
-
if (family) {
|
|
1178
|
-
token.family = family;
|
|
1179
|
-
}
|
|
1180
|
-
store.subject.selectorCreation.next(token);
|
|
1181
|
-
return token;
|
|
1182
|
-
};
|
|
1183
|
-
|
|
1184
|
-
// src/selector/create-selector.ts
|
|
1185
|
-
function createSelector(options, family, store) {
|
|
1420
|
+
const coreState = createAtom(options, void 0, store);
|
|
1421
|
+
new Tracker(coreState, store);
|
|
1422
|
+
const jsonState = selectJson(coreState, options, store);
|
|
1186
1423
|
const target = newest(store);
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
}
|
|
1200
|
-
return createReadonlySelector(options, family, store);
|
|
1424
|
+
subscribeToState(
|
|
1425
|
+
jsonState,
|
|
1426
|
+
() => {
|
|
1427
|
+
const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
|
|
1428
|
+
if (!trackerHasBeenInitialized) {
|
|
1429
|
+
new Tracker(coreState, store);
|
|
1430
|
+
}
|
|
1431
|
+
},
|
|
1432
|
+
`tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`,
|
|
1433
|
+
store
|
|
1434
|
+
);
|
|
1435
|
+
return coreState;
|
|
1201
1436
|
}
|
|
1202
1437
|
|
|
1203
|
-
// src/
|
|
1204
|
-
function
|
|
1205
|
-
const
|
|
1206
|
-
const
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1438
|
+
// internal/src/families/create-atom-family.ts
|
|
1439
|
+
function createAtomFamily(options, store) {
|
|
1440
|
+
const subject = new Subject();
|
|
1441
|
+
const atomFamily = Object.assign(
|
|
1442
|
+
(key) => {
|
|
1443
|
+
const subKey = stringifyJson(key);
|
|
1444
|
+
const family = { key: options.key, subKey };
|
|
1445
|
+
const fullKey = `${options.key}(${subKey})`;
|
|
1446
|
+
const existing = withdraw({ key: fullKey, type: `atom` }, store);
|
|
1447
|
+
let token;
|
|
1448
|
+
if (existing) {
|
|
1449
|
+
token = deposit(existing);
|
|
1450
|
+
} else {
|
|
1451
|
+
const individualOptions = {
|
|
1452
|
+
key: fullKey,
|
|
1453
|
+
default: options.default instanceof Function ? options.default(key) : options.default
|
|
1454
|
+
};
|
|
1455
|
+
if (options.effects) {
|
|
1456
|
+
individualOptions.effects = options.effects(key);
|
|
1457
|
+
}
|
|
1458
|
+
token = createAtom(individualOptions, family, store);
|
|
1459
|
+
subject.next(token);
|
|
1460
|
+
}
|
|
1461
|
+
return token;
|
|
1462
|
+
},
|
|
1463
|
+
{
|
|
1464
|
+
key: options.key,
|
|
1465
|
+
type: `atom_family`,
|
|
1466
|
+
subject
|
|
1221
1467
|
}
|
|
1222
1468
|
);
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
target.selectorGraph.delete(key);
|
|
1229
|
-
store.logger.info(`\u{1F525}`, selectorToken.type, `${key}`, `deleted`);
|
|
1469
|
+
const target = newest(store);
|
|
1470
|
+
target.families.set(options.key, atomFamily);
|
|
1471
|
+
return atomFamily;
|
|
1230
1472
|
}
|
|
1231
1473
|
|
|
1232
|
-
// src/families/create-readonly-selector-family.ts
|
|
1474
|
+
// internal/src/families/create-readonly-selector-family.ts
|
|
1233
1475
|
function createReadonlySelectorFamily(options, store) {
|
|
1234
1476
|
const subject = new Subject();
|
|
1235
1477
|
return Object.assign(
|
|
1236
1478
|
(key) => {
|
|
1237
1479
|
const target = newest(store);
|
|
1238
|
-
const subKey =
|
|
1480
|
+
const subKey = stringifyJson(key);
|
|
1239
1481
|
const family = { key: options.key, subKey };
|
|
1240
1482
|
const fullKey = `${options.key}(${subKey})`;
|
|
1241
1483
|
const existing = target.readonlySelectors.get(fullKey);
|
|
@@ -1258,6 +1500,8 @@ function createReadonlySelectorFamily(options, store) {
|
|
|
1258
1500
|
}
|
|
1259
1501
|
);
|
|
1260
1502
|
}
|
|
1503
|
+
|
|
1504
|
+
// internal/src/families/create-selector-family.ts
|
|
1261
1505
|
function createSelectorFamily(options, store) {
|
|
1262
1506
|
const isReadonly = !(`set` in options);
|
|
1263
1507
|
if (isReadonly) {
|
|
@@ -1267,7 +1511,7 @@ function createSelectorFamily(options, store) {
|
|
|
1267
1511
|
const subject = new Subject();
|
|
1268
1512
|
const selectorFamily = Object.assign(
|
|
1269
1513
|
(key) => {
|
|
1270
|
-
const subKey =
|
|
1514
|
+
const subKey = stringifyJson(key);
|
|
1271
1515
|
const family = { key: options.key, subKey };
|
|
1272
1516
|
const fullKey = `${options.key}(${subKey})`;
|
|
1273
1517
|
const existing = target.selectors.get(fullKey);
|
|
@@ -1295,7 +1539,7 @@ function createSelectorFamily(options, store) {
|
|
|
1295
1539
|
return selectorFamily;
|
|
1296
1540
|
}
|
|
1297
1541
|
|
|
1298
|
-
// src/mutable/tracker-family.ts
|
|
1542
|
+
// internal/src/mutable/tracker-family.ts
|
|
1299
1543
|
var FamilyTracker = class {
|
|
1300
1544
|
constructor(findMutableState, store) {
|
|
1301
1545
|
this.findLatestUpdateState = createAtomFamily(
|
|
@@ -1310,7 +1554,7 @@ var FamilyTracker = class {
|
|
|
1310
1554
|
`store=${store.config.name}::tracker-atom-family`,
|
|
1311
1555
|
(atomToken) => {
|
|
1312
1556
|
if (atomToken.family) {
|
|
1313
|
-
const key =
|
|
1557
|
+
const key = parseJson(atomToken.family.subKey);
|
|
1314
1558
|
this.findLatestUpdateState(key);
|
|
1315
1559
|
new Tracker(atomToken, store);
|
|
1316
1560
|
}
|
|
@@ -1320,7 +1564,7 @@ var FamilyTracker = class {
|
|
|
1320
1564
|
`store=${store.config.name}::tracker-atom-family`,
|
|
1321
1565
|
(atomToken) => {
|
|
1322
1566
|
if (atomToken.family) {
|
|
1323
|
-
const key =
|
|
1567
|
+
const key = parseJson(atomToken.family.subKey);
|
|
1324
1568
|
const mutableAtomToken = this.findMutableState(key);
|
|
1325
1569
|
new Tracker(mutableAtomToken, store);
|
|
1326
1570
|
}
|
|
@@ -1329,18 +1573,18 @@ var FamilyTracker = class {
|
|
|
1329
1573
|
}
|
|
1330
1574
|
};
|
|
1331
1575
|
|
|
1332
|
-
// src/mutable/create-mutable-atom-family.ts
|
|
1576
|
+
// internal/src/mutable/create-mutable-atom-family.ts
|
|
1333
1577
|
function createMutableAtomFamily(options, store) {
|
|
1334
1578
|
const coreFamily = Object.assign(
|
|
1335
1579
|
createAtomFamily(options, store),
|
|
1336
1580
|
options
|
|
1337
1581
|
);
|
|
1338
|
-
|
|
1582
|
+
selectJsonFamily(coreFamily, options);
|
|
1339
1583
|
new FamilyTracker(coreFamily, store);
|
|
1340
1584
|
return coreFamily;
|
|
1341
1585
|
}
|
|
1342
1586
|
|
|
1343
|
-
// src/mutable/get-json-family.ts
|
|
1587
|
+
// internal/src/mutable/get-json-family.ts
|
|
1344
1588
|
var getJsonFamily = (mutableAtomFamily, store) => {
|
|
1345
1589
|
const target = newest(store);
|
|
1346
1590
|
const key = `${mutableAtomFamily.key}:JSON`;
|
|
@@ -1350,7 +1594,7 @@ var getJsonFamily = (mutableAtomFamily, store) => {
|
|
|
1350
1594
|
return jsonFamily;
|
|
1351
1595
|
};
|
|
1352
1596
|
|
|
1353
|
-
// src/mutable/get-json-token.ts
|
|
1597
|
+
// internal/src/mutable/get-json-token.ts
|
|
1354
1598
|
var getJsonToken = (mutableAtomToken) => {
|
|
1355
1599
|
const key = mutableAtomToken.family ? `${mutableAtomToken.family.key}:JSON(${mutableAtomToken.family.subKey})` : `${mutableAtomToken.key}:JSON`;
|
|
1356
1600
|
const jsonToken = { type: `selector`, key };
|
|
@@ -1363,7 +1607,7 @@ var getJsonToken = (mutableAtomToken) => {
|
|
|
1363
1607
|
return jsonToken;
|
|
1364
1608
|
};
|
|
1365
1609
|
|
|
1366
|
-
// src/mutable/get-update-token.ts
|
|
1610
|
+
// internal/src/mutable/get-update-token.ts
|
|
1367
1611
|
var getUpdateToken = (mutableAtomToken) => {
|
|
1368
1612
|
const key = `*${mutableAtomToken.key}`;
|
|
1369
1613
|
const updateToken = { type: `atom`, key };
|
|
@@ -1376,20 +1620,20 @@ var getUpdateToken = (mutableAtomToken) => {
|
|
|
1376
1620
|
return updateToken;
|
|
1377
1621
|
};
|
|
1378
1622
|
|
|
1379
|
-
// src/mutable/is-atom-token-mutable.ts
|
|
1623
|
+
// internal/src/mutable/is-atom-token-mutable.ts
|
|
1380
1624
|
function isAtomTokenMutable(token) {
|
|
1381
1625
|
return token.key.endsWith(`::mutable`);
|
|
1382
1626
|
}
|
|
1383
1627
|
|
|
1384
|
-
// src/mutable/transceiver.ts
|
|
1628
|
+
// internal/src/mutable/transceiver.ts
|
|
1385
1629
|
function isTransceiver(value) {
|
|
1386
1630
|
return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
|
|
1387
1631
|
}
|
|
1388
1632
|
|
|
1389
|
-
// src/mutable/index.ts
|
|
1633
|
+
// internal/src/mutable/index.ts
|
|
1390
1634
|
var isAtomMutable = (atom) => `isMutable` in atom;
|
|
1391
1635
|
|
|
1392
|
-
// src/atom/is-default.ts
|
|
1636
|
+
// internal/src/atom/is-default.ts
|
|
1393
1637
|
var isAtomDefault = (key, store) => {
|
|
1394
1638
|
const core = newest(store);
|
|
1395
1639
|
return core.atomsThatAreDefault.has(key);
|
|
@@ -1408,7 +1652,7 @@ var isSelectorDefault = (key, store) => {
|
|
|
1408
1652
|
return rootKeys.every((rootKey) => isAtomDefault(rootKey, store));
|
|
1409
1653
|
};
|
|
1410
1654
|
|
|
1411
|
-
// src/atom/create-atom.ts
|
|
1655
|
+
// internal/src/atom/create-atom.ts
|
|
1412
1656
|
function createAtom(options, family, store) {
|
|
1413
1657
|
store.logger.info(
|
|
1414
1658
|
`\u{1F528}`,
|
|
@@ -1455,8 +1699,8 @@ function createAtom(options, family, store) {
|
|
|
1455
1699
|
const cleanupFunctions = [];
|
|
1456
1700
|
for (const effect of options.effects) {
|
|
1457
1701
|
const cleanup = effect({
|
|
1458
|
-
setSelf: (next) =>
|
|
1459
|
-
onSet: (handle) =>
|
|
1702
|
+
setSelf: (next) => setState(token, next, store),
|
|
1703
|
+
onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
|
|
1460
1704
|
});
|
|
1461
1705
|
if (cleanup) {
|
|
1462
1706
|
cleanupFunctions.push(cleanup);
|
|
@@ -1473,7 +1717,7 @@ function createAtom(options, family, store) {
|
|
|
1473
1717
|
return token;
|
|
1474
1718
|
}
|
|
1475
1719
|
|
|
1476
|
-
// src/atom/delete-atom.ts
|
|
1720
|
+
// internal/src/atom/delete-atom.ts
|
|
1477
1721
|
function deleteAtom(atomToken, store) {
|
|
1478
1722
|
var _a, _b;
|
|
1479
1723
|
const target = newest(store);
|
|
@@ -1505,7 +1749,7 @@ function deleteAtom(atomToken, store) {
|
|
|
1505
1749
|
store.logger.info(`\u{1F525}`, `atom`, `${key}`, `deleted`);
|
|
1506
1750
|
}
|
|
1507
1751
|
|
|
1508
|
-
// src/lazy-map.ts
|
|
1752
|
+
// internal/src/lazy-map.ts
|
|
1509
1753
|
var LazyMap = class extends Map {
|
|
1510
1754
|
constructor(source) {
|
|
1511
1755
|
super();
|
|
@@ -1539,7 +1783,7 @@ var LazyMap = class extends Map {
|
|
|
1539
1783
|
}
|
|
1540
1784
|
};
|
|
1541
1785
|
|
|
1542
|
-
// src/not-found-error.ts
|
|
1786
|
+
// internal/src/not-found-error.ts
|
|
1543
1787
|
var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
|
|
1544
1788
|
function prettyPrintTokenType(token) {
|
|
1545
1789
|
if (token.type === `readonly_selector`) {
|
|
@@ -1555,63 +1799,7 @@ var NotFoundError = class extends Error {
|
|
|
1555
1799
|
}
|
|
1556
1800
|
};
|
|
1557
1801
|
|
|
1558
|
-
// src/
|
|
1559
|
-
var recallState = (state, store) => {
|
|
1560
|
-
const target = newest(store);
|
|
1561
|
-
if (!target.operation.open) {
|
|
1562
|
-
store.logger.warn(
|
|
1563
|
-
`\u{1F41E}`,
|
|
1564
|
-
state.type,
|
|
1565
|
-
state.key,
|
|
1566
|
-
`recall called outside of an operation. This is probably a bug.`
|
|
1567
|
-
);
|
|
1568
|
-
return target.valueMap.get(state.key);
|
|
1569
|
-
}
|
|
1570
|
-
return target.operation.prev.get(state.key);
|
|
1571
|
-
};
|
|
1572
|
-
|
|
1573
|
-
// src/subscribe/subscribe-to-root-atoms.ts
|
|
1574
|
-
var subscribeToRootAtoms = (state, store) => {
|
|
1575
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1576
|
-
const atom = store.atoms.get(atomKey);
|
|
1577
|
-
if (atom === void 0) {
|
|
1578
|
-
throw new Error(
|
|
1579
|
-
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1580
|
-
);
|
|
1581
|
-
}
|
|
1582
|
-
return atom.subject.subscribe(
|
|
1583
|
-
`${state.type}:${state.key}`,
|
|
1584
|
-
(atomChange) => {
|
|
1585
|
-
store.logger.info(
|
|
1586
|
-
`\u{1F4E2}`,
|
|
1587
|
-
state.type,
|
|
1588
|
-
state.key,
|
|
1589
|
-
`root`,
|
|
1590
|
-
atomKey,
|
|
1591
|
-
`went`,
|
|
1592
|
-
atomChange.oldValue,
|
|
1593
|
-
`->`,
|
|
1594
|
-
atomChange.newValue
|
|
1595
|
-
);
|
|
1596
|
-
const oldValue = recallState(state, store);
|
|
1597
|
-
const newValue = readOrComputeValue(state, store);
|
|
1598
|
-
store.logger.info(
|
|
1599
|
-
`\u2728`,
|
|
1600
|
-
state.type,
|
|
1601
|
-
state.key,
|
|
1602
|
-
`went`,
|
|
1603
|
-
oldValue,
|
|
1604
|
-
`->`,
|
|
1605
|
-
newValue
|
|
1606
|
-
);
|
|
1607
|
-
state.subject.next({ newValue, oldValue });
|
|
1608
|
-
}
|
|
1609
|
-
);
|
|
1610
|
-
});
|
|
1611
|
-
return dependencySubscriptions;
|
|
1612
|
-
};
|
|
1613
|
-
|
|
1614
|
-
// src/timeline/add-atom-to-timeline.ts
|
|
1802
|
+
// internal/src/timeline/add-atom-to-timeline.ts
|
|
1615
1803
|
var addAtomToTimeline = (atomToken, tl, store) => {
|
|
1616
1804
|
const atom = withdraw(atomToken, store);
|
|
1617
1805
|
if (atom === void 0) {
|
|
@@ -1803,7 +1991,7 @@ var addAtomToTimeline = (atomToken, tl, store) => {
|
|
|
1803
1991
|
});
|
|
1804
1992
|
};
|
|
1805
1993
|
|
|
1806
|
-
// src/timeline/create-timeline.ts
|
|
1994
|
+
// internal/src/timeline/create-timeline.ts
|
|
1807
1995
|
function createTimeline(options, store, data) {
|
|
1808
1996
|
var _a, _b;
|
|
1809
1997
|
const tl = __spreadProps(__spreadValues({
|
|
@@ -1874,6 +2062,8 @@ function createTimeline(options, store, data) {
|
|
|
1874
2062
|
store.subject.timelineCreation.next(token);
|
|
1875
2063
|
return token;
|
|
1876
2064
|
}
|
|
2065
|
+
|
|
2066
|
+
// internal/src/timeline/time-travel.ts
|
|
1877
2067
|
var timeTravel = (direction, token, store) => {
|
|
1878
2068
|
const action = direction === `forward` ? `redo` : `undo`;
|
|
1879
2069
|
store.logger.info(
|
|
@@ -1909,7 +2099,7 @@ var timeTravel = (direction, token, store) => {
|
|
|
1909
2099
|
const updateValues = (atomUpdate) => {
|
|
1910
2100
|
const { key, newValue, oldValue } = atomUpdate;
|
|
1911
2101
|
const value = direction === `forward` ? newValue : oldValue;
|
|
1912
|
-
|
|
2102
|
+
setState({ key, type: `atom` }, value, store);
|
|
1913
2103
|
};
|
|
1914
2104
|
const updateValuesFromTransactionUpdate = (transactionUpdate) => {
|
|
1915
2105
|
const updates = direction === `forward` ? transactionUpdate.updates : [...transactionUpdate.updates].reverse();
|
|
@@ -1951,7 +2141,7 @@ var timeTravel = (direction, token, store) => {
|
|
|
1951
2141
|
);
|
|
1952
2142
|
};
|
|
1953
2143
|
|
|
1954
|
-
// src/transaction/abort-transaction.ts
|
|
2144
|
+
// internal/src/transaction/abort-transaction.ts
|
|
1955
2145
|
var abortTransaction = (store) => {
|
|
1956
2146
|
const target = newest(store);
|
|
1957
2147
|
if (target.transactionMeta === null || target.parent === null) {
|
|
@@ -1971,6 +2161,8 @@ var abortTransaction = (store) => {
|
|
|
1971
2161
|
);
|
|
1972
2162
|
target.parent.child = null;
|
|
1973
2163
|
};
|
|
2164
|
+
|
|
2165
|
+
// internal/src/transaction/apply-transaction.ts
|
|
1974
2166
|
function ingestAtomUpdate(update, parent, child) {
|
|
1975
2167
|
var _a, _b, _c;
|
|
1976
2168
|
const { key, newValue } = update;
|
|
@@ -1998,7 +2190,7 @@ function ingestAtomUpdate(update, parent, child) {
|
|
|
1998
2190
|
);
|
|
1999
2191
|
}
|
|
2000
2192
|
}
|
|
2001
|
-
|
|
2193
|
+
setState(token, newValue, parent);
|
|
2002
2194
|
}
|
|
2003
2195
|
function ingestTransactionUpdate(transactionUpdate, parent, child) {
|
|
2004
2196
|
for (const update of transactionUpdate.updates) {
|
|
@@ -2054,7 +2246,7 @@ var applyTransaction = (output, store) => {
|
|
|
2054
2246
|
parent.subject.transactionApplying.next(null);
|
|
2055
2247
|
};
|
|
2056
2248
|
|
|
2057
|
-
// src/transaction/build-transaction.ts
|
|
2249
|
+
// internal/src/transaction/build-transaction.ts
|
|
2058
2250
|
var buildTransaction = (key, params, store) => {
|
|
2059
2251
|
const parent = newest(store);
|
|
2060
2252
|
parent.child = {
|
|
@@ -2098,6 +2290,8 @@ var buildTransaction = (key, params, store) => {
|
|
|
2098
2290
|
params
|
|
2099
2291
|
);
|
|
2100
2292
|
};
|
|
2293
|
+
|
|
2294
|
+
// internal/src/transaction/create-transaction.ts
|
|
2101
2295
|
function createTransaction(options, store) {
|
|
2102
2296
|
const newTransaction = {
|
|
2103
2297
|
key: options.key,
|
|
@@ -2107,9 +2301,9 @@ function createTransaction(options, store) {
|
|
|
2107
2301
|
try {
|
|
2108
2302
|
const output = options.do(
|
|
2109
2303
|
{
|
|
2110
|
-
get: (token2) =>
|
|
2111
|
-
set: (token2, value) =>
|
|
2112
|
-
run: (token2) =>
|
|
2304
|
+
get: (token2) => getState(token2, store),
|
|
2305
|
+
set: (token2, value) => setState(token2, value, store),
|
|
2306
|
+
run: (token2) => runTransaction(token2, store)
|
|
2113
2307
|
},
|
|
2114
2308
|
...params
|
|
2115
2309
|
);
|
|
@@ -2130,6 +2324,8 @@ function createTransaction(options, store) {
|
|
|
2130
2324
|
store.subject.transactionCreation.next(token);
|
|
2131
2325
|
return token;
|
|
2132
2326
|
}
|
|
2327
|
+
|
|
2328
|
+
// internal/src/transaction/redo-transaction.ts
|
|
2133
2329
|
var redoTransactionUpdate = (transactionUpdate, store) => {
|
|
2134
2330
|
store.logger.info(`\u23ED\uFE0F`, `transaction`, transactionUpdate.key, `Redo`);
|
|
2135
2331
|
for (const update of transactionUpdate.updates) {
|
|
@@ -2142,12 +2338,14 @@ var redoTransactionUpdate = (transactionUpdate, store) => {
|
|
|
2142
2338
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2143
2339
|
);
|
|
2144
2340
|
}
|
|
2145
|
-
|
|
2341
|
+
setState(state, newValue, store);
|
|
2146
2342
|
} else {
|
|
2147
2343
|
redoTransactionUpdate(update, store);
|
|
2148
2344
|
}
|
|
2149
2345
|
}
|
|
2150
2346
|
};
|
|
2347
|
+
|
|
2348
|
+
// internal/src/transaction/undo-transaction.ts
|
|
2151
2349
|
var undoTransactionUpdate = (transactionUpdate, store) => {
|
|
2152
2350
|
store.logger.info(`\u23EE\uFE0F`, `transaction`, transactionUpdate.key, `Undo`);
|
|
2153
2351
|
for (const update of transactionUpdate.updates.reverse()) {
|
|
@@ -2160,14 +2358,14 @@ var undoTransactionUpdate = (transactionUpdate, store) => {
|
|
|
2160
2358
|
`State "${token.key}" not found in this store. This is surprising, because we are navigating the history of the store.`
|
|
2161
2359
|
);
|
|
2162
2360
|
}
|
|
2163
|
-
|
|
2361
|
+
setState(state, newValue, store);
|
|
2164
2362
|
} else {
|
|
2165
2363
|
undoTransactionUpdate(update, store);
|
|
2166
2364
|
}
|
|
2167
2365
|
}
|
|
2168
2366
|
};
|
|
2169
2367
|
|
|
2170
|
-
// src/transaction/index.ts
|
|
2368
|
+
// internal/src/transaction/index.ts
|
|
2171
2369
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
2172
2370
|
|
|
2173
2371
|
exports.FamilyTracker = FamilyTracker;
|
|
@@ -2228,6 +2426,9 @@ exports.redoTransactionUpdate = redoTransactionUpdate;
|
|
|
2228
2426
|
exports.registerSelector = registerSelector;
|
|
2229
2427
|
exports.setAtomOrSelector = setAtomOrSelector;
|
|
2230
2428
|
exports.subscribeToRootAtoms = subscribeToRootAtoms;
|
|
2429
|
+
exports.subscribeToState = subscribeToState;
|
|
2430
|
+
exports.subscribeToTimeline = subscribeToTimeline;
|
|
2431
|
+
exports.subscribeToTransaction = subscribeToTransaction;
|
|
2231
2432
|
exports.timeTravel = timeTravel;
|
|
2232
2433
|
exports.traceAllSelectorAtoms = traceAllSelectorAtoms;
|
|
2233
2434
|
exports.traceSelectorAtoms = traceSelectorAtoms;
|