@legendapp/state 3.0.0-alpha.38 → 3.0.0-alpha.39
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/.DS_Store +0 -0
- package/{config.d.ts → config/configureLegendState.d.mts} +1 -1
- package/{config.d.mts → config/configureLegendState.d.ts} +1 -1
- package/config/configureLegendState.js +45 -0
- package/config/configureLegendState.mjs +43 -0
- package/config/enable$GetSet.js +2 -2
- package/config/enable$GetSet.mjs +1 -1
- package/config/enableReactTracking.js +2 -2
- package/config/enableReactTracking.mjs +1 -1
- package/config/enableReactUse.js +2 -2
- package/config/enableReactUse.mjs +1 -1
- package/config/enable_PeekAssign.js +2 -2
- package/config/enable_PeekAssign.mjs +1 -1
- package/index.d.mts +298 -3
- package/index.d.ts +298 -3
- package/index.js +6 -2
- package/index.mjs +6 -2
- package/package.json +6 -6
- package/react-reactive/enableReactive.d.mts +1 -3
- package/react-reactive/enableReactive.d.ts +1 -3
- package/react.d.mts +30 -4
- package/react.d.ts +30 -4
- package/react.js +3 -1
- package/react.mjs +3 -1
- package/sync-plugins/tanstack-query.js +12 -6
- package/sync-plugins/tanstack-query.mjs +12 -6
- package/sync-plugins/tanstack-react-query.js +8 -1
- package/sync-plugins/tanstack-react-query.mjs +8 -1
- package/sync.js +7 -6
- package/sync.mjs +7 -6
- package/config.js +0 -2072
- package/config.mjs +0 -2070
- package/configureReactive-BAV1PS2I.d.mts +0 -32
- package/configureReactive-BAV1PS2I.d.ts +0 -32
- package/observableInterfaces-CgBddSU6.d.mts +0 -287
- package/observableInterfaces-CgBddSU6.d.ts +0 -287
package/config.js
DELETED
|
@@ -1,2072 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// src/is.ts
|
|
4
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
5
|
-
function isArray(obj) {
|
|
6
|
-
return Array.isArray(obj);
|
|
7
|
-
}
|
|
8
|
-
function isObject(obj) {
|
|
9
|
-
return !!obj && typeof obj === "object" && !(obj instanceof Date) && !isArray(obj);
|
|
10
|
-
}
|
|
11
|
-
function isFunction(obj) {
|
|
12
|
-
return typeof obj === "function";
|
|
13
|
-
}
|
|
14
|
-
function isPrimitive(arg) {
|
|
15
|
-
const type = typeof arg;
|
|
16
|
-
return arg !== void 0 && (isDate(arg) || type !== "object" && type !== "function");
|
|
17
|
-
}
|
|
18
|
-
function isDate(obj) {
|
|
19
|
-
return obj instanceof Date;
|
|
20
|
-
}
|
|
21
|
-
function isBoolean(obj) {
|
|
22
|
-
return typeof obj === "boolean";
|
|
23
|
-
}
|
|
24
|
-
function isPromise(obj) {
|
|
25
|
-
return obj instanceof Promise;
|
|
26
|
-
}
|
|
27
|
-
function isMap(obj) {
|
|
28
|
-
return obj instanceof Map || obj instanceof WeakMap;
|
|
29
|
-
}
|
|
30
|
-
function isSet(obj) {
|
|
31
|
-
return obj instanceof Set || obj instanceof WeakSet;
|
|
32
|
-
}
|
|
33
|
-
function isEmpty(obj) {
|
|
34
|
-
if (!obj)
|
|
35
|
-
return false;
|
|
36
|
-
if (isArray(obj))
|
|
37
|
-
return obj.length === 0;
|
|
38
|
-
if (isMap(obj) || isSet(obj))
|
|
39
|
-
return obj.size === 0;
|
|
40
|
-
for (const key in obj) {
|
|
41
|
-
if (hasOwnProperty.call(obj, key)) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
function isNullOrUndefined(value) {
|
|
48
|
-
return value === void 0 || value === null;
|
|
49
|
-
}
|
|
50
|
-
var setPrimitives = /* @__PURE__ */ new Set(["boolean", "string", "number"]);
|
|
51
|
-
function isActualPrimitive(arg) {
|
|
52
|
-
return setPrimitives.has(typeof arg);
|
|
53
|
-
}
|
|
54
|
-
function isChildNode(node) {
|
|
55
|
-
return !!node.parent;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// src/globals.ts
|
|
59
|
-
var symbolToPrimitive = Symbol.toPrimitive;
|
|
60
|
-
var symbolIterator = Symbol.iterator;
|
|
61
|
-
var symbolGetNode = Symbol("getNode");
|
|
62
|
-
var symbolDelete = /* @__PURE__ */ Symbol("delete");
|
|
63
|
-
var symbolOpaque = Symbol("opaque");
|
|
64
|
-
var symbolPlain = Symbol("plain");
|
|
65
|
-
var optimized = Symbol("optimized");
|
|
66
|
-
var symbolLinked = Symbol("linked");
|
|
67
|
-
var globalState = {
|
|
68
|
-
pendingNodes: /* @__PURE__ */ new Map(),
|
|
69
|
-
dirtyNodes: /* @__PURE__ */ new Set()
|
|
70
|
-
};
|
|
71
|
-
function isHintOpaque(value) {
|
|
72
|
-
return value && (value[symbolOpaque] || value["$$typeof"]);
|
|
73
|
-
}
|
|
74
|
-
function isHintPlain(value) {
|
|
75
|
-
return value && value[symbolPlain];
|
|
76
|
-
}
|
|
77
|
-
function getPathType(value) {
|
|
78
|
-
return isArray(value) ? "array" : isMap(value) ? "map" : value instanceof Set ? "set" : "object";
|
|
79
|
-
}
|
|
80
|
-
function replacer(key, value) {
|
|
81
|
-
if (isMap(value)) {
|
|
82
|
-
return {
|
|
83
|
-
__LSType: "Map",
|
|
84
|
-
value: Array.from(value.entries())
|
|
85
|
-
// or with spread: value: [...value]
|
|
86
|
-
};
|
|
87
|
-
} else if (value instanceof Set) {
|
|
88
|
-
return {
|
|
89
|
-
__LSType: "Set",
|
|
90
|
-
value: Array.from(value)
|
|
91
|
-
// or with spread: value: [...value]
|
|
92
|
-
};
|
|
93
|
-
} else if (globalState.replacer) {
|
|
94
|
-
value = globalState.replacer(key, value);
|
|
95
|
-
}
|
|
96
|
-
return value;
|
|
97
|
-
}
|
|
98
|
-
var ISO8601 = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
|
|
99
|
-
function reviver(key, value) {
|
|
100
|
-
if (value) {
|
|
101
|
-
if (typeof value === "string" && ISO8601.test(value)) {
|
|
102
|
-
return new Date(value);
|
|
103
|
-
}
|
|
104
|
-
if (typeof value === "object") {
|
|
105
|
-
if (value.__LSType === "Map") {
|
|
106
|
-
return new Map(value.value);
|
|
107
|
-
} else if (value.__LSType === "Set") {
|
|
108
|
-
return new Set(value.value);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (globalState.reviver) {
|
|
112
|
-
value = globalState.reviver(key, value);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return value;
|
|
116
|
-
}
|
|
117
|
-
function safeStringify(value) {
|
|
118
|
-
return value ? JSON.stringify(value, replacer) : value;
|
|
119
|
-
}
|
|
120
|
-
function safeParse(value) {
|
|
121
|
-
return value ? JSON.parse(value, reviver) : value;
|
|
122
|
-
}
|
|
123
|
-
function clone(value) {
|
|
124
|
-
return safeParse(safeStringify(value));
|
|
125
|
-
}
|
|
126
|
-
function isObservable(value$) {
|
|
127
|
-
return !!value$ && !!value$[symbolGetNode];
|
|
128
|
-
}
|
|
129
|
-
function getNode(value$) {
|
|
130
|
-
return value$ && value$[symbolGetNode];
|
|
131
|
-
}
|
|
132
|
-
function isEvent(value$) {
|
|
133
|
-
var _a;
|
|
134
|
-
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
135
|
-
}
|
|
136
|
-
function setNodeValue(node, newValue) {
|
|
137
|
-
var _a;
|
|
138
|
-
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
139
|
-
const key = node.parent ? node.key : "_";
|
|
140
|
-
const isDelete = newValue === symbolDelete;
|
|
141
|
-
if (isDelete)
|
|
142
|
-
newValue = void 0;
|
|
143
|
-
const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
|
|
144
|
-
const useSetFn = isSet(parentValue);
|
|
145
|
-
const useMapFn = isMap(parentValue);
|
|
146
|
-
const prevValue = useSetFn ? key : useMapFn ? parentValue.get(key) : parentValue[key];
|
|
147
|
-
const isFunc = isFunction(newValue);
|
|
148
|
-
newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
|
|
149
|
-
if (newValue !== prevValue) {
|
|
150
|
-
try {
|
|
151
|
-
parentNode.isSetting = (parentNode.isSetting || 0) + 1;
|
|
152
|
-
if (isDelete) {
|
|
153
|
-
if (useMapFn || useSetFn) {
|
|
154
|
-
parentValue.delete(key);
|
|
155
|
-
} else {
|
|
156
|
-
delete parentValue[key];
|
|
157
|
-
}
|
|
158
|
-
} else {
|
|
159
|
-
if (useSetFn) {
|
|
160
|
-
parentValue.add(newValue);
|
|
161
|
-
} else if (useMapFn) {
|
|
162
|
-
parentValue.set(key, newValue);
|
|
163
|
-
} else {
|
|
164
|
-
parentValue[key] = newValue;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
} finally {
|
|
168
|
-
parentNode.isSetting--;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return { prevValue, newValue };
|
|
172
|
-
}
|
|
173
|
-
var arrNodeKeys = [];
|
|
174
|
-
function getNodeValue(node) {
|
|
175
|
-
let count = 0;
|
|
176
|
-
let n = node;
|
|
177
|
-
while (isChildNode(n)) {
|
|
178
|
-
arrNodeKeys[count++] = n.key;
|
|
179
|
-
n = n.parent;
|
|
180
|
-
}
|
|
181
|
-
let child = node.root._;
|
|
182
|
-
for (let i = count - 1; child && i >= 0; i--) {
|
|
183
|
-
const key = arrNodeKeys[i];
|
|
184
|
-
child = key !== "size" && (isMap(child) || child instanceof WeakMap) ? child.get(key) : child[key];
|
|
185
|
-
}
|
|
186
|
-
return child;
|
|
187
|
-
}
|
|
188
|
-
function getChildNode(node, key, asFunction) {
|
|
189
|
-
var _a, _b;
|
|
190
|
-
let child = (_a = node.children) == null ? void 0 : _a.get(key);
|
|
191
|
-
if (!child) {
|
|
192
|
-
child = {
|
|
193
|
-
root: node.root,
|
|
194
|
-
parent: node,
|
|
195
|
-
key,
|
|
196
|
-
lazy: true,
|
|
197
|
-
numListenersRecursive: 0
|
|
198
|
-
};
|
|
199
|
-
if (((_b = node.lazyFn) == null ? void 0 : _b.length) === 1) {
|
|
200
|
-
asFunction = node.lazyFn.bind(node, key);
|
|
201
|
-
}
|
|
202
|
-
if (isFunction(asFunction)) {
|
|
203
|
-
child = Object.assign(() => {
|
|
204
|
-
}, child);
|
|
205
|
-
child.lazyFn = asFunction;
|
|
206
|
-
}
|
|
207
|
-
if (!node.children) {
|
|
208
|
-
node.children = /* @__PURE__ */ new Map();
|
|
209
|
-
}
|
|
210
|
-
node.children.set(key, child);
|
|
211
|
-
}
|
|
212
|
-
return child;
|
|
213
|
-
}
|
|
214
|
-
function ensureNodeValue(node) {
|
|
215
|
-
let value = getNodeValue(node);
|
|
216
|
-
if (!value || isFunction(value)) {
|
|
217
|
-
if (isChildNode(node)) {
|
|
218
|
-
const parent = ensureNodeValue(node.parent);
|
|
219
|
-
value = parent[node.key] = {};
|
|
220
|
-
} else {
|
|
221
|
-
value = node.root._ = {};
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return value;
|
|
225
|
-
}
|
|
226
|
-
function findIDKey(obj, node) {
|
|
227
|
-
var _a, _b;
|
|
228
|
-
let idKey = isObservable(obj) ? void 0 : isObject(obj) ? "id" in obj ? "id" : "key" in obj ? "key" : "_id" in obj ? "_id" : "__id" in obj ? "__id" : void 0 : void 0;
|
|
229
|
-
if (!idKey && node.parent) {
|
|
230
|
-
const k = node.key + "_keyExtractor";
|
|
231
|
-
const keyExtractor = (_b = (_a = node.functions) == null ? void 0 : _a.get(k)) != null ? _b : getNodeValue(node.parent)[node.key + "_keyExtractor"];
|
|
232
|
-
if (keyExtractor && isFunction(keyExtractor)) {
|
|
233
|
-
idKey = keyExtractor;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return idKey;
|
|
237
|
-
}
|
|
238
|
-
function extractFunction(node, key, fnOrComputed) {
|
|
239
|
-
if (!node.functions) {
|
|
240
|
-
node.functions = /* @__PURE__ */ new Map();
|
|
241
|
-
}
|
|
242
|
-
node.functions.set(key, fnOrComputed);
|
|
243
|
-
}
|
|
244
|
-
function equals(a, b) {
|
|
245
|
-
return a === b || isDate(a) && isDate(b) && +a === +b;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// src/helpers.ts
|
|
249
|
-
function computeSelector(selector, e, retainObservable) {
|
|
250
|
-
let c = selector;
|
|
251
|
-
if (!isObservable(c) && isFunction(c)) {
|
|
252
|
-
c = e ? c(e) : c();
|
|
253
|
-
}
|
|
254
|
-
return isObservable(c) && !retainObservable ? c.get() : c;
|
|
255
|
-
}
|
|
256
|
-
function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
257
|
-
let p = void 0;
|
|
258
|
-
let o = obj;
|
|
259
|
-
if (path.length > 0) {
|
|
260
|
-
for (let i = 0; i < path.length; i++) {
|
|
261
|
-
p = path[i];
|
|
262
|
-
const map = isMap(o);
|
|
263
|
-
let child = o ? map ? o.get(p) : o[p] : void 0;
|
|
264
|
-
if (child === symbolDelete) {
|
|
265
|
-
return obj;
|
|
266
|
-
} else if (child === void 0 && value === void 0 && i === path.length - 1) {
|
|
267
|
-
return obj;
|
|
268
|
-
} else if (i < path.length - 1 && (child === void 0 || child === null)) {
|
|
269
|
-
child = initializePathType(pathTypes[i]);
|
|
270
|
-
if (isMap(o)) {
|
|
271
|
-
o.set(p, child);
|
|
272
|
-
} else {
|
|
273
|
-
o[p] = child;
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (i < path.length - 1) {
|
|
277
|
-
o = child;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (p === void 0) {
|
|
282
|
-
{
|
|
283
|
-
obj = value;
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
if (isMap(o)) {
|
|
287
|
-
o.set(p, value);
|
|
288
|
-
} else {
|
|
289
|
-
o[p] = value;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
return obj;
|
|
293
|
-
}
|
|
294
|
-
function deconstructObjectWithPath(path, pathTypes, value) {
|
|
295
|
-
let o = value;
|
|
296
|
-
for (let i = 0; i < path.length; i++) {
|
|
297
|
-
const p = path[i];
|
|
298
|
-
o = o ? o[p] : initializePathType(pathTypes[i]);
|
|
299
|
-
}
|
|
300
|
-
return o;
|
|
301
|
-
}
|
|
302
|
-
function isObservableValueReady(value) {
|
|
303
|
-
return !!value && (!isObject(value) && !isArray(value) || !isEmpty(value));
|
|
304
|
-
}
|
|
305
|
-
function initializePathType(pathType) {
|
|
306
|
-
switch (pathType) {
|
|
307
|
-
case "array":
|
|
308
|
-
return [];
|
|
309
|
-
case "map":
|
|
310
|
-
return /* @__PURE__ */ new Map();
|
|
311
|
-
case "set":
|
|
312
|
-
return /* @__PURE__ */ new Set();
|
|
313
|
-
case "object":
|
|
314
|
-
default:
|
|
315
|
-
return {};
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function applyChange(value, change, applyPrevious) {
|
|
319
|
-
const { path, valueAtPath, prevAtPath, pathTypes } = change;
|
|
320
|
-
return setAtPath(value, path, pathTypes, prevAtPath );
|
|
321
|
-
}
|
|
322
|
-
function applyChanges(value, changes, applyPrevious) {
|
|
323
|
-
for (let i = 0; i < changes.length; i++) {
|
|
324
|
-
value = applyChange(value, changes[i]);
|
|
325
|
-
}
|
|
326
|
-
return value;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
// src/batching.ts
|
|
330
|
-
var timeout;
|
|
331
|
-
var numInBatch = 0;
|
|
332
|
-
var isRunningBatch = false;
|
|
333
|
-
var didDelayEndBatch = false;
|
|
334
|
-
var _batchMap = /* @__PURE__ */ new Map();
|
|
335
|
-
function onActionTimeout() {
|
|
336
|
-
if (_batchMap.size > 0) {
|
|
337
|
-
if (process.env.NODE_ENV === "development") {
|
|
338
|
-
console.error(
|
|
339
|
-
"Forcibly completing observableBatcher because end() was never called. This may be due to an uncaught error between begin() and end()."
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
endBatch(
|
|
343
|
-
/*force*/
|
|
344
|
-
true
|
|
345
|
-
);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
function isArraySubset(mainArr, subsetArr) {
|
|
349
|
-
for (let i = 0; i < mainArr.length; i++) {
|
|
350
|
-
if (mainArr[i] !== subsetArr[i]) {
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
return true;
|
|
355
|
-
}
|
|
356
|
-
function createPreviousHandlerInner(value, changes) {
|
|
357
|
-
try {
|
|
358
|
-
return applyChanges(value ? clone(value) : {}, changes, true);
|
|
359
|
-
} catch (e) {
|
|
360
|
-
return void 0;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
function createPreviousHandler(value, changes) {
|
|
364
|
-
return function() {
|
|
365
|
-
return createPreviousHandlerInner(value, changes);
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
369
|
-
const changesInBatch = /* @__PURE__ */ new Map();
|
|
370
|
-
computeChangesRecursive(
|
|
371
|
-
changesInBatch,
|
|
372
|
-
node,
|
|
373
|
-
/*loading*/
|
|
374
|
-
!!globalState.isLoadingLocal,
|
|
375
|
-
/*remote*/
|
|
376
|
-
!!globalState.isLoadingRemote,
|
|
377
|
-
value,
|
|
378
|
-
[],
|
|
379
|
-
[],
|
|
380
|
-
value,
|
|
381
|
-
prev,
|
|
382
|
-
/*immediate*/
|
|
383
|
-
true,
|
|
384
|
-
level,
|
|
385
|
-
whenOptimizedOnlyIf
|
|
386
|
-
);
|
|
387
|
-
const existing = _batchMap.get(node);
|
|
388
|
-
if (existing) {
|
|
389
|
-
if (existing.prev === value) {
|
|
390
|
-
_batchMap.delete(node);
|
|
391
|
-
} else {
|
|
392
|
-
existing.value = value;
|
|
393
|
-
}
|
|
394
|
-
} else {
|
|
395
|
-
_batchMap.set(node, {
|
|
396
|
-
value,
|
|
397
|
-
prev,
|
|
398
|
-
level,
|
|
399
|
-
whenOptimizedOnlyIf,
|
|
400
|
-
isFromSync: !!globalState.isLoadingRemote,
|
|
401
|
-
isFromPersist: !!globalState.isLoadingLocal
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
if (changesInBatch.size) {
|
|
405
|
-
batchNotifyChanges(
|
|
406
|
-
changesInBatch,
|
|
407
|
-
/*immediate*/
|
|
408
|
-
true
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
if (numInBatch <= 0) {
|
|
412
|
-
runBatch();
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
function computeChangesAtNode(changesInBatch, node, isFromPersist, isFromSync, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
416
|
-
if (immediate ? node.listenersImmediate : node.listeners) {
|
|
417
|
-
const change = {
|
|
418
|
-
path,
|
|
419
|
-
pathTypes,
|
|
420
|
-
valueAtPath,
|
|
421
|
-
prevAtPath
|
|
422
|
-
};
|
|
423
|
-
const changeInBatch = changesInBatch.get(node);
|
|
424
|
-
if (changeInBatch && path.length > 0) {
|
|
425
|
-
const { changes } = changeInBatch;
|
|
426
|
-
if (!isArraySubset(changes[0].path, change.path)) {
|
|
427
|
-
changes.push(change);
|
|
428
|
-
changeInBatch.level = Math.min(changeInBatch.level, level);
|
|
429
|
-
}
|
|
430
|
-
} else {
|
|
431
|
-
changesInBatch.set(node, {
|
|
432
|
-
level,
|
|
433
|
-
value,
|
|
434
|
-
isFromSync,
|
|
435
|
-
isFromPersist,
|
|
436
|
-
whenOptimizedOnlyIf,
|
|
437
|
-
changes: [change]
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
function computeChangesRecursive(changesInBatch, node, loading, remote, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
443
|
-
computeChangesAtNode(
|
|
444
|
-
changesInBatch,
|
|
445
|
-
node,
|
|
446
|
-
loading,
|
|
447
|
-
remote,
|
|
448
|
-
value,
|
|
449
|
-
path,
|
|
450
|
-
pathTypes,
|
|
451
|
-
valueAtPath,
|
|
452
|
-
prevAtPath,
|
|
453
|
-
immediate,
|
|
454
|
-
level,
|
|
455
|
-
whenOptimizedOnlyIf
|
|
456
|
-
);
|
|
457
|
-
if (node.linkedFromNodes) {
|
|
458
|
-
for (const linkedFromNode of node.linkedFromNodes) {
|
|
459
|
-
const childNode = getNodeAtPath(linkedFromNode, path);
|
|
460
|
-
computeChangesRecursive(
|
|
461
|
-
changesInBatch,
|
|
462
|
-
childNode,
|
|
463
|
-
loading,
|
|
464
|
-
remote,
|
|
465
|
-
valueAtPath,
|
|
466
|
-
[],
|
|
467
|
-
[],
|
|
468
|
-
valueAtPath,
|
|
469
|
-
prevAtPath,
|
|
470
|
-
immediate,
|
|
471
|
-
0,
|
|
472
|
-
whenOptimizedOnlyIf
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
if (node.parent) {
|
|
477
|
-
const parent = node.parent;
|
|
478
|
-
if (parent) {
|
|
479
|
-
const parentValue = getNodeValue(parent);
|
|
480
|
-
computeChangesRecursive(
|
|
481
|
-
changesInBatch,
|
|
482
|
-
parent,
|
|
483
|
-
loading,
|
|
484
|
-
remote,
|
|
485
|
-
parentValue,
|
|
486
|
-
[node.key].concat(path),
|
|
487
|
-
[getPathType(value)].concat(pathTypes),
|
|
488
|
-
valueAtPath,
|
|
489
|
-
prevAtPath,
|
|
490
|
-
immediate,
|
|
491
|
-
level + 1,
|
|
492
|
-
whenOptimizedOnlyIf
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
function batchNotifyChanges(changesInBatch, immediate) {
|
|
498
|
-
const listenersNotified = /* @__PURE__ */ new Set();
|
|
499
|
-
changesInBatch.forEach(({ changes, level, value, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
500
|
-
const listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
501
|
-
if (listeners) {
|
|
502
|
-
let listenerParams;
|
|
503
|
-
const arr = Array.from(listeners);
|
|
504
|
-
for (let i = 0; i < arr.length; i++) {
|
|
505
|
-
const listenerFn = arr[i];
|
|
506
|
-
const { track, noArgs, listener } = listenerFn;
|
|
507
|
-
if (!listenersNotified.has(listener)) {
|
|
508
|
-
const ok = track === true ? level <= 0 : track === optimized ? whenOptimizedOnlyIf && level <= 0 : true;
|
|
509
|
-
if (ok) {
|
|
510
|
-
if (!noArgs && !listenerParams) {
|
|
511
|
-
listenerParams = {
|
|
512
|
-
value,
|
|
513
|
-
isFromPersist,
|
|
514
|
-
isFromSync,
|
|
515
|
-
getPrevious: createPreviousHandler(value, changes),
|
|
516
|
-
changes
|
|
517
|
-
};
|
|
518
|
-
}
|
|
519
|
-
if (!track) {
|
|
520
|
-
listenersNotified.add(listener);
|
|
521
|
-
}
|
|
522
|
-
listener(listenerParams);
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
});
|
|
528
|
-
}
|
|
529
|
-
function runBatch() {
|
|
530
|
-
const dirtyNodes = Array.from(globalState.dirtyNodes);
|
|
531
|
-
globalState.dirtyNodes.clear();
|
|
532
|
-
dirtyNodes.forEach((node) => {
|
|
533
|
-
const dirtyFn = node.dirtyFn;
|
|
534
|
-
if (dirtyFn) {
|
|
535
|
-
node.dirtyFn = void 0;
|
|
536
|
-
dirtyFn();
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
const map = _batchMap;
|
|
540
|
-
_batchMap = /* @__PURE__ */ new Map();
|
|
541
|
-
const changesInBatch = /* @__PURE__ */ new Map();
|
|
542
|
-
map.forEach(({ value, prev, level, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
543
|
-
computeChangesRecursive(
|
|
544
|
-
changesInBatch,
|
|
545
|
-
node,
|
|
546
|
-
isFromPersist,
|
|
547
|
-
isFromSync,
|
|
548
|
-
value,
|
|
549
|
-
[],
|
|
550
|
-
[],
|
|
551
|
-
value,
|
|
552
|
-
prev,
|
|
553
|
-
false,
|
|
554
|
-
level,
|
|
555
|
-
whenOptimizedOnlyIf
|
|
556
|
-
);
|
|
557
|
-
});
|
|
558
|
-
if (changesInBatch.size) {
|
|
559
|
-
batchNotifyChanges(changesInBatch, false);
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
function beginBatch() {
|
|
563
|
-
numInBatch++;
|
|
564
|
-
if (!timeout) {
|
|
565
|
-
timeout = setTimeout(onActionTimeout, 0);
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
function endBatch(force) {
|
|
569
|
-
numInBatch--;
|
|
570
|
-
if (numInBatch <= 0 || force) {
|
|
571
|
-
if (isRunningBatch) {
|
|
572
|
-
didDelayEndBatch = true;
|
|
573
|
-
} else {
|
|
574
|
-
if (timeout) {
|
|
575
|
-
clearTimeout(timeout);
|
|
576
|
-
timeout = void 0;
|
|
577
|
-
}
|
|
578
|
-
numInBatch = 0;
|
|
579
|
-
isRunningBatch = true;
|
|
580
|
-
runBatch();
|
|
581
|
-
isRunningBatch = false;
|
|
582
|
-
if (didDelayEndBatch) {
|
|
583
|
-
didDelayEndBatch = false;
|
|
584
|
-
endBatch(true);
|
|
585
|
-
}
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
function getNodeAtPath(obj, path) {
|
|
590
|
-
let o = obj;
|
|
591
|
-
for (let i = 0; i < path.length; i++) {
|
|
592
|
-
const p = path[i];
|
|
593
|
-
o = getChildNode(o, p);
|
|
594
|
-
}
|
|
595
|
-
return o;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
// src/createObservable.ts
|
|
599
|
-
function createObservable(value, makePrimitive, extractPromise2, createObject, createPrimitive) {
|
|
600
|
-
if (isObservable(value)) {
|
|
601
|
-
return value;
|
|
602
|
-
}
|
|
603
|
-
const valueIsPromise = isPromise(value);
|
|
604
|
-
const valueIsFunction = isFunction(value);
|
|
605
|
-
const root = {
|
|
606
|
-
_: value
|
|
607
|
-
};
|
|
608
|
-
let node = {
|
|
609
|
-
root,
|
|
610
|
-
lazy: true,
|
|
611
|
-
numListenersRecursive: 0
|
|
612
|
-
};
|
|
613
|
-
if (valueIsFunction) {
|
|
614
|
-
node = Object.assign(() => {
|
|
615
|
-
}, node);
|
|
616
|
-
node.lazyFn = value;
|
|
617
|
-
}
|
|
618
|
-
const prim = isActualPrimitive(value);
|
|
619
|
-
const obs = prim ? new createPrimitive(node) : createObject(node);
|
|
620
|
-
if (valueIsPromise) {
|
|
621
|
-
setNodeValue(node, void 0);
|
|
622
|
-
extractPromise2(node, value);
|
|
623
|
-
}
|
|
624
|
-
return obs;
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// src/linked.ts
|
|
628
|
-
function linked(params, options) {
|
|
629
|
-
if (isFunction(params)) {
|
|
630
|
-
params = { get: params };
|
|
631
|
-
}
|
|
632
|
-
const ret = function() {
|
|
633
|
-
return { [symbolLinked]: params };
|
|
634
|
-
};
|
|
635
|
-
ret.prototype[symbolLinked] = params;
|
|
636
|
-
return ret;
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// src/onChange.ts
|
|
640
|
-
function onChange(node, callback, options = {}, fromLinks) {
|
|
641
|
-
var _a;
|
|
642
|
-
const { initial, immediate, noArgs } = options;
|
|
643
|
-
const { trackingType } = options;
|
|
644
|
-
let listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
645
|
-
if (!listeners) {
|
|
646
|
-
listeners = /* @__PURE__ */ new Set();
|
|
647
|
-
if (immediate) {
|
|
648
|
-
node.listenersImmediate = listeners;
|
|
649
|
-
} else {
|
|
650
|
-
node.listeners = listeners;
|
|
651
|
-
}
|
|
652
|
-
}
|
|
653
|
-
const listener = {
|
|
654
|
-
listener: callback,
|
|
655
|
-
track: trackingType,
|
|
656
|
-
noArgs
|
|
657
|
-
};
|
|
658
|
-
listeners.add(listener);
|
|
659
|
-
if (initial) {
|
|
660
|
-
const value = getNodeValue(node);
|
|
661
|
-
callback({
|
|
662
|
-
value,
|
|
663
|
-
isFromPersist: true,
|
|
664
|
-
isFromSync: false,
|
|
665
|
-
changes: [
|
|
666
|
-
{
|
|
667
|
-
path: [],
|
|
668
|
-
pathTypes: [],
|
|
669
|
-
prevAtPath: value,
|
|
670
|
-
valueAtPath: value
|
|
671
|
-
}
|
|
672
|
-
],
|
|
673
|
-
getPrevious: () => void 0
|
|
674
|
-
});
|
|
675
|
-
}
|
|
676
|
-
let extraDisposes;
|
|
677
|
-
function addLinkedNodeListeners(childNode, cb = callback, from) {
|
|
678
|
-
if (!(fromLinks == null ? void 0 : fromLinks.has(childNode))) {
|
|
679
|
-
fromLinks || (fromLinks = /* @__PURE__ */ new Set());
|
|
680
|
-
fromLinks.add(from || node);
|
|
681
|
-
cb || (cb = callback);
|
|
682
|
-
const childOptions = {
|
|
683
|
-
trackingType: true,
|
|
684
|
-
...options
|
|
685
|
-
};
|
|
686
|
-
extraDisposes = [...extraDisposes || [], onChange(childNode, cb, childOptions, fromLinks)];
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
if (node.linkedToNode) {
|
|
690
|
-
addLinkedNodeListeners(node.linkedToNode);
|
|
691
|
-
}
|
|
692
|
-
(_a = node.linkedFromNodes) == null ? void 0 : _a.forEach((linkedFromNode) => addLinkedNodeListeners(linkedFromNode));
|
|
693
|
-
node.numListenersRecursive++;
|
|
694
|
-
let parent = node.parent;
|
|
695
|
-
let pathParent = [node.key];
|
|
696
|
-
while (parent) {
|
|
697
|
-
if (parent.linkedFromNodes) {
|
|
698
|
-
for (const linkedFromNode of parent.linkedFromNodes) {
|
|
699
|
-
if (!(fromLinks == null ? void 0 : fromLinks.has(linkedFromNode))) {
|
|
700
|
-
const cb = createCb(linkedFromNode, pathParent, callback);
|
|
701
|
-
addLinkedNodeListeners(linkedFromNode, cb, parent);
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
}
|
|
705
|
-
parent.numListenersRecursive++;
|
|
706
|
-
pathParent = [parent.key, ...pathParent];
|
|
707
|
-
parent = parent.parent;
|
|
708
|
-
}
|
|
709
|
-
return () => {
|
|
710
|
-
listeners.delete(listener);
|
|
711
|
-
extraDisposes == null ? void 0 : extraDisposes.forEach((fn) => fn());
|
|
712
|
-
let parent2 = node;
|
|
713
|
-
while (parent2) {
|
|
714
|
-
parent2.numListenersRecursive--;
|
|
715
|
-
parent2 = parent2.parent;
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
}
|
|
719
|
-
function createCb(linkedFromNode, path, callback) {
|
|
720
|
-
let prevAtPath = deconstructObjectWithPath(path, [], getNodeValue(linkedFromNode));
|
|
721
|
-
return function({ value: valueA, isFromPersist, isFromSync }) {
|
|
722
|
-
const valueAtPath = deconstructObjectWithPath(path, [], valueA);
|
|
723
|
-
if (valueAtPath !== prevAtPath) {
|
|
724
|
-
callback({
|
|
725
|
-
value: valueAtPath,
|
|
726
|
-
isFromPersist,
|
|
727
|
-
isFromSync,
|
|
728
|
-
changes: [
|
|
729
|
-
{
|
|
730
|
-
path: [],
|
|
731
|
-
pathTypes: [],
|
|
732
|
-
prevAtPath,
|
|
733
|
-
valueAtPath
|
|
734
|
-
}
|
|
735
|
-
],
|
|
736
|
-
getPrevious: () => prevAtPath
|
|
737
|
-
});
|
|
738
|
-
}
|
|
739
|
-
prevAtPath = valueAtPath;
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
// src/setupTracking.ts
|
|
744
|
-
function setupTracking(nodes, update, noArgs, immediate) {
|
|
745
|
-
let listeners = [];
|
|
746
|
-
nodes == null ? void 0 : nodes.forEach((tracked) => {
|
|
747
|
-
const { node, track } = tracked;
|
|
748
|
-
listeners.push(onChange(node, update, { trackingType: track, immediate, noArgs }));
|
|
749
|
-
});
|
|
750
|
-
return () => {
|
|
751
|
-
if (listeners) {
|
|
752
|
-
for (let i = 0; i < listeners.length; i++) {
|
|
753
|
-
listeners[i]();
|
|
754
|
-
}
|
|
755
|
-
listeners = void 0;
|
|
756
|
-
}
|
|
757
|
-
};
|
|
758
|
-
}
|
|
759
|
-
|
|
760
|
-
// src/tracking.ts
|
|
761
|
-
var trackCount = 0;
|
|
762
|
-
var trackingQueue = [];
|
|
763
|
-
var tracking = {
|
|
764
|
-
current: void 0
|
|
765
|
-
};
|
|
766
|
-
function beginTracking() {
|
|
767
|
-
trackingQueue.push(tracking.current);
|
|
768
|
-
trackCount++;
|
|
769
|
-
tracking.current = {};
|
|
770
|
-
}
|
|
771
|
-
function endTracking() {
|
|
772
|
-
trackCount--;
|
|
773
|
-
if (trackCount < 0) {
|
|
774
|
-
trackCount = 0;
|
|
775
|
-
}
|
|
776
|
-
tracking.current = trackingQueue.pop();
|
|
777
|
-
}
|
|
778
|
-
function updateTracking(node, track) {
|
|
779
|
-
if (trackCount) {
|
|
780
|
-
const tracker = tracking.current;
|
|
781
|
-
if (tracker) {
|
|
782
|
-
if (!tracker.nodes) {
|
|
783
|
-
tracker.nodes = /* @__PURE__ */ new Map();
|
|
784
|
-
}
|
|
785
|
-
const existing = tracker.nodes.get(node);
|
|
786
|
-
if (existing) {
|
|
787
|
-
existing.track = existing.track || track;
|
|
788
|
-
existing.num++;
|
|
789
|
-
} else {
|
|
790
|
-
tracker.nodes.set(node, { node, track, num: 1 });
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
// src/trackSelector.ts
|
|
797
|
-
function trackSelector(selector, update, observeEvent, observeOptions, createResubscribe) {
|
|
798
|
-
var _a;
|
|
799
|
-
let dispose;
|
|
800
|
-
let resubscribe;
|
|
801
|
-
let updateFn = update;
|
|
802
|
-
beginTracking();
|
|
803
|
-
const value = selector ? computeSelector(selector, observeEvent, observeOptions == null ? void 0 : observeOptions.fromComputed) : selector;
|
|
804
|
-
const tracker = tracking.current;
|
|
805
|
-
const nodes = tracker.nodes;
|
|
806
|
-
endTracking();
|
|
807
|
-
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && tracker && nodes) {
|
|
808
|
-
(_a = tracker.traceListeners) == null ? void 0 : _a.call(tracker, nodes);
|
|
809
|
-
if (tracker.traceUpdates) {
|
|
810
|
-
updateFn = tracker.traceUpdates(update);
|
|
811
|
-
}
|
|
812
|
-
tracker.traceListeners = void 0;
|
|
813
|
-
tracker.traceUpdates = void 0;
|
|
814
|
-
}
|
|
815
|
-
if (!(observeEvent == null ? void 0 : observeEvent.cancel)) {
|
|
816
|
-
dispose = setupTracking(nodes, updateFn, false, observeOptions == null ? void 0 : observeOptions.immediate);
|
|
817
|
-
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
818
|
-
resubscribe = void 0;
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
return { nodes, value, dispose, resubscribe };
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
// src/observe.ts
|
|
825
|
-
function observe(selectorOrRun, reactionOrOptions, options) {
|
|
826
|
-
let reaction;
|
|
827
|
-
if (isFunction(reactionOrOptions)) {
|
|
828
|
-
reaction = reactionOrOptions;
|
|
829
|
-
} else {
|
|
830
|
-
options = reactionOrOptions;
|
|
831
|
-
}
|
|
832
|
-
let dispose;
|
|
833
|
-
let isRunning = false;
|
|
834
|
-
const e = { num: 0 };
|
|
835
|
-
const update = function() {
|
|
836
|
-
if (isRunning) {
|
|
837
|
-
return;
|
|
838
|
-
}
|
|
839
|
-
if (e.onCleanup) {
|
|
840
|
-
e.onCleanup();
|
|
841
|
-
e.onCleanup = void 0;
|
|
842
|
-
}
|
|
843
|
-
isRunning = true;
|
|
844
|
-
beginBatch();
|
|
845
|
-
delete e.value;
|
|
846
|
-
dispose == null ? void 0 : dispose();
|
|
847
|
-
const { dispose: _dispose, value, nodes } = trackSelector(selectorOrRun, update, e, options);
|
|
848
|
-
dispose = _dispose;
|
|
849
|
-
e.value = value;
|
|
850
|
-
e.nodes = nodes;
|
|
851
|
-
e.refresh = update;
|
|
852
|
-
if (e.onCleanupReaction) {
|
|
853
|
-
e.onCleanupReaction();
|
|
854
|
-
e.onCleanupReaction = void 0;
|
|
855
|
-
}
|
|
856
|
-
endBatch();
|
|
857
|
-
isRunning = false;
|
|
858
|
-
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
859
|
-
reaction(e);
|
|
860
|
-
}
|
|
861
|
-
e.previous = e.value;
|
|
862
|
-
e.num++;
|
|
863
|
-
};
|
|
864
|
-
update();
|
|
865
|
-
return () => {
|
|
866
|
-
var _a, _b;
|
|
867
|
-
(_a = e.onCleanup) == null ? void 0 : _a.call(e);
|
|
868
|
-
e.onCleanup = void 0;
|
|
869
|
-
(_b = e.onCleanupReaction) == null ? void 0 : _b.call(e);
|
|
870
|
-
e.onCleanupReaction = void 0;
|
|
871
|
-
dispose == null ? void 0 : dispose();
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
|
|
875
|
-
// src/when.ts
|
|
876
|
-
function _when(predicate, effect, checkReady) {
|
|
877
|
-
if (isPromise(predicate)) {
|
|
878
|
-
return effect ? predicate.then(effect) : predicate;
|
|
879
|
-
}
|
|
880
|
-
const isPredicateArray = isArray(predicate);
|
|
881
|
-
let value;
|
|
882
|
-
let effectValue;
|
|
883
|
-
function run(e) {
|
|
884
|
-
const ret = isPredicateArray ? predicate.map((p) => computeSelector(p)) : computeSelector(predicate);
|
|
885
|
-
if (isPromise(ret)) {
|
|
886
|
-
value = ret;
|
|
887
|
-
return void 0;
|
|
888
|
-
} else {
|
|
889
|
-
let isOk = true;
|
|
890
|
-
if (isArray(ret)) {
|
|
891
|
-
for (let i = 0; i < ret.length; i++) {
|
|
892
|
-
if (isObservable(ret[i])) {
|
|
893
|
-
ret[i] = computeSelector(ret[i]);
|
|
894
|
-
}
|
|
895
|
-
isOk = isOk && !!(isObservableValueReady(ret[i]) );
|
|
896
|
-
}
|
|
897
|
-
} else {
|
|
898
|
-
isOk = isObservableValueReady(ret) ;
|
|
899
|
-
}
|
|
900
|
-
if (isOk) {
|
|
901
|
-
value = ret;
|
|
902
|
-
e.cancel = true;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
return value;
|
|
906
|
-
}
|
|
907
|
-
function doEffect() {
|
|
908
|
-
effectValue = effect == null ? void 0 : effect(value);
|
|
909
|
-
}
|
|
910
|
-
observe(run, doEffect);
|
|
911
|
-
if (isPromise(value)) {
|
|
912
|
-
return effect ? value.then(effect) : value;
|
|
913
|
-
} else if (value !== void 0) {
|
|
914
|
-
return effect ? effectValue : Promise.resolve(value);
|
|
915
|
-
} else {
|
|
916
|
-
const promise = new Promise((resolve) => {
|
|
917
|
-
if (effect) {
|
|
918
|
-
const originalEffect = effect;
|
|
919
|
-
effect = (value2) => {
|
|
920
|
-
const effectValue2 = originalEffect(value2);
|
|
921
|
-
resolve(isPromise(effectValue2) ? effectValue2.then((value3) => value3) : effectValue2);
|
|
922
|
-
};
|
|
923
|
-
} else {
|
|
924
|
-
effect = resolve;
|
|
925
|
-
}
|
|
926
|
-
});
|
|
927
|
-
return promise;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
function whenReady(predicate, effect) {
|
|
931
|
-
return _when(predicate, effect);
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
// src/ObservableObject.ts
|
|
935
|
-
var ArrayModifiers = /* @__PURE__ */ new Set([
|
|
936
|
-
"copyWithin",
|
|
937
|
-
"fill",
|
|
938
|
-
"from",
|
|
939
|
-
"pop",
|
|
940
|
-
"push",
|
|
941
|
-
"reverse",
|
|
942
|
-
"shift",
|
|
943
|
-
"sort",
|
|
944
|
-
"splice",
|
|
945
|
-
"unshift"
|
|
946
|
-
]);
|
|
947
|
-
var ArrayLoopers = /* @__PURE__ */ new Set([
|
|
948
|
-
"every",
|
|
949
|
-
"filter",
|
|
950
|
-
"find",
|
|
951
|
-
"findIndex",
|
|
952
|
-
"flatMap",
|
|
953
|
-
"forEach",
|
|
954
|
-
"join",
|
|
955
|
-
"map",
|
|
956
|
-
"reduce",
|
|
957
|
-
"some"
|
|
958
|
-
]);
|
|
959
|
-
var ArrayLoopersReturn = /* @__PURE__ */ new Set(["filter", "find"]);
|
|
960
|
-
var observableProperties = /* @__PURE__ */ new Map();
|
|
961
|
-
var observableFns = /* @__PURE__ */ new Map([
|
|
962
|
-
["get", get],
|
|
963
|
-
["set", set],
|
|
964
|
-
["peek", peek],
|
|
965
|
-
["onChange", onChange],
|
|
966
|
-
["assign", assign],
|
|
967
|
-
["delete", deleteFn],
|
|
968
|
-
["toggle", toggle]
|
|
969
|
-
]);
|
|
970
|
-
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
971
|
-
__devUpdateNodes = /* @__PURE__ */ new Set();
|
|
972
|
-
}
|
|
973
|
-
var __devUpdateNodes;
|
|
974
|
-
function collectionSetter(node, target, prop, ...args) {
|
|
975
|
-
var _a;
|
|
976
|
-
if (prop === "push" && args.length === 1) {
|
|
977
|
-
setKey(node, target.length + "", args[0]);
|
|
978
|
-
} else {
|
|
979
|
-
const prevValue = target.slice();
|
|
980
|
-
const ret = target[prop].apply(target, args);
|
|
981
|
-
if (node) {
|
|
982
|
-
const hasParent = isChildNode(node);
|
|
983
|
-
const key = hasParent ? node.key : "_";
|
|
984
|
-
const parentValue = hasParent ? getNodeValue(node.parent) : node.root;
|
|
985
|
-
parentValue[key] = prevValue;
|
|
986
|
-
setKey((_a = node.parent) != null ? _a : node, key, target);
|
|
987
|
-
}
|
|
988
|
-
return ret;
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
function getKeys(obj, isArr, isMap2) {
|
|
992
|
-
return isArr ? void 0 : obj ? isMap2 ? Array.from(obj.keys()) : Object.keys(obj) : [];
|
|
993
|
-
}
|
|
994
|
-
function updateNodes(parent, obj, prevValue) {
|
|
995
|
-
var _a, _b, _c;
|
|
996
|
-
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && isObject(obj)) {
|
|
997
|
-
if (__devUpdateNodes.has(obj)) {
|
|
998
|
-
console.error(
|
|
999
|
-
"[legend-state] Circular reference detected in object. You may want to use opaqueObject to stop traversing child nodes.",
|
|
1000
|
-
obj
|
|
1001
|
-
);
|
|
1002
|
-
return false;
|
|
1003
|
-
}
|
|
1004
|
-
__devUpdateNodes.add(obj);
|
|
1005
|
-
}
|
|
1006
|
-
if (isObject(obj) && isHintOpaque(obj) || isObject(prevValue) && isHintOpaque(prevValue)) {
|
|
1007
|
-
const isDiff = obj !== prevValue;
|
|
1008
|
-
if (isDiff) {
|
|
1009
|
-
if (parent.listeners || parent.listenersImmediate) {
|
|
1010
|
-
notify(parent, obj, prevValue, 0);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && obj !== void 0) {
|
|
1014
|
-
__devUpdateNodes.delete(obj);
|
|
1015
|
-
}
|
|
1016
|
-
return isDiff;
|
|
1017
|
-
}
|
|
1018
|
-
const isArr = isArray(obj);
|
|
1019
|
-
let prevChildrenById;
|
|
1020
|
-
let moved;
|
|
1021
|
-
const isCurMap = isMap(obj);
|
|
1022
|
-
const isPrevMap = isMap(prevValue);
|
|
1023
|
-
const keys = getKeys(obj, isArr, isCurMap);
|
|
1024
|
-
const keysPrev = getKeys(prevValue, isArr, isPrevMap);
|
|
1025
|
-
const length = ((_a = keys || obj) == null ? void 0 : _a.length) || 0;
|
|
1026
|
-
const lengthPrev = ((_b = keysPrev || prevValue) == null ? void 0 : _b.length) || 0;
|
|
1027
|
-
let idField;
|
|
1028
|
-
let isIdFieldFunction;
|
|
1029
|
-
let hasADiff = false;
|
|
1030
|
-
let retValue;
|
|
1031
|
-
if (isArr && isArray(prevValue)) {
|
|
1032
|
-
if (prevValue.length > 0) {
|
|
1033
|
-
const firstPrevValue = prevValue[0];
|
|
1034
|
-
if (firstPrevValue !== void 0) {
|
|
1035
|
-
idField = findIDKey(firstPrevValue, parent);
|
|
1036
|
-
if (idField) {
|
|
1037
|
-
isIdFieldFunction = isFunction(idField);
|
|
1038
|
-
prevChildrenById = /* @__PURE__ */ new Map();
|
|
1039
|
-
moved = [];
|
|
1040
|
-
}
|
|
1041
|
-
const keysSeen = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test" ? /* @__PURE__ */ new Set() : void 0;
|
|
1042
|
-
if (parent.children) {
|
|
1043
|
-
for (let i = 0; i < prevValue.length; i++) {
|
|
1044
|
-
const p = prevValue[i];
|
|
1045
|
-
if (p) {
|
|
1046
|
-
const child = parent.children.get(i + "");
|
|
1047
|
-
if (child) {
|
|
1048
|
-
if (!obj[i]) {
|
|
1049
|
-
handleDeletedChild(child, p);
|
|
1050
|
-
}
|
|
1051
|
-
if (idField) {
|
|
1052
|
-
const key = isIdFieldFunction ? idField(p) : p[idField];
|
|
1053
|
-
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
1054
|
-
if (keysSeen.has(key)) {
|
|
1055
|
-
console.warn(
|
|
1056
|
-
`[legend-state] Warning: Multiple elements in array have the same ID. Key field: ${idField}, Array:`,
|
|
1057
|
-
prevValue
|
|
1058
|
-
);
|
|
1059
|
-
}
|
|
1060
|
-
keysSeen.add(key);
|
|
1061
|
-
}
|
|
1062
|
-
prevChildrenById.set(key, child);
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
} else if (prevValue && (!obj || isObject(obj))) {
|
|
1071
|
-
const lengthPrev2 = keysPrev.length;
|
|
1072
|
-
for (let i = 0; i < lengthPrev2; i++) {
|
|
1073
|
-
const key = keysPrev[i];
|
|
1074
|
-
if (!keys.includes(key)) {
|
|
1075
|
-
hasADiff = true;
|
|
1076
|
-
const child = getChildNode(parent, key);
|
|
1077
|
-
const prev = isPrevMap ? prevValue.get(key) : prevValue[key];
|
|
1078
|
-
if (prev !== void 0) {
|
|
1079
|
-
handleDeletedChild(child, prev);
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
if (obj && !isPrimitive(obj)) {
|
|
1085
|
-
hasADiff = hasADiff || length !== lengthPrev;
|
|
1086
|
-
const isArrDiff = hasADiff;
|
|
1087
|
-
let didMove = false;
|
|
1088
|
-
for (let i = 0; i < length; i++) {
|
|
1089
|
-
const key = isArr ? i + "" : keys[i];
|
|
1090
|
-
let value = isCurMap ? obj.get(key) : obj[key];
|
|
1091
|
-
const prev = isPrevMap ? prevValue == null ? void 0 : prevValue.get(key) : prevValue == null ? void 0 : prevValue[key];
|
|
1092
|
-
let isDiff = !equals(value, prev);
|
|
1093
|
-
if (isDiff) {
|
|
1094
|
-
const id = idField && value ? isIdFieldFunction ? idField(value) : value[idField] : void 0;
|
|
1095
|
-
const existingChild = (_c = parent.children) == null ? void 0 : _c.get(key);
|
|
1096
|
-
if (isObservable(value)) {
|
|
1097
|
-
const valueNode = getNode(value);
|
|
1098
|
-
if ((existingChild == null ? void 0 : existingChild.linkedToNode) === valueNode) {
|
|
1099
|
-
const targetValue = getNodeValue(valueNode);
|
|
1100
|
-
isCurMap ? obj.set(key, targetValue) : obj[key] = targetValue;
|
|
1101
|
-
continue;
|
|
1102
|
-
}
|
|
1103
|
-
const obs = value;
|
|
1104
|
-
value = () => obs;
|
|
1105
|
-
}
|
|
1106
|
-
let child = getChildNode(parent, key, value);
|
|
1107
|
-
if (!child.lazy && (isFunction(value) || isObservable(value))) {
|
|
1108
|
-
reactivateNode(child, value);
|
|
1109
|
-
peekInternal(child);
|
|
1110
|
-
}
|
|
1111
|
-
if (isArr && id !== void 0) {
|
|
1112
|
-
const prevChild = id !== void 0 ? prevChildrenById == null ? void 0 : prevChildrenById.get(id) : void 0;
|
|
1113
|
-
if (!prevChild) {
|
|
1114
|
-
hasADiff = true;
|
|
1115
|
-
} else if (prevChild !== void 0 && prevChild.key !== key) {
|
|
1116
|
-
const valuePrevChild = prevValue[prevChild.key];
|
|
1117
|
-
if (isArrDiff) {
|
|
1118
|
-
child = prevChild;
|
|
1119
|
-
parent.children.delete(child.key);
|
|
1120
|
-
child.key = key;
|
|
1121
|
-
moved.push([key, child]);
|
|
1122
|
-
}
|
|
1123
|
-
didMove = true;
|
|
1124
|
-
isDiff = valuePrevChild !== value;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
if (isDiff) {
|
|
1128
|
-
if (isFunction(value) || isObservable(value)) {
|
|
1129
|
-
extractFunctionOrComputed(parent, key, value);
|
|
1130
|
-
} else if (isPrimitive(value)) {
|
|
1131
|
-
hasADiff = true;
|
|
1132
|
-
} else {
|
|
1133
|
-
const updatedNodes = updateNodes(child, value, prev);
|
|
1134
|
-
hasADiff = hasADiff || updatedNodes;
|
|
1135
|
-
isDiff = updatedNodes;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
if (isDiff || isArr && !isArrDiff) {
|
|
1139
|
-
if (child.listeners || child.listenersImmediate) {
|
|
1140
|
-
notify(child, value, prev, 0, !isArrDiff);
|
|
1141
|
-
}
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
}
|
|
1145
|
-
if (moved) {
|
|
1146
|
-
for (let i = 0; i < moved.length; i++) {
|
|
1147
|
-
const [key, child] = moved[i];
|
|
1148
|
-
parent.children.set(key, child);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
retValue = hasADiff || didMove;
|
|
1152
|
-
} else if (prevValue !== void 0) {
|
|
1153
|
-
retValue = true;
|
|
1154
|
-
}
|
|
1155
|
-
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined" && obj !== void 0) {
|
|
1156
|
-
__devUpdateNodes.delete(obj);
|
|
1157
|
-
}
|
|
1158
|
-
return retValue != null ? retValue : false;
|
|
1159
|
-
}
|
|
1160
|
-
function handleDeletedChild(child, p) {
|
|
1161
|
-
var _a, _b;
|
|
1162
|
-
(_a = child.linkedToNodeDispose) == null ? void 0 : _a.call(child);
|
|
1163
|
-
(_b = child.activatedObserveDispose) == null ? void 0 : _b.call(child);
|
|
1164
|
-
if (!isPrimitive(p)) {
|
|
1165
|
-
updateNodes(child, void 0, p);
|
|
1166
|
-
}
|
|
1167
|
-
if (child.listeners || child.listenersImmediate) {
|
|
1168
|
-
notify(child, void 0, p, 0);
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
function getProxy(node, p, asFunction) {
|
|
1172
|
-
if (p !== void 0)
|
|
1173
|
-
node = getChildNode(node, p, asFunction);
|
|
1174
|
-
return node.proxy || (node.proxy = new Proxy(node, proxyHandler));
|
|
1175
|
-
}
|
|
1176
|
-
function flushPending() {
|
|
1177
|
-
if (globalState.pendingNodes.size > 0) {
|
|
1178
|
-
const nodes = Array.from(globalState.pendingNodes.values());
|
|
1179
|
-
globalState.pendingNodes.clear();
|
|
1180
|
-
nodes.forEach((fn) => fn());
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
var proxyHandler = {
|
|
1184
|
-
get(node, p, receiver) {
|
|
1185
|
-
var _a, _b;
|
|
1186
|
-
if (p === symbolToPrimitive) {
|
|
1187
|
-
throw new Error(
|
|
1188
|
-
process.env.NODE_ENV === "development" ? "[legend-state] observable should not be used as a primitive. You may have forgotten to use .get() or .peek() to get the value of the observable." : "[legend-state] observable is not a primitive."
|
|
1189
|
-
);
|
|
1190
|
-
}
|
|
1191
|
-
if (p === symbolGetNode) {
|
|
1192
|
-
return node;
|
|
1193
|
-
}
|
|
1194
|
-
if (p === "apply" || p === "call") {
|
|
1195
|
-
const nodeValue = getNodeValue(node);
|
|
1196
|
-
if (isFunction(nodeValue)) {
|
|
1197
|
-
return nodeValue[p];
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
let value = peekInternal(
|
|
1201
|
-
node,
|
|
1202
|
-
/*activateRecursive*/
|
|
1203
|
-
p === "get" || p === "peek"
|
|
1204
|
-
);
|
|
1205
|
-
if (p === symbolIterator) {
|
|
1206
|
-
return !value || isPrimitive(value) ? void 0 : value[p];
|
|
1207
|
-
}
|
|
1208
|
-
const targetNode = node.linkedToNode || (value == null ? void 0 : value[symbolGetNode]);
|
|
1209
|
-
if (targetNode && p !== "onChange") {
|
|
1210
|
-
return proxyHandler.get(targetNode, p, receiver);
|
|
1211
|
-
}
|
|
1212
|
-
if (isMap(value) || isSet(value)) {
|
|
1213
|
-
const ret = handlerMapSet(node, p, value);
|
|
1214
|
-
if (ret !== void 0) {
|
|
1215
|
-
return ret;
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
const fn = observableFns.get(p);
|
|
1219
|
-
if (fn) {
|
|
1220
|
-
if (p === "get" || p === "peek") {
|
|
1221
|
-
flushPending();
|
|
1222
|
-
}
|
|
1223
|
-
return function(a, b, c) {
|
|
1224
|
-
const l = arguments.length;
|
|
1225
|
-
switch (l) {
|
|
1226
|
-
case 0:
|
|
1227
|
-
return fn(node);
|
|
1228
|
-
case 1:
|
|
1229
|
-
return fn(node, a);
|
|
1230
|
-
case 2:
|
|
1231
|
-
return fn(node, a, b);
|
|
1232
|
-
default:
|
|
1233
|
-
return fn(node, a, b, c);
|
|
1234
|
-
}
|
|
1235
|
-
};
|
|
1236
|
-
}
|
|
1237
|
-
const property = observableProperties.get(p);
|
|
1238
|
-
if (property) {
|
|
1239
|
-
return property.get(node);
|
|
1240
|
-
}
|
|
1241
|
-
let vProp = value == null ? void 0 : value[p];
|
|
1242
|
-
if (isObject(value) && isHintOpaque(value)) {
|
|
1243
|
-
return vProp;
|
|
1244
|
-
}
|
|
1245
|
-
const fnOrComputed = (_a = node.functions) == null ? void 0 : _a.get(p);
|
|
1246
|
-
if (fnOrComputed) {
|
|
1247
|
-
if (isObservable(fnOrComputed)) {
|
|
1248
|
-
return fnOrComputed;
|
|
1249
|
-
} else {
|
|
1250
|
-
return getProxy(node, p, fnOrComputed);
|
|
1251
|
-
}
|
|
1252
|
-
} else {
|
|
1253
|
-
vProp = checkProperty(value, p);
|
|
1254
|
-
}
|
|
1255
|
-
if (isNullOrUndefined(value) && vProp === void 0 && (ArrayModifiers.has(p) || ArrayLoopers.has(p))) {
|
|
1256
|
-
value = [];
|
|
1257
|
-
setNodeValue(node, value);
|
|
1258
|
-
vProp = value[p];
|
|
1259
|
-
}
|
|
1260
|
-
if (isFunction(vProp)) {
|
|
1261
|
-
if (isArray(value)) {
|
|
1262
|
-
if (ArrayModifiers.has(p)) {
|
|
1263
|
-
return (...args) => collectionSetter(node, value, p, ...args);
|
|
1264
|
-
} else if (ArrayLoopers.has(p)) {
|
|
1265
|
-
updateTracking(node, true);
|
|
1266
|
-
return function(cbOrig, thisArg) {
|
|
1267
|
-
const isReduce = p === "reduce";
|
|
1268
|
-
const cbWrapped = isReduce ? (previousValue, currentValue, currentIndex, array) => {
|
|
1269
|
-
return cbOrig(
|
|
1270
|
-
previousValue,
|
|
1271
|
-
getProxy(node, currentIndex + "", currentValue),
|
|
1272
|
-
currentIndex,
|
|
1273
|
-
array
|
|
1274
|
-
);
|
|
1275
|
-
} : (val, index, array) => {
|
|
1276
|
-
return cbOrig(getProxy(node, index + "", val), index, array);
|
|
1277
|
-
};
|
|
1278
|
-
if (isReduce || !ArrayLoopersReturn.has(p)) {
|
|
1279
|
-
return value[p](cbWrapped, thisArg);
|
|
1280
|
-
}
|
|
1281
|
-
const isFind = p === "find";
|
|
1282
|
-
const out = [];
|
|
1283
|
-
for (let i = 0; i < value.length; i++) {
|
|
1284
|
-
if (cbWrapped(value[i], i, value)) {
|
|
1285
|
-
const proxy = getProxy(node, i + "");
|
|
1286
|
-
if (isFind) {
|
|
1287
|
-
return proxy;
|
|
1288
|
-
}
|
|
1289
|
-
out.push(proxy);
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
return isFind ? void 0 : out;
|
|
1293
|
-
};
|
|
1294
|
-
}
|
|
1295
|
-
}
|
|
1296
|
-
extractFunctionOrComputed(node, p, vProp);
|
|
1297
|
-
const fnOrComputed2 = (_b = node.functions) == null ? void 0 : _b.get(p);
|
|
1298
|
-
if (fnOrComputed2) {
|
|
1299
|
-
return getProxy(node, p, fnOrComputed2);
|
|
1300
|
-
}
|
|
1301
|
-
return vProp.bind(value);
|
|
1302
|
-
}
|
|
1303
|
-
if (isPrimitive(vProp)) {
|
|
1304
|
-
if (p === "length" && isArray(value)) {
|
|
1305
|
-
updateTracking(node, true);
|
|
1306
|
-
return vProp;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
return getProxy(node, p);
|
|
1310
|
-
},
|
|
1311
|
-
// Forward all proxy properties to the target's value
|
|
1312
|
-
getPrototypeOf(node) {
|
|
1313
|
-
const value = getNodeValue(node);
|
|
1314
|
-
return value !== null && typeof value === "object" ? Reflect.getPrototypeOf(value) : null;
|
|
1315
|
-
},
|
|
1316
|
-
ownKeys(node) {
|
|
1317
|
-
peekInternal(node);
|
|
1318
|
-
const value = get(node, true);
|
|
1319
|
-
if (isPrimitive(value))
|
|
1320
|
-
return [];
|
|
1321
|
-
const keys = value ? Reflect.ownKeys(value) : [];
|
|
1322
|
-
if (isArray(value) && keys[keys.length - 1] === "length") {
|
|
1323
|
-
keys.splice(keys.length - 1, 1);
|
|
1324
|
-
}
|
|
1325
|
-
if (isFunction(node)) {
|
|
1326
|
-
const reflectedKeys = Reflect.ownKeys(node);
|
|
1327
|
-
["caller", "arguments", "prototype"].forEach((key) => reflectedKeys.includes(key) && keys.push(key));
|
|
1328
|
-
}
|
|
1329
|
-
return keys;
|
|
1330
|
-
},
|
|
1331
|
-
getOwnPropertyDescriptor(node, prop) {
|
|
1332
|
-
if (prop === "caller" || prop === "arguments" || prop === "prototype") {
|
|
1333
|
-
return { configurable: false, enumerable: false };
|
|
1334
|
-
}
|
|
1335
|
-
const value = getNodeValue(node);
|
|
1336
|
-
return isPrimitive(value) ? void 0 : Reflect.getOwnPropertyDescriptor(value, prop);
|
|
1337
|
-
},
|
|
1338
|
-
set(node, prop, value) {
|
|
1339
|
-
if (node.isSetting) {
|
|
1340
|
-
return Reflect.set(node, prop, value);
|
|
1341
|
-
}
|
|
1342
|
-
if (node.isAssigning) {
|
|
1343
|
-
setKey(node, prop, value);
|
|
1344
|
-
return true;
|
|
1345
|
-
}
|
|
1346
|
-
const property = observableProperties.get(prop);
|
|
1347
|
-
if (property) {
|
|
1348
|
-
property.set(node, value);
|
|
1349
|
-
return true;
|
|
1350
|
-
}
|
|
1351
|
-
if (process.env.NODE_ENV === "development") {
|
|
1352
|
-
console.warn("[legend-state]: Error: Cannot set a value directly:", prop, value);
|
|
1353
|
-
}
|
|
1354
|
-
return false;
|
|
1355
|
-
},
|
|
1356
|
-
deleteProperty(node, prop) {
|
|
1357
|
-
if (node.isSetting) {
|
|
1358
|
-
return Reflect.deleteProperty(node, prop);
|
|
1359
|
-
} else {
|
|
1360
|
-
if (process.env.NODE_ENV === "development") {
|
|
1361
|
-
console.warn("[legend-state]: Error: Cannot delete a value directly:", prop);
|
|
1362
|
-
}
|
|
1363
|
-
return false;
|
|
1364
|
-
}
|
|
1365
|
-
},
|
|
1366
|
-
has(node, prop) {
|
|
1367
|
-
const value = getNodeValue(node);
|
|
1368
|
-
return Reflect.has(value, prop);
|
|
1369
|
-
},
|
|
1370
|
-
apply(target, thisArg, argArray) {
|
|
1371
|
-
if (isObservable(thisArg)) {
|
|
1372
|
-
thisArg = thisArg.peek();
|
|
1373
|
-
}
|
|
1374
|
-
return Reflect.apply(target.lazyFn || target, thisArg, argArray);
|
|
1375
|
-
}
|
|
1376
|
-
};
|
|
1377
|
-
function set(node, newValue) {
|
|
1378
|
-
if (node.parent) {
|
|
1379
|
-
setKey(node.parent, node.key, newValue);
|
|
1380
|
-
} else {
|
|
1381
|
-
setKey(node, "_", newValue);
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
function toggle(node) {
|
|
1385
|
-
const value = getNodeValue(node);
|
|
1386
|
-
if (value === void 0 || value === null || isBoolean(value)) {
|
|
1387
|
-
set(node, !value);
|
|
1388
|
-
} else if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
1389
|
-
throw new Error("[legend-state] Cannot toggle a non-boolean value");
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
function setKey(node, key, newValue, level) {
|
|
1393
|
-
if (process.env.NODE_ENV === "development") {
|
|
1394
|
-
if (typeof HTMLElement !== "undefined" && newValue instanceof HTMLElement) {
|
|
1395
|
-
console.warn(`[legend-state] Set an HTMLElement into state. You probably don't want to do that.`);
|
|
1396
|
-
}
|
|
1397
|
-
}
|
|
1398
|
-
const isRoot = !node.parent && key === "_";
|
|
1399
|
-
if (node.parent && !getNodeValue(node) && !isFunction(newValue)) {
|
|
1400
|
-
set(node, { [key]: newValue });
|
|
1401
|
-
}
|
|
1402
|
-
const childNode = isRoot ? node : getChildNode(node, key, newValue);
|
|
1403
|
-
if (isObservable(newValue)) {
|
|
1404
|
-
setToObservable(childNode, newValue);
|
|
1405
|
-
} else {
|
|
1406
|
-
const { newValue: savedValue, prevValue } = setNodeValue(childNode, newValue);
|
|
1407
|
-
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1408
|
-
if (!isPrim) {
|
|
1409
|
-
let parent = childNode;
|
|
1410
|
-
do {
|
|
1411
|
-
parent.needsExtract = true;
|
|
1412
|
-
parent.recursivelyAutoActivated = false;
|
|
1413
|
-
} while (parent = parent.parent);
|
|
1414
|
-
}
|
|
1415
|
-
const notify2 = !equals(savedValue, prevValue);
|
|
1416
|
-
const forceNotify = !notify2 && childNode.isComputing && !isPrim;
|
|
1417
|
-
if (notify2 || forceNotify) {
|
|
1418
|
-
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level, forceNotify);
|
|
1419
|
-
}
|
|
1420
|
-
extractFunctionOrComputed(node, key, savedValue);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
function assign(node, value) {
|
|
1424
|
-
const proxy = getProxy(node);
|
|
1425
|
-
beginBatch();
|
|
1426
|
-
if (isPrimitive(node.root._)) {
|
|
1427
|
-
node.root._ = {};
|
|
1428
|
-
}
|
|
1429
|
-
if (isMap(value)) {
|
|
1430
|
-
const currentValue = getNodeValue(node);
|
|
1431
|
-
if (isMap(currentValue)) {
|
|
1432
|
-
value.forEach((value2, key) => currentValue.set(key, value2));
|
|
1433
|
-
} else {
|
|
1434
|
-
set(node, value);
|
|
1435
|
-
}
|
|
1436
|
-
} else {
|
|
1437
|
-
node.isAssigning = (node.isAssigning || 0) + 1;
|
|
1438
|
-
try {
|
|
1439
|
-
Object.assign(proxy, value);
|
|
1440
|
-
} finally {
|
|
1441
|
-
node.isAssigning--;
|
|
1442
|
-
}
|
|
1443
|
-
}
|
|
1444
|
-
endBatch();
|
|
1445
|
-
return proxy;
|
|
1446
|
-
}
|
|
1447
|
-
function deleteFn(node, key) {
|
|
1448
|
-
if (key === void 0 && isChildNode(node)) {
|
|
1449
|
-
key = node.key;
|
|
1450
|
-
node = node.parent;
|
|
1451
|
-
}
|
|
1452
|
-
const value = getNodeValue(node);
|
|
1453
|
-
if (isArray(value)) {
|
|
1454
|
-
collectionSetter(node, value, "splice", key, 1);
|
|
1455
|
-
} else {
|
|
1456
|
-
setKey(
|
|
1457
|
-
node,
|
|
1458
|
-
key != null ? key : "_",
|
|
1459
|
-
symbolDelete,
|
|
1460
|
-
/*level*/
|
|
1461
|
-
-1
|
|
1462
|
-
);
|
|
1463
|
-
}
|
|
1464
|
-
}
|
|
1465
|
-
function handlerMapSet(node, p, value) {
|
|
1466
|
-
const vProp = value == null ? void 0 : value[p];
|
|
1467
|
-
if (p === "size") {
|
|
1468
|
-
updateTracking(node, true);
|
|
1469
|
-
return value[p];
|
|
1470
|
-
} else if (isFunction(vProp)) {
|
|
1471
|
-
return function(a, b, c) {
|
|
1472
|
-
const l = arguments.length;
|
|
1473
|
-
const valueMap = value;
|
|
1474
|
-
if (p === "get") {
|
|
1475
|
-
if (l > 0 && typeof a !== "boolean" && a !== optimized) {
|
|
1476
|
-
return getProxy(node, a);
|
|
1477
|
-
}
|
|
1478
|
-
} else if (p === "set") {
|
|
1479
|
-
if (l === 2) {
|
|
1480
|
-
set(getChildNode(node, a), b);
|
|
1481
|
-
} else if (l === 1 && isMap(value)) {
|
|
1482
|
-
set(node, a);
|
|
1483
|
-
}
|
|
1484
|
-
return getProxy(node);
|
|
1485
|
-
} else if (p === "delete") {
|
|
1486
|
-
if (l > 0) {
|
|
1487
|
-
const prev = value.get ? valueMap.get(a) : a;
|
|
1488
|
-
deleteFn(node, a);
|
|
1489
|
-
return prev !== void 0;
|
|
1490
|
-
}
|
|
1491
|
-
} else if (p === "clear") {
|
|
1492
|
-
const prev = new Map(valueMap);
|
|
1493
|
-
const size = valueMap.size;
|
|
1494
|
-
valueMap.clear();
|
|
1495
|
-
if (size) {
|
|
1496
|
-
updateNodesAndNotify(node, value, prev);
|
|
1497
|
-
}
|
|
1498
|
-
return;
|
|
1499
|
-
} else if (p === "add") {
|
|
1500
|
-
const prev = new Set(value);
|
|
1501
|
-
const ret = value.add(a);
|
|
1502
|
-
if (!value.has(p)) {
|
|
1503
|
-
notify(node, ret, prev, 0);
|
|
1504
|
-
}
|
|
1505
|
-
return getProxy(node);
|
|
1506
|
-
}
|
|
1507
|
-
const fn = observableFns.get(p);
|
|
1508
|
-
if (fn) {
|
|
1509
|
-
switch (l) {
|
|
1510
|
-
case 0:
|
|
1511
|
-
return fn(node);
|
|
1512
|
-
case 1:
|
|
1513
|
-
return fn(node, a);
|
|
1514
|
-
case 2:
|
|
1515
|
-
return fn(node, a, b);
|
|
1516
|
-
default:
|
|
1517
|
-
return fn(node, a, b, c);
|
|
1518
|
-
}
|
|
1519
|
-
} else {
|
|
1520
|
-
return value[p](a, b);
|
|
1521
|
-
}
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level, forceNotify) {
|
|
1526
|
-
if (!childNode)
|
|
1527
|
-
childNode = node;
|
|
1528
|
-
beginBatch();
|
|
1529
|
-
if (isPrim === void 0) {
|
|
1530
|
-
isPrim = isPrimitive(newValue);
|
|
1531
|
-
}
|
|
1532
|
-
let hasADiff = forceNotify || isPrim;
|
|
1533
|
-
let whenOptimizedOnlyIf = false;
|
|
1534
|
-
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1535
|
-
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1536
|
-
__devUpdateNodes.clear();
|
|
1537
|
-
}
|
|
1538
|
-
hasADiff = hasADiff || updateNodes(childNode, newValue, prevValue);
|
|
1539
|
-
if (isArray(newValue)) {
|
|
1540
|
-
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
if (isPrim || !newValue || isEmpty(newValue) && !isEmpty(prevValue) ? newValue !== prevValue : hasADiff) {
|
|
1544
|
-
notify(
|
|
1545
|
-
isPrim && isRoot ? node : childNode,
|
|
1546
|
-
newValue,
|
|
1547
|
-
prevValue,
|
|
1548
|
-
(level != null ? level : prevValue === void 0) ? -1 : hasADiff ? 0 : 1,
|
|
1549
|
-
whenOptimizedOnlyIf
|
|
1550
|
-
);
|
|
1551
|
-
}
|
|
1552
|
-
endBatch();
|
|
1553
|
-
}
|
|
1554
|
-
function extractPromise(node, value, setter) {
|
|
1555
|
-
const numGets = node.numGets = (node.numGets || 0) + 1;
|
|
1556
|
-
if (!node.state) {
|
|
1557
|
-
node.state = createObservable(
|
|
1558
|
-
{
|
|
1559
|
-
isLoaded: false
|
|
1560
|
-
},
|
|
1561
|
-
false,
|
|
1562
|
-
extractPromise,
|
|
1563
|
-
getProxy
|
|
1564
|
-
);
|
|
1565
|
-
}
|
|
1566
|
-
value.then((value2) => {
|
|
1567
|
-
if (numGets >= (node.getNumResolved || 0)) {
|
|
1568
|
-
node.getNumResolved = node.numGets;
|
|
1569
|
-
setter ? setter({ value: value2 }) : set(node, value2);
|
|
1570
|
-
node.state.assign({
|
|
1571
|
-
isLoaded: true,
|
|
1572
|
-
error: void 0
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
}).catch((error) => {
|
|
1576
|
-
node.state.error.set(error);
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
function extractFunctionOrComputed(node, k, v) {
|
|
1580
|
-
if (isPromise(v)) {
|
|
1581
|
-
const childNode = getChildNode(node, k);
|
|
1582
|
-
extractPromise(childNode, v);
|
|
1583
|
-
setNodeValue(childNode, void 0);
|
|
1584
|
-
return void 0;
|
|
1585
|
-
} else if (isObservable(v)) {
|
|
1586
|
-
const fn = () => v;
|
|
1587
|
-
extractFunction(node, k, fn);
|
|
1588
|
-
const childNode = getChildNode(node, k, fn);
|
|
1589
|
-
const targetNode = getNode(v);
|
|
1590
|
-
const initialValue = peek(targetNode);
|
|
1591
|
-
setToObservable(childNode, v);
|
|
1592
|
-
setNodeValue(childNode, initialValue);
|
|
1593
|
-
return getNodeValue(childNode);
|
|
1594
|
-
} else if (typeof v === "function") {
|
|
1595
|
-
extractFunction(node, k, v);
|
|
1596
|
-
return k;
|
|
1597
|
-
}
|
|
1598
|
-
}
|
|
1599
|
-
function get(node, options) {
|
|
1600
|
-
const track = options ? isObject(options) ? options.shallow : options : void 0;
|
|
1601
|
-
updateTracking(node, track);
|
|
1602
|
-
return peek(node);
|
|
1603
|
-
}
|
|
1604
|
-
function peek(node) {
|
|
1605
|
-
return peekInternal(node, true);
|
|
1606
|
-
}
|
|
1607
|
-
var isFlushing = false;
|
|
1608
|
-
function peekInternal(node, activateRecursive) {
|
|
1609
|
-
var _a;
|
|
1610
|
-
isFlushing = true;
|
|
1611
|
-
if (activateRecursive && ((_a = node.dirtyChildren) == null ? void 0 : _a.size)) {
|
|
1612
|
-
const dirty = Array.from(node.dirtyChildren);
|
|
1613
|
-
node.dirtyChildren.clear();
|
|
1614
|
-
dirty.forEach((node2) => node2.dirtyFn && peekInternal(node2));
|
|
1615
|
-
}
|
|
1616
|
-
if (node.dirtyFn) {
|
|
1617
|
-
const dirtyFn = node.dirtyFn;
|
|
1618
|
-
node.dirtyFn = void 0;
|
|
1619
|
-
globalState.dirtyNodes.delete(node);
|
|
1620
|
-
dirtyFn();
|
|
1621
|
-
}
|
|
1622
|
-
isFlushing = false;
|
|
1623
|
-
let value = getNodeValue(node);
|
|
1624
|
-
if (!globalState.isLoadingLocal) {
|
|
1625
|
-
value = checkLazy(node, value, !!activateRecursive);
|
|
1626
|
-
}
|
|
1627
|
-
return value;
|
|
1628
|
-
}
|
|
1629
|
-
function checkLazy(node, value, activateRecursive) {
|
|
1630
|
-
const origValue = value;
|
|
1631
|
-
const lazy = node.lazy;
|
|
1632
|
-
if (lazy) {
|
|
1633
|
-
const lazyFn = node.lazyFn;
|
|
1634
|
-
delete node.lazy;
|
|
1635
|
-
if (isFunction(lazyFn)) {
|
|
1636
|
-
if (lazyFn.length === 1) {
|
|
1637
|
-
value = {};
|
|
1638
|
-
} else {
|
|
1639
|
-
if (node.parent) {
|
|
1640
|
-
const parentValue = getNodeValue(node.parent);
|
|
1641
|
-
if (isFunction(value)) {
|
|
1642
|
-
if (parentValue) {
|
|
1643
|
-
delete parentValue[node.key];
|
|
1644
|
-
} else {
|
|
1645
|
-
node.root._ = void 0;
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
value = activateNodeFunction(node, lazyFn);
|
|
1650
|
-
}
|
|
1651
|
-
} else if (isObservable(value)) {
|
|
1652
|
-
value = extractFunctionOrComputed(node.parent, node.key, value);
|
|
1653
|
-
}
|
|
1654
|
-
}
|
|
1655
|
-
if ((lazy || node.needsExtract) && !isObservable(value) && !isPrimitive(value)) {
|
|
1656
|
-
if (activateRecursive) {
|
|
1657
|
-
recursivelyAutoActivate(value, node);
|
|
1658
|
-
}
|
|
1659
|
-
if (node.parent) {
|
|
1660
|
-
extractFunctionOrComputed(node.parent, node.key, origValue);
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
return value;
|
|
1664
|
-
}
|
|
1665
|
-
function checkProperty(value, key) {
|
|
1666
|
-
if (value) {
|
|
1667
|
-
const property = Object.getOwnPropertyDescriptor(value, key);
|
|
1668
|
-
if (property == null ? void 0 : property.get) {
|
|
1669
|
-
delete value[key];
|
|
1670
|
-
value[key] = property.set ? linked({
|
|
1671
|
-
get: property.get,
|
|
1672
|
-
set: ({ value: value2 }) => property.set(value2)
|
|
1673
|
-
}) : property.get;
|
|
1674
|
-
}
|
|
1675
|
-
return value[key];
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
function reactivateNode(node, lazyFn) {
|
|
1679
|
-
var _a, _b;
|
|
1680
|
-
(_a = node.activatedObserveDispose) == null ? void 0 : _a.call(node);
|
|
1681
|
-
(_b = node.linkedToNodeDispose) == null ? void 0 : _b.call(node);
|
|
1682
|
-
node.activatedObserveDispose = node.linkedToNodeDispose = node.linkedToNode = void 0;
|
|
1683
|
-
node.lazyFn = lazyFn;
|
|
1684
|
-
node.lazy = true;
|
|
1685
|
-
}
|
|
1686
|
-
function isObserved(node) {
|
|
1687
|
-
var _a, _b;
|
|
1688
|
-
let parent = node;
|
|
1689
|
-
let hasListeners = node.numListenersRecursive > 0;
|
|
1690
|
-
while (parent && !hasListeners) {
|
|
1691
|
-
if (!!((_a = parent.listeners) == null ? void 0 : _a.size) || !!((_b = parent.listenersImmediate) == null ? void 0 : _b.size)) {
|
|
1692
|
-
hasListeners = true;
|
|
1693
|
-
}
|
|
1694
|
-
parent = parent.parent;
|
|
1695
|
-
}
|
|
1696
|
-
return hasListeners;
|
|
1697
|
-
}
|
|
1698
|
-
function shouldIgnoreUnobserved(node, refreshFn) {
|
|
1699
|
-
if (!isFlushing) {
|
|
1700
|
-
const hasListeners = isObserved(node);
|
|
1701
|
-
if (!hasListeners) {
|
|
1702
|
-
if (refreshFn) {
|
|
1703
|
-
node.dirtyFn = refreshFn;
|
|
1704
|
-
}
|
|
1705
|
-
let parent = node;
|
|
1706
|
-
while (parent) {
|
|
1707
|
-
if (!parent.dirtyChildren) {
|
|
1708
|
-
parent.dirtyChildren = /* @__PURE__ */ new Set();
|
|
1709
|
-
}
|
|
1710
|
-
parent.dirtyChildren.add(node);
|
|
1711
|
-
parent = parent.parent;
|
|
1712
|
-
}
|
|
1713
|
-
return true;
|
|
1714
|
-
}
|
|
1715
|
-
}
|
|
1716
|
-
}
|
|
1717
|
-
function activateNodeFunction(node, lazyFn) {
|
|
1718
|
-
let update;
|
|
1719
|
-
let wasPromise;
|
|
1720
|
-
let ignoreThisUpdate;
|
|
1721
|
-
let isFirst = true;
|
|
1722
|
-
const activateFn = lazyFn;
|
|
1723
|
-
let activatedValue;
|
|
1724
|
-
let disposes = [];
|
|
1725
|
-
let refreshFn;
|
|
1726
|
-
function markDirty() {
|
|
1727
|
-
node.dirtyFn = refreshFn;
|
|
1728
|
-
globalState.dirtyNodes.add(node);
|
|
1729
|
-
}
|
|
1730
|
-
node.activatedObserveDispose = observe(
|
|
1731
|
-
() => {
|
|
1732
|
-
var _a, _b, _c, _d;
|
|
1733
|
-
if (isFirst) {
|
|
1734
|
-
isFirst = false;
|
|
1735
|
-
if (isFunction(getNodeValue(node))) {
|
|
1736
|
-
setNodeValue(node, void 0);
|
|
1737
|
-
}
|
|
1738
|
-
} else if (!isFlushing && refreshFn) {
|
|
1739
|
-
if (shouldIgnoreUnobserved(node, refreshFn)) {
|
|
1740
|
-
ignoreThisUpdate = true;
|
|
1741
|
-
return;
|
|
1742
|
-
}
|
|
1743
|
-
}
|
|
1744
|
-
let value = activateFn();
|
|
1745
|
-
let didSetToObs = false;
|
|
1746
|
-
const isObs = isObservable(value);
|
|
1747
|
-
if (isObs || node.linkedToNode) {
|
|
1748
|
-
didSetToObs = isObs;
|
|
1749
|
-
value = setToObservable(node, value);
|
|
1750
|
-
}
|
|
1751
|
-
if (isFunction(value) && value.length === 0) {
|
|
1752
|
-
value = value();
|
|
1753
|
-
}
|
|
1754
|
-
const activated = !isObs ? value == null ? void 0 : value[symbolLinked] : void 0;
|
|
1755
|
-
if (activated) {
|
|
1756
|
-
node.activationState = activated;
|
|
1757
|
-
value = void 0;
|
|
1758
|
-
}
|
|
1759
|
-
ignoreThisUpdate = false;
|
|
1760
|
-
wasPromise = isPromise(value);
|
|
1761
|
-
if (!node.activated) {
|
|
1762
|
-
node.activated = true;
|
|
1763
|
-
let activateNodeFn = activateNodeBase;
|
|
1764
|
-
if (activated == null ? void 0 : activated.synced) {
|
|
1765
|
-
activateNodeFn = globalState.activateSyncedNode;
|
|
1766
|
-
ignoreThisUpdate = true;
|
|
1767
|
-
}
|
|
1768
|
-
const result = activateNodeFn(node, value);
|
|
1769
|
-
update = result.update;
|
|
1770
|
-
let newValue = result.value;
|
|
1771
|
-
if (!didSetToObs && isObservable(newValue)) {
|
|
1772
|
-
newValue = setToObservable(node, newValue);
|
|
1773
|
-
}
|
|
1774
|
-
value = newValue != null ? newValue : activated == null ? void 0 : activated.initial;
|
|
1775
|
-
} else if (node.activationState) {
|
|
1776
|
-
const activated2 = node.activationState;
|
|
1777
|
-
if ((_b = (_a = node.state) == null ? void 0 : _a.peek()) == null ? void 0 : _b.sync) {
|
|
1778
|
-
node.state.sync();
|
|
1779
|
-
ignoreThisUpdate = true;
|
|
1780
|
-
} else {
|
|
1781
|
-
value = (_d = (_c = activated2.get) == null ? void 0 : _c.call(activated2)) != null ? _d : activated2.initial;
|
|
1782
|
-
}
|
|
1783
|
-
}
|
|
1784
|
-
wasPromise = wasPromise || isPromise(value);
|
|
1785
|
-
return value;
|
|
1786
|
-
},
|
|
1787
|
-
(e) => {
|
|
1788
|
-
const { value, nodes, refresh } = e;
|
|
1789
|
-
refreshFn = refresh;
|
|
1790
|
-
if (!ignoreThisUpdate) {
|
|
1791
|
-
if (!wasPromise || !globalState.isLoadingRemote) {
|
|
1792
|
-
if (wasPromise) {
|
|
1793
|
-
if (node.activationState) {
|
|
1794
|
-
const { initial } = node.activationState;
|
|
1795
|
-
if (value && isPromise(value)) {
|
|
1796
|
-
extractPromise(node, value, update);
|
|
1797
|
-
}
|
|
1798
|
-
if (isFunction(getNodeValue(node))) {
|
|
1799
|
-
setNodeValue(node, initial != null ? initial : void 0);
|
|
1800
|
-
}
|
|
1801
|
-
} else if (node.activated) {
|
|
1802
|
-
extractPromise(node, value, update);
|
|
1803
|
-
if (isFunction(getNodeValue(node))) {
|
|
1804
|
-
setNodeValue(node, void 0);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
} else {
|
|
1808
|
-
activatedValue = value;
|
|
1809
|
-
const isLoaded = node.state.isLoaded.peek();
|
|
1810
|
-
if (isLoaded || !isFunction(value)) {
|
|
1811
|
-
node.isComputing = true;
|
|
1812
|
-
set(node, value);
|
|
1813
|
-
node.isComputing = false;
|
|
1814
|
-
}
|
|
1815
|
-
if (!isLoaded) {
|
|
1816
|
-
node.state.assign({ isLoaded: true, error: void 0 });
|
|
1817
|
-
}
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
disposes.forEach((fn) => fn());
|
|
1821
|
-
disposes = [];
|
|
1822
|
-
nodes == null ? void 0 : nodes.forEach(({ node: node2, track }) => {
|
|
1823
|
-
disposes.push(onChange(node2, markDirty, { immediate: true, trackingType: track }));
|
|
1824
|
-
});
|
|
1825
|
-
}
|
|
1826
|
-
e.cancel = true;
|
|
1827
|
-
},
|
|
1828
|
-
{ fromComputed: true }
|
|
1829
|
-
);
|
|
1830
|
-
return activatedValue;
|
|
1831
|
-
}
|
|
1832
|
-
function activateNodeBase(node, value) {
|
|
1833
|
-
if (!node.state) {
|
|
1834
|
-
node.state = createObservable(
|
|
1835
|
-
{
|
|
1836
|
-
isLoaded: false
|
|
1837
|
-
},
|
|
1838
|
-
false,
|
|
1839
|
-
extractPromise,
|
|
1840
|
-
getProxy
|
|
1841
|
-
);
|
|
1842
|
-
}
|
|
1843
|
-
if (node.activationState) {
|
|
1844
|
-
const { set: setFn, get: getFn, initial } = node.activationState;
|
|
1845
|
-
value = getFn == null ? void 0 : getFn();
|
|
1846
|
-
if (value == void 0 || value === null) {
|
|
1847
|
-
value = initial;
|
|
1848
|
-
}
|
|
1849
|
-
if (setFn) {
|
|
1850
|
-
let allChanges = [];
|
|
1851
|
-
let latestValue = void 0;
|
|
1852
|
-
let runNumber = 0;
|
|
1853
|
-
const runChanges = (listenerParams) => {
|
|
1854
|
-
if (allChanges.length > 0) {
|
|
1855
|
-
let changes;
|
|
1856
|
-
let value2;
|
|
1857
|
-
let isFromPersist = false;
|
|
1858
|
-
let isFromSync = false;
|
|
1859
|
-
let getPrevious;
|
|
1860
|
-
if (listenerParams) {
|
|
1861
|
-
changes = listenerParams.changes;
|
|
1862
|
-
value2 = listenerParams.value;
|
|
1863
|
-
isFromPersist = listenerParams.isFromPersist;
|
|
1864
|
-
isFromSync = listenerParams.isFromSync;
|
|
1865
|
-
getPrevious = listenerParams.getPrevious;
|
|
1866
|
-
} else {
|
|
1867
|
-
changes = allChanges;
|
|
1868
|
-
value2 = latestValue;
|
|
1869
|
-
getPrevious = createPreviousHandler(value2, changes);
|
|
1870
|
-
}
|
|
1871
|
-
allChanges = [];
|
|
1872
|
-
latestValue = void 0;
|
|
1873
|
-
globalState.pendingNodes.delete(node);
|
|
1874
|
-
runNumber++;
|
|
1875
|
-
const thisRunNumber = runNumber;
|
|
1876
|
-
const run = () => {
|
|
1877
|
-
if (thisRunNumber !== runNumber) {
|
|
1878
|
-
return;
|
|
1879
|
-
}
|
|
1880
|
-
node.isComputing = true;
|
|
1881
|
-
setFn({
|
|
1882
|
-
value: value2,
|
|
1883
|
-
changes,
|
|
1884
|
-
isFromPersist,
|
|
1885
|
-
isFromSync,
|
|
1886
|
-
getPrevious
|
|
1887
|
-
});
|
|
1888
|
-
node.isComputing = false;
|
|
1889
|
-
};
|
|
1890
|
-
whenReady(node.state.isLoaded, run);
|
|
1891
|
-
}
|
|
1892
|
-
};
|
|
1893
|
-
const onChangeImmediate = ({ value: value2, changes }) => {
|
|
1894
|
-
if (!node.isComputing) {
|
|
1895
|
-
if (changes.length > 1 || !isFunction(changes[0].prevAtPath)) {
|
|
1896
|
-
latestValue = value2;
|
|
1897
|
-
if (allChanges.length > 0) {
|
|
1898
|
-
changes = changes.filter((change) => !isArraySubset(allChanges[0].path, change.path));
|
|
1899
|
-
}
|
|
1900
|
-
allChanges.push(...changes);
|
|
1901
|
-
globalState.pendingNodes.set(node, runChanges);
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
};
|
|
1905
|
-
onChange(node, onChangeImmediate, { immediate: true });
|
|
1906
|
-
onChange(node, runChanges);
|
|
1907
|
-
}
|
|
1908
|
-
}
|
|
1909
|
-
const update = ({ value: value2 }) => {
|
|
1910
|
-
if (!node.isComputing) {
|
|
1911
|
-
node.isComputing = true;
|
|
1912
|
-
set(node, value2);
|
|
1913
|
-
node.isComputing = false;
|
|
1914
|
-
}
|
|
1915
|
-
};
|
|
1916
|
-
return { update, value };
|
|
1917
|
-
}
|
|
1918
|
-
function setToObservable(node, value) {
|
|
1919
|
-
var _a;
|
|
1920
|
-
const linkedNode = value ? getNode(value) : void 0;
|
|
1921
|
-
if (linkedNode !== node && (linkedNode == null ? void 0 : linkedNode.linkedToNode) !== node) {
|
|
1922
|
-
node.linkedToNode = linkedNode;
|
|
1923
|
-
(_a = node.linkedToNodeDispose) == null ? void 0 : _a.call(node);
|
|
1924
|
-
if (linkedNode) {
|
|
1925
|
-
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
1926
|
-
linkedNode.linkedFromNodes.add(node);
|
|
1927
|
-
node.linkedToNodeDispose = onChange(
|
|
1928
|
-
linkedNode,
|
|
1929
|
-
() => {
|
|
1930
|
-
value = peekInternal(linkedNode);
|
|
1931
|
-
if (!isFunction(value)) {
|
|
1932
|
-
set(node, value);
|
|
1933
|
-
}
|
|
1934
|
-
},
|
|
1935
|
-
{ initial: true },
|
|
1936
|
-
/* @__PURE__ */ new Set([node])
|
|
1937
|
-
);
|
|
1938
|
-
}
|
|
1939
|
-
}
|
|
1940
|
-
return value;
|
|
1941
|
-
}
|
|
1942
|
-
function recursivelyAutoActivate(obj, node) {
|
|
1943
|
-
if (!node.recursivelyAutoActivated && (isObject(obj) || isArray(obj)) && !isHintOpaque(obj)) {
|
|
1944
|
-
node.recursivelyAutoActivated = true;
|
|
1945
|
-
const pathStack = [];
|
|
1946
|
-
const getNodeAtPath2 = () => {
|
|
1947
|
-
var _a;
|
|
1948
|
-
let childNode = node;
|
|
1949
|
-
for (let i = 0; i < pathStack.length; i++) {
|
|
1950
|
-
const key = pathStack[i];
|
|
1951
|
-
const value = (_a = getNodeValue(childNode)) == null ? void 0 : _a[key];
|
|
1952
|
-
childNode = getChildNode(childNode, key, isFunction(value) ? value : void 0);
|
|
1953
|
-
peekInternal(childNode);
|
|
1954
|
-
}
|
|
1955
|
-
return childNode;
|
|
1956
|
-
};
|
|
1957
|
-
recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2);
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
function recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2) {
|
|
1961
|
-
var _a;
|
|
1962
|
-
if ((isObject(obj) || isArray(obj)) && !isHintOpaque(obj) && !isHintPlain(obj)) {
|
|
1963
|
-
for (const key in obj) {
|
|
1964
|
-
if (hasOwnProperty.call(obj, key)) {
|
|
1965
|
-
const value = obj[key];
|
|
1966
|
-
if (isObservable(value)) {
|
|
1967
|
-
const childNode = getNodeAtPath2();
|
|
1968
|
-
extractFunctionOrComputed(childNode, key, value);
|
|
1969
|
-
delete childNode.lazy;
|
|
1970
|
-
} else {
|
|
1971
|
-
const linkedOptions = isFunction(value) && ((_a = value.prototype) == null ? void 0 : _a[symbolLinked]);
|
|
1972
|
-
if (linkedOptions) {
|
|
1973
|
-
const activate = linkedOptions.activate;
|
|
1974
|
-
if (!activate || activate === "auto") {
|
|
1975
|
-
const childNode = getNodeAtPath2();
|
|
1976
|
-
peek(getChildNode(childNode, key, value));
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
if (typeof value === "object") {
|
|
1981
|
-
pathStack.push(key);
|
|
1982
|
-
recursivelyAutoActivateInner(value, pathStack, getNodeAtPath2);
|
|
1983
|
-
pathStack.pop();
|
|
1984
|
-
}
|
|
1985
|
-
}
|
|
1986
|
-
}
|
|
1987
|
-
}
|
|
1988
|
-
}
|
|
1989
|
-
|
|
1990
|
-
// src/ObservablePrimitive.ts
|
|
1991
|
-
var fns = ["get", "set", "peek", "onChange", "toggle"];
|
|
1992
|
-
function ObservablePrimitiveClass(node) {
|
|
1993
|
-
this._node = node;
|
|
1994
|
-
for (let i = 0; i < fns.length; i++) {
|
|
1995
|
-
const key = fns[i];
|
|
1996
|
-
this[key] = this[key].bind(this);
|
|
1997
|
-
}
|
|
1998
|
-
}
|
|
1999
|
-
function proto(key, fn) {
|
|
2000
|
-
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2001
|
-
return fn.call(this, this._node, ...args);
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
proto("peek", (node) => {
|
|
2005
|
-
flushPending();
|
|
2006
|
-
return peek(node);
|
|
2007
|
-
});
|
|
2008
|
-
proto("get", (node, options) => {
|
|
2009
|
-
flushPending();
|
|
2010
|
-
return get(node, options);
|
|
2011
|
-
});
|
|
2012
|
-
proto("set", set);
|
|
2013
|
-
proto("onChange", onChange);
|
|
2014
|
-
Object.defineProperty(ObservablePrimitiveClass.prototype, symbolGetNode, {
|
|
2015
|
-
configurable: true,
|
|
2016
|
-
get() {
|
|
2017
|
-
return this._node;
|
|
2018
|
-
}
|
|
2019
|
-
});
|
|
2020
|
-
ObservablePrimitiveClass.prototype.toggle = function() {
|
|
2021
|
-
const value = this.peek();
|
|
2022
|
-
if (value === void 0 || value === null || isBoolean(value)) {
|
|
2023
|
-
this.set(!value);
|
|
2024
|
-
} else if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
2025
|
-
throw new Error("[legend-state] Cannot toggle a non-boolean value");
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
ObservablePrimitiveClass.prototype.delete = function() {
|
|
2029
|
-
this.set(void 0);
|
|
2030
|
-
return this;
|
|
2031
|
-
};
|
|
2032
|
-
|
|
2033
|
-
// src/configureLegendState.ts
|
|
2034
|
-
function configureLegendState({
|
|
2035
|
-
observableFunctions,
|
|
2036
|
-
observableProperties: observableProperties2,
|
|
2037
|
-
jsonReplacer,
|
|
2038
|
-
jsonReviver
|
|
2039
|
-
}) {
|
|
2040
|
-
if (observableFunctions) {
|
|
2041
|
-
for (const key in observableFunctions) {
|
|
2042
|
-
const fn = observableFunctions[key];
|
|
2043
|
-
observableFns.set(key, fn);
|
|
2044
|
-
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2045
|
-
return fn.call(this, this._node, ...args);
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
if (observableProperties2) {
|
|
2050
|
-
for (const key in observableProperties2) {
|
|
2051
|
-
const fns2 = observableProperties2[key];
|
|
2052
|
-
observableProperties.set(key, fns2);
|
|
2053
|
-
Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
|
|
2054
|
-
configurable: true,
|
|
2055
|
-
get() {
|
|
2056
|
-
return fns2.get.call(this, this._node);
|
|
2057
|
-
},
|
|
2058
|
-
set(value) {
|
|
2059
|
-
return fns2.set.call(this, this._node, value);
|
|
2060
|
-
}
|
|
2061
|
-
});
|
|
2062
|
-
}
|
|
2063
|
-
}
|
|
2064
|
-
if (jsonReplacer) {
|
|
2065
|
-
globalState.replacer = jsonReplacer;
|
|
2066
|
-
}
|
|
2067
|
-
if (jsonReviver) {
|
|
2068
|
-
globalState.reviver = jsonReviver;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
|
|
2072
|
-
exports.configureLegendState = configureLegendState;
|