@legendapp/state 3.0.0-alpha.3 → 3.0.0-alpha.30
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/CHANGELOG.md +831 -1
- package/LICENSE +21 -1
- package/README.md +141 -1
- package/babel.js +0 -2
- package/babel.mjs +0 -2
- package/config/enable$GetSet.js +2 -1
- package/config/enable$GetSet.mjs +2 -1
- package/config/enableReactTracking.js +2 -1
- package/config/enableReactTracking.mjs +2 -1
- package/config/enableReactUse.js +2 -1
- package/config/enableReactUse.mjs +2 -1
- package/config/enable_PeekAssign.js +2 -1
- package/config/enable_PeekAssign.mjs +2 -1
- package/config.d.mts +13 -0
- package/config.d.ts +13 -0
- package/config.js +2052 -0
- package/config.mjs +2050 -0
- package/helpers/trackHistory.js +2 -2
- package/helpers/trackHistory.mjs +2 -2
- package/index.d.mts +21 -302
- package/index.d.ts +21 -302
- package/index.js +274 -318
- package/index.mjs +275 -317
- package/observableInterfaces-Dilj6F92.d.mts +282 -0
- package/observableInterfaces-Dilj6F92.d.ts +282 -0
- package/package.json +11 -1
- package/persist-plugins/async-storage.d.mts +6 -3
- package/persist-plugins/async-storage.d.ts +6 -3
- package/persist-plugins/async-storage.js +12 -4
- package/persist-plugins/async-storage.mjs +12 -5
- package/persist-plugins/indexeddb.d.mts +6 -4
- package/persist-plugins/indexeddb.d.ts +6 -4
- package/persist-plugins/indexeddb.js +16 -6
- package/persist-plugins/indexeddb.mjs +16 -7
- package/persist-plugins/mmkv.d.mts +5 -1
- package/persist-plugins/mmkv.d.ts +5 -1
- package/persist-plugins/mmkv.js +14 -5
- package/persist-plugins/mmkv.mjs +14 -6
- package/react.d.mts +18 -14
- package/react.d.ts +18 -14
- package/react.js +57 -32
- package/react.mjs +58 -33
- package/sync-plugins/_transformObjectFields.d.mts +31 -0
- package/sync-plugins/_transformObjectFields.d.ts +31 -0
- package/sync-plugins/_transformObjectFields.js +114 -0
- package/sync-plugins/_transformObjectFields.mjs +110 -0
- package/sync-plugins/crud.d.mts +15 -23
- package/sync-plugins/crud.d.ts +15 -23
- package/sync-plugins/crud.js +213 -134
- package/sync-plugins/crud.mjs +214 -135
- package/sync-plugins/fetch.js +12 -8
- package/sync-plugins/fetch.mjs +13 -9
- package/sync-plugins/firebase.d.mts +26 -0
- package/sync-plugins/firebase.d.ts +26 -0
- package/sync-plugins/firebase.js +373 -0
- package/sync-plugins/firebase.mjs +368 -0
- package/sync-plugins/keel.d.mts +27 -10
- package/sync-plugins/keel.d.ts +27 -10
- package/sync-plugins/keel.js +40 -21
- package/sync-plugins/keel.mjs +40 -21
- package/sync-plugins/supabase.d.mts +12 -7
- package/sync-plugins/supabase.d.ts +12 -7
- package/sync-plugins/supabase.js +24 -13
- package/sync-plugins/supabase.mjs +25 -14
- package/sync-plugins/tanstack-query.d.mts +2 -2
- package/sync-plugins/tanstack-query.d.ts +2 -2
- package/sync-plugins/tanstack-query.js +3 -2
- package/sync-plugins/tanstack-query.mjs +3 -2
- package/sync-plugins/tanstack-react-query.d.mts +1 -1
- package/sync-plugins/tanstack-react-query.d.ts +1 -1
- package/sync.d.mts +68 -197
- package/sync.d.ts +68 -197
- package/sync.js +448 -283
- package/sync.mjs +454 -289
- package/types/babel.d.ts +12 -1
- package/.DS_Store +0 -0
- /package/config/{enable_GetSet.d.mts → enable$GetSet.d.mts} +0 -0
- /package/config/{enable_GetSet.d.ts → enable$GetSet.d.ts} +0 -0
package/index.js
CHANGED
|
@@ -31,17 +31,22 @@ function isPromise(obj) {
|
|
|
31
31
|
return obj instanceof Promise;
|
|
32
32
|
}
|
|
33
33
|
function isMap(obj) {
|
|
34
|
-
return obj instanceof Map;
|
|
34
|
+
return obj instanceof Map || obj instanceof WeakMap;
|
|
35
|
+
}
|
|
36
|
+
function isSet(obj) {
|
|
37
|
+
return obj instanceof Set || obj instanceof WeakSet;
|
|
35
38
|
}
|
|
36
39
|
function isNumber(obj) {
|
|
37
40
|
const n = obj;
|
|
38
|
-
return n - n < 1;
|
|
41
|
+
return typeof n === "number" && n - n < 1;
|
|
39
42
|
}
|
|
40
43
|
function isEmpty(obj) {
|
|
41
44
|
if (!obj)
|
|
42
45
|
return false;
|
|
43
46
|
if (isArray(obj))
|
|
44
47
|
return obj.length === 0;
|
|
48
|
+
if (isMap(obj) || isSet(obj))
|
|
49
|
+
return obj.size === 0;
|
|
45
50
|
for (const key in obj) {
|
|
46
51
|
if (hasOwnProperty.call(obj, key)) {
|
|
47
52
|
return false;
|
|
@@ -56,27 +61,25 @@ var setPrimitives = /* @__PURE__ */ new Set(["boolean", "string", "number"]);
|
|
|
56
61
|
function isActualPrimitive(arg) {
|
|
57
62
|
return setPrimitives.has(typeof arg);
|
|
58
63
|
}
|
|
59
|
-
function
|
|
64
|
+
function isChildNode(node) {
|
|
60
65
|
return !!node.parent;
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// src/globals.ts
|
|
64
69
|
var symbolToPrimitive = Symbol.toPrimitive;
|
|
70
|
+
var symbolIterator = Symbol.iterator;
|
|
65
71
|
var symbolGetNode = Symbol("getNode");
|
|
66
72
|
var symbolDelete = /* @__PURE__ */ Symbol("delete");
|
|
67
73
|
var symbolOpaque = Symbol("opaque");
|
|
68
74
|
var optimized = Symbol("optimized");
|
|
69
75
|
var symbolLinked = Symbol("linked");
|
|
70
76
|
var globalState = {
|
|
71
|
-
isLoadingLocal: false,
|
|
72
|
-
isMerging: false,
|
|
73
|
-
isLoadingRemote: false,
|
|
74
|
-
activateSyncedNode: void 0,
|
|
75
77
|
pendingNodes: /* @__PURE__ */ new Map(),
|
|
76
|
-
dirtyNodes: /* @__PURE__ */ new Set()
|
|
77
|
-
replacer: void 0,
|
|
78
|
-
reviver: void 0
|
|
78
|
+
dirtyNodes: /* @__PURE__ */ new Set()
|
|
79
79
|
};
|
|
80
|
+
function isOpaqueObject(value) {
|
|
81
|
+
return value && (value[symbolOpaque] || value["$$typeof"]);
|
|
82
|
+
}
|
|
80
83
|
function getPathType(value) {
|
|
81
84
|
return isArray(value) ? "array" : isMap(value) ? "map" : value instanceof Set ? "set" : "object";
|
|
82
85
|
}
|
|
@@ -118,10 +121,10 @@ function reviver(key, value) {
|
|
|
118
121
|
return value;
|
|
119
122
|
}
|
|
120
123
|
function safeStringify(value) {
|
|
121
|
-
return JSON.stringify(value, replacer);
|
|
124
|
+
return value ? JSON.stringify(value, replacer) : value;
|
|
122
125
|
}
|
|
123
126
|
function safeParse(value) {
|
|
124
|
-
return JSON.parse(value, reviver);
|
|
127
|
+
return value ? JSON.parse(value, reviver) : value;
|
|
125
128
|
}
|
|
126
129
|
function clone(value) {
|
|
127
130
|
return safeParse(safeStringify(value));
|
|
@@ -137,29 +140,31 @@ function isEvent(value$) {
|
|
|
137
140
|
return value$ && ((_a = value$[symbolGetNode]) == null ? void 0 : _a.isEvent);
|
|
138
141
|
}
|
|
139
142
|
function setNodeValue(node, newValue) {
|
|
140
|
-
var _a
|
|
143
|
+
var _a;
|
|
141
144
|
const parentNode = (_a = node.parent) != null ? _a : node;
|
|
142
145
|
const key = node.parent ? node.key : "_";
|
|
143
146
|
const isDelete = newValue === symbolDelete;
|
|
144
147
|
if (isDelete)
|
|
145
148
|
newValue = void 0;
|
|
146
149
|
const parentValue = node.parent ? ensureNodeValue(parentNode) : parentNode.root;
|
|
147
|
-
const
|
|
150
|
+
const useSetFn = isSet(parentValue);
|
|
151
|
+
const useMapFn = isMap(parentValue);
|
|
152
|
+
const prevValue = useSetFn ? key : useMapFn ? parentValue.get(key) : parentValue[key];
|
|
148
153
|
const isFunc = isFunction(newValue);
|
|
149
154
|
newValue = !parentNode.isAssigning && isFunc && !isFunction(prevValue) ? newValue(prevValue) : newValue;
|
|
150
|
-
if (
|
|
155
|
+
if (newValue !== prevValue) {
|
|
151
156
|
try {
|
|
152
157
|
parentNode.isSetting = (parentNode.isSetting || 0) + 1;
|
|
153
|
-
const useMapFn = isMap(parentValue);
|
|
154
158
|
if (isDelete) {
|
|
155
|
-
if (useMapFn) {
|
|
159
|
+
if (useMapFn || useSetFn) {
|
|
156
160
|
parentValue.delete(key);
|
|
157
161
|
} else {
|
|
158
162
|
delete parentValue[key];
|
|
159
163
|
}
|
|
160
164
|
} else {
|
|
161
|
-
|
|
162
|
-
|
|
165
|
+
if (useSetFn) {
|
|
166
|
+
parentValue.add(newValue);
|
|
167
|
+
} else if (useMapFn) {
|
|
163
168
|
parentValue.set(key, newValue);
|
|
164
169
|
} else {
|
|
165
170
|
parentValue[key] = newValue;
|
|
@@ -175,7 +180,7 @@ var arrNodeKeys = [];
|
|
|
175
180
|
function getNodeValue(node) {
|
|
176
181
|
let count = 0;
|
|
177
182
|
let n = node;
|
|
178
|
-
while (
|
|
183
|
+
while (isChildNode(n)) {
|
|
179
184
|
arrNodeKeys[count++] = n.key;
|
|
180
185
|
n = n.parent;
|
|
181
186
|
}
|
|
@@ -215,7 +220,7 @@ function getChildNode(node, key, asFunction) {
|
|
|
215
220
|
function ensureNodeValue(node) {
|
|
216
221
|
let value = getNodeValue(node);
|
|
217
222
|
if (!value || isFunction(value)) {
|
|
218
|
-
if (
|
|
223
|
+
if (isChildNode(node)) {
|
|
219
224
|
const parent = ensureNodeValue(node.parent);
|
|
220
225
|
value = parent[node.key] = {};
|
|
221
226
|
} else {
|
|
@@ -284,11 +289,16 @@ function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
|
284
289
|
return obj;
|
|
285
290
|
} else if (o[p] === void 0 && value === void 0 && i === path.length - 1) {
|
|
286
291
|
return obj;
|
|
287
|
-
} else if (o[p] === void 0 || o[p] === null) {
|
|
288
|
-
|
|
292
|
+
} else if (i < path.length - 1 && (o[p] === void 0 || o[p] === null)) {
|
|
293
|
+
const child = initializePathType(pathTypes[i]);
|
|
294
|
+
if (isMap(o)) {
|
|
295
|
+
o.set(p, child);
|
|
296
|
+
} else {
|
|
297
|
+
o[p] = child;
|
|
298
|
+
}
|
|
289
299
|
}
|
|
290
300
|
if (i < path.length - 1) {
|
|
291
|
-
o = o[p];
|
|
301
|
+
o = isMap(o) ? o.get(p) : o[p];
|
|
292
302
|
if (oFull) {
|
|
293
303
|
oFull = oFull[p];
|
|
294
304
|
}
|
|
@@ -297,13 +307,13 @@ function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
|
297
307
|
}
|
|
298
308
|
if (p === void 0) {
|
|
299
309
|
if (mode === "merge") {
|
|
300
|
-
obj =
|
|
310
|
+
obj = deepMerge(obj, value);
|
|
301
311
|
} else {
|
|
302
312
|
obj = value;
|
|
303
313
|
}
|
|
304
314
|
} else {
|
|
305
315
|
if (mode === "merge") {
|
|
306
|
-
o[p] =
|
|
316
|
+
o[p] = deepMerge(o[p], value);
|
|
307
317
|
} else if (isMap(o)) {
|
|
308
318
|
o.set(p, value);
|
|
309
319
|
} else {
|
|
@@ -312,80 +322,59 @@ function setAtPath(obj, path, pathTypes, value, mode, fullObj, restore) {
|
|
|
312
322
|
}
|
|
313
323
|
return obj;
|
|
314
324
|
}
|
|
315
|
-
function setInObservableAtPath(value$, path, pathTypes, value, mode) {
|
|
316
|
-
let o = value$;
|
|
317
|
-
let v = value;
|
|
318
|
-
for (let i = 0; i < path.length; i++) {
|
|
319
|
-
const p = path[i];
|
|
320
|
-
if (!o.peek()[p]) {
|
|
321
|
-
o[p].set(initializePathType(pathTypes[i]));
|
|
322
|
-
}
|
|
323
|
-
o = o[p];
|
|
324
|
-
v = v[p];
|
|
325
|
-
}
|
|
326
|
-
if (v === symbolDelete) {
|
|
327
|
-
o.delete();
|
|
328
|
-
} else if (mode === "assign" && o.assign && isObject(o.peek())) {
|
|
329
|
-
o.assign(v);
|
|
330
|
-
} else if (mode === "merge") {
|
|
331
|
-
mergeIntoObservable(o, v);
|
|
332
|
-
} else {
|
|
333
|
-
o.set(v);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
325
|
function mergeIntoObservable(target, ...sources) {
|
|
326
|
+
if (process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") {
|
|
327
|
+
if (!isObservable(target)) {
|
|
328
|
+
console.error("[legend-state] should only use mergeIntoObservable with observables");
|
|
329
|
+
}
|
|
330
|
+
}
|
|
337
331
|
beginBatch();
|
|
338
|
-
globalState.isMerging = true;
|
|
339
332
|
for (let i = 0; i < sources.length; i++) {
|
|
340
|
-
|
|
333
|
+
_mergeIntoObservable(
|
|
341
334
|
target,
|
|
342
335
|
sources[i],
|
|
343
336
|
/*assign*/
|
|
344
|
-
i < sources.length - 1
|
|
337
|
+
i < sources.length - 1,
|
|
338
|
+
0
|
|
345
339
|
);
|
|
346
340
|
}
|
|
347
|
-
globalState.isMerging = false;
|
|
348
341
|
endBatch();
|
|
349
342
|
return target;
|
|
350
343
|
}
|
|
351
|
-
function _mergeIntoObservable(target, source, assign2) {
|
|
352
|
-
var _a;
|
|
344
|
+
function _mergeIntoObservable(target, source, assign2, levelsDeep) {
|
|
353
345
|
if (isObservable(source)) {
|
|
354
346
|
source = source.peek();
|
|
355
347
|
}
|
|
356
|
-
const
|
|
357
|
-
const targetValue = needsSet ? target.peek() : target;
|
|
348
|
+
const targetValue = target.peek();
|
|
358
349
|
const isTargetArr = isArray(targetValue);
|
|
359
350
|
const isTargetObj = !isTargetArr && isObject(targetValue);
|
|
360
|
-
|
|
361
|
-
|
|
351
|
+
const isSourceMap = isMap(source);
|
|
352
|
+
const isSourceSet = isSet(source);
|
|
353
|
+
if (isSourceSet && isSet(targetValue)) {
|
|
354
|
+
target.set(/* @__PURE__ */ new Set([...source, ...targetValue]));
|
|
355
|
+
} else if (isTargetObj && isObject(source) && !isEmpty(targetValue) || isTargetArr && targetValue.length > 0) {
|
|
356
|
+
const keys = isSourceMap || isSourceSet ? Array.from(source.keys()) : Object.keys(source);
|
|
362
357
|
for (let i = 0; i < keys.length; i++) {
|
|
363
358
|
const key = keys[i];
|
|
364
|
-
const sourceValue = source[key];
|
|
359
|
+
const sourceValue = isSourceSet ? key : isSourceMap ? source.get(key) : source[key];
|
|
365
360
|
if (sourceValue === symbolDelete) {
|
|
366
|
-
|
|
361
|
+
target[key].delete();
|
|
367
362
|
} else {
|
|
368
363
|
const isObj = isObject(sourceValue);
|
|
369
364
|
const isArr = !isObj && isArray(sourceValue);
|
|
370
365
|
const targetChild = target[key];
|
|
371
|
-
if ((isObj || isArr) && targetChild
|
|
372
|
-
if (
|
|
373
|
-
target[key] = assign2 ? isArr ? [...sourceValue] : { ...sourceValue } : sourceValue;
|
|
374
|
-
} else {
|
|
375
|
-
_mergeIntoObservable(targetChild, sourceValue);
|
|
376
|
-
}
|
|
377
|
-
} else {
|
|
378
|
-
if (needsSet) {
|
|
366
|
+
if ((isObj || isArr) && targetChild) {
|
|
367
|
+
if (levelsDeep > 0 && isEmpty(sourceValue)) {
|
|
379
368
|
targetChild.set(sourceValue);
|
|
380
|
-
} else {
|
|
381
|
-
const toSet = isObject(sourceValue) ? { ...sourceValue } : isArray(sourceValue) ? [...sourceValue] : sourceValue;
|
|
382
|
-
target[key] = toSet;
|
|
383
369
|
}
|
|
370
|
+
_mergeIntoObservable(targetChild, sourceValue, false, levelsDeep + 1);
|
|
371
|
+
} else {
|
|
372
|
+
targetChild.set(sourceValue);
|
|
384
373
|
}
|
|
385
374
|
}
|
|
386
375
|
}
|
|
387
376
|
} else if (source !== void 0) {
|
|
388
|
-
|
|
377
|
+
target.set(source);
|
|
389
378
|
}
|
|
390
379
|
return target;
|
|
391
380
|
}
|
|
@@ -422,12 +411,13 @@ function initializePathType(pathType) {
|
|
|
422
411
|
switch (pathType) {
|
|
423
412
|
case "array":
|
|
424
413
|
return [];
|
|
425
|
-
case "object":
|
|
426
|
-
return {};
|
|
427
414
|
case "map":
|
|
428
415
|
return /* @__PURE__ */ new Map();
|
|
429
416
|
case "set":
|
|
430
417
|
return /* @__PURE__ */ new Set();
|
|
418
|
+
case "object":
|
|
419
|
+
default:
|
|
420
|
+
return {};
|
|
431
421
|
}
|
|
432
422
|
}
|
|
433
423
|
function applyChange(value, change, applyPrevious) {
|
|
@@ -440,6 +430,33 @@ function applyChanges(value, changes, applyPrevious) {
|
|
|
440
430
|
}
|
|
441
431
|
return value;
|
|
442
432
|
}
|
|
433
|
+
function deepMerge(target, ...sources) {
|
|
434
|
+
if (isPrimitive(target)) {
|
|
435
|
+
return sources[sources.length - 1];
|
|
436
|
+
}
|
|
437
|
+
let result = isArray(target) ? [...target] : { ...target };
|
|
438
|
+
for (let i = 0; i < sources.length; i++) {
|
|
439
|
+
const obj2 = sources[i];
|
|
440
|
+
if (isObject(obj2) || isArray(obj2)) {
|
|
441
|
+
const objTarget = obj2;
|
|
442
|
+
for (const key in objTarget) {
|
|
443
|
+
if (hasOwnProperty.call(objTarget, key)) {
|
|
444
|
+
if (objTarget[key] instanceof Object && !isObservable(objTarget[key]) && Object.keys(objTarget[key]).length > 0) {
|
|
445
|
+
result[key] = deepMerge(
|
|
446
|
+
result[key] || (isArray(objTarget[key]) ? [] : {}),
|
|
447
|
+
objTarget[key]
|
|
448
|
+
);
|
|
449
|
+
} else {
|
|
450
|
+
result[key] = objTarget[key];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
} else {
|
|
455
|
+
result = obj2;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return result;
|
|
459
|
+
}
|
|
443
460
|
|
|
444
461
|
// src/batching.ts
|
|
445
462
|
var timeout;
|
|
@@ -486,9 +503,9 @@ function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
|
486
503
|
changesInBatch,
|
|
487
504
|
node,
|
|
488
505
|
/*loading*/
|
|
489
|
-
globalState.isLoadingLocal,
|
|
506
|
+
!!globalState.isLoadingLocal,
|
|
490
507
|
/*remote*/
|
|
491
|
-
globalState.isLoadingRemote,
|
|
508
|
+
!!globalState.isLoadingRemote,
|
|
492
509
|
value,
|
|
493
510
|
[],
|
|
494
511
|
[],
|
|
@@ -499,31 +516,35 @@ function notify(node, value, prev, level, whenOptimizedOnlyIf) {
|
|
|
499
516
|
level,
|
|
500
517
|
whenOptimizedOnlyIf
|
|
501
518
|
);
|
|
502
|
-
if (changesInBatch.size) {
|
|
503
|
-
batchNotifyChanges(
|
|
504
|
-
changesInBatch,
|
|
505
|
-
/*immediate*/
|
|
506
|
-
true
|
|
507
|
-
);
|
|
508
|
-
}
|
|
509
519
|
const existing = _batchMap.get(node);
|
|
510
520
|
if (existing) {
|
|
511
|
-
existing.
|
|
521
|
+
if (existing.prev === value) {
|
|
522
|
+
_batchMap.delete(node);
|
|
523
|
+
} else {
|
|
524
|
+
existing.value = value;
|
|
525
|
+
}
|
|
512
526
|
} else {
|
|
513
527
|
_batchMap.set(node, {
|
|
514
528
|
value,
|
|
515
529
|
prev,
|
|
516
530
|
level,
|
|
517
531
|
whenOptimizedOnlyIf,
|
|
518
|
-
|
|
519
|
-
|
|
532
|
+
isFromSync: !!globalState.isLoadingRemote,
|
|
533
|
+
isFromPersist: !!globalState.isLoadingLocal
|
|
520
534
|
});
|
|
521
535
|
}
|
|
536
|
+
if (changesInBatch.size) {
|
|
537
|
+
batchNotifyChanges(
|
|
538
|
+
changesInBatch,
|
|
539
|
+
/*immediate*/
|
|
540
|
+
true
|
|
541
|
+
);
|
|
542
|
+
}
|
|
522
543
|
if (numInBatch <= 0) {
|
|
523
544
|
runBatch();
|
|
524
545
|
}
|
|
525
546
|
}
|
|
526
|
-
function computeChangesAtNode(changesInBatch, node,
|
|
547
|
+
function computeChangesAtNode(changesInBatch, node, isFromPersist, isFromSync, value, path, pathTypes, valueAtPath, prevAtPath, immediate, level, whenOptimizedOnlyIf) {
|
|
527
548
|
if (immediate ? node.listenersImmediate : node.listeners) {
|
|
528
549
|
const change = {
|
|
529
550
|
path,
|
|
@@ -536,13 +557,14 @@ function computeChangesAtNode(changesInBatch, node, loading, remote, value, path
|
|
|
536
557
|
const { changes } = changeInBatch;
|
|
537
558
|
if (!isArraySubset(changes[0].path, change.path)) {
|
|
538
559
|
changes.push(change);
|
|
560
|
+
changeInBatch.level = Math.min(changeInBatch.level, level);
|
|
539
561
|
}
|
|
540
562
|
} else {
|
|
541
563
|
changesInBatch.set(node, {
|
|
542
564
|
level,
|
|
543
565
|
value,
|
|
544
|
-
|
|
545
|
-
|
|
566
|
+
isFromSync,
|
|
567
|
+
isFromPersist,
|
|
546
568
|
whenOptimizedOnlyIf,
|
|
547
569
|
changes: [change]
|
|
548
570
|
});
|
|
@@ -606,7 +628,7 @@ function computeChangesRecursive(changesInBatch, node, loading, remote, value, p
|
|
|
606
628
|
}
|
|
607
629
|
function batchNotifyChanges(changesInBatch, immediate) {
|
|
608
630
|
const listenersNotified = /* @__PURE__ */ new Set();
|
|
609
|
-
changesInBatch.forEach(({ changes, level, value,
|
|
631
|
+
changesInBatch.forEach(({ changes, level, value, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
610
632
|
const listeners = immediate ? node.listenersImmediate : node.listeners;
|
|
611
633
|
if (listeners) {
|
|
612
634
|
let listenerParams;
|
|
@@ -620,8 +642,8 @@ function batchNotifyChanges(changesInBatch, immediate) {
|
|
|
620
642
|
if (!noArgs && !listenerParams) {
|
|
621
643
|
listenerParams = {
|
|
622
644
|
value,
|
|
623
|
-
|
|
624
|
-
|
|
645
|
+
isFromPersist,
|
|
646
|
+
isFromSync,
|
|
625
647
|
getPrevious: createPreviousHandler(value, changes),
|
|
626
648
|
changes
|
|
627
649
|
};
|
|
@@ -649,12 +671,12 @@ function runBatch() {
|
|
|
649
671
|
const map = _batchMap;
|
|
650
672
|
_batchMap = /* @__PURE__ */ new Map();
|
|
651
673
|
const changesInBatch = /* @__PURE__ */ new Map();
|
|
652
|
-
map.forEach(({ value, prev, level,
|
|
674
|
+
map.forEach(({ value, prev, level, isFromPersist, isFromSync, whenOptimizedOnlyIf }, node) => {
|
|
653
675
|
computeChangesRecursive(
|
|
654
676
|
changesInBatch,
|
|
655
677
|
node,
|
|
656
|
-
|
|
657
|
-
|
|
678
|
+
isFromPersist,
|
|
679
|
+
isFromSync,
|
|
658
680
|
value,
|
|
659
681
|
[],
|
|
660
682
|
[],
|
|
@@ -713,21 +735,6 @@ function getNodeAtPath(obj, path) {
|
|
|
713
735
|
return o;
|
|
714
736
|
}
|
|
715
737
|
|
|
716
|
-
// src/linked.ts
|
|
717
|
-
function linked(params, options) {
|
|
718
|
-
if (isFunction(params)) {
|
|
719
|
-
params = { get: params };
|
|
720
|
-
}
|
|
721
|
-
if (options) {
|
|
722
|
-
params = { ...params, ...options };
|
|
723
|
-
}
|
|
724
|
-
const ret = function() {
|
|
725
|
-
return { [symbolLinked]: params };
|
|
726
|
-
};
|
|
727
|
-
ret.prototype[symbolLinked] = params;
|
|
728
|
-
return ret;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
738
|
// src/createObservable.ts
|
|
732
739
|
function createObservable(value, makePrimitive, extractPromise2, createObject, createPrimitive) {
|
|
733
740
|
if (isObservable(value)) {
|
|
@@ -757,6 +764,21 @@ function createObservable(value, makePrimitive, extractPromise2, createObject, c
|
|
|
757
764
|
return obs;
|
|
758
765
|
}
|
|
759
766
|
|
|
767
|
+
// src/linked.ts
|
|
768
|
+
function linked(params, options) {
|
|
769
|
+
if (isFunction(params)) {
|
|
770
|
+
params = { get: params };
|
|
771
|
+
}
|
|
772
|
+
if (options) {
|
|
773
|
+
params = { ...params, ...options };
|
|
774
|
+
}
|
|
775
|
+
const ret = function() {
|
|
776
|
+
return { [symbolLinked]: params };
|
|
777
|
+
};
|
|
778
|
+
ret.prototype[symbolLinked] = params;
|
|
779
|
+
return ret;
|
|
780
|
+
}
|
|
781
|
+
|
|
760
782
|
// src/onChange.ts
|
|
761
783
|
function onChange(node, callback, options = {}, fromLinks) {
|
|
762
784
|
var _a;
|
|
@@ -781,8 +803,8 @@ function onChange(node, callback, options = {}, fromLinks) {
|
|
|
781
803
|
const value = getNodeValue(node);
|
|
782
804
|
callback({
|
|
783
805
|
value,
|
|
784
|
-
|
|
785
|
-
|
|
806
|
+
isFromPersist: true,
|
|
807
|
+
isFromSync: false,
|
|
786
808
|
changes: [
|
|
787
809
|
{
|
|
788
810
|
path: [],
|
|
@@ -838,14 +860,14 @@ function onChange(node, callback, options = {}, fromLinks) {
|
|
|
838
860
|
};
|
|
839
861
|
}
|
|
840
862
|
function createCb(linkedFromNode, path, callback) {
|
|
841
|
-
let
|
|
842
|
-
return function({ value: valueA,
|
|
843
|
-
const
|
|
863
|
+
let prevAtPath = deconstructObjectWithPath(path, [], getNodeValue(linkedFromNode));
|
|
864
|
+
return function({ value: valueA, isFromPersist, isFromSync }) {
|
|
865
|
+
const valueAtPath = deconstructObjectWithPath(path, [], valueA);
|
|
844
866
|
if (valueAtPath !== prevAtPath) {
|
|
845
867
|
callback({
|
|
846
868
|
value: valueAtPath,
|
|
847
|
-
|
|
848
|
-
|
|
869
|
+
isFromPersist,
|
|
870
|
+
isFromSync,
|
|
849
871
|
changes: [
|
|
850
872
|
{
|
|
851
873
|
path: [],
|
|
@@ -860,16 +882,6 @@ function createCb(linkedFromNode, path, callback) {
|
|
|
860
882
|
prevAtPath = valueAtPath;
|
|
861
883
|
};
|
|
862
884
|
}
|
|
863
|
-
function getValueAtPath2(obj, path) {
|
|
864
|
-
let o = obj;
|
|
865
|
-
const pathTypes = [];
|
|
866
|
-
for (let i = 0; o && i < path.length; i++) {
|
|
867
|
-
pathTypes.push(isArray(o) ? "array" : "object");
|
|
868
|
-
const p = path[i];
|
|
869
|
-
o = o[p];
|
|
870
|
-
}
|
|
871
|
-
return { valueAtPath: o, pathTypes };
|
|
872
|
-
}
|
|
873
885
|
|
|
874
886
|
// src/setupTracking.ts
|
|
875
887
|
function setupTracking(nodes, update, noArgs, immediate) {
|
|
@@ -965,12 +977,17 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
965
977
|
options = reactionOrOptions;
|
|
966
978
|
}
|
|
967
979
|
let dispose;
|
|
980
|
+
let isRunning = false;
|
|
968
981
|
const e = { num: 0 };
|
|
969
982
|
const update = function() {
|
|
983
|
+
if (isRunning) {
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
970
986
|
if (e.onCleanup) {
|
|
971
987
|
e.onCleanup();
|
|
972
988
|
e.onCleanup = void 0;
|
|
973
989
|
}
|
|
990
|
+
isRunning = true;
|
|
974
991
|
beginBatch();
|
|
975
992
|
delete e.value;
|
|
976
993
|
dispose == null ? void 0 : dispose();
|
|
@@ -984,6 +1001,7 @@ function observe(selectorOrRun, reactionOrOptions, options) {
|
|
|
984
1001
|
e.onCleanupReaction = void 0;
|
|
985
1002
|
}
|
|
986
1003
|
endBatch();
|
|
1004
|
+
isRunning = false;
|
|
987
1005
|
if (reaction && ((options == null ? void 0 : options.fromComputed) || (e.num > 0 || !isEvent(selectorOrRun)) && (e.previous !== e.value || typeof e.value === "object"))) {
|
|
988
1006
|
reaction(e);
|
|
989
1007
|
}
|
|
@@ -1067,6 +1085,7 @@ var ArrayLoopers = /* @__PURE__ */ new Set([
|
|
|
1067
1085
|
"filter",
|
|
1068
1086
|
"find",
|
|
1069
1087
|
"findIndex",
|
|
1088
|
+
"flatMap",
|
|
1070
1089
|
"forEach",
|
|
1071
1090
|
"join",
|
|
1072
1091
|
"map",
|
|
@@ -1096,7 +1115,7 @@ function collectionSetter(node, target, prop, ...args) {
|
|
|
1096
1115
|
const prevValue = target.slice();
|
|
1097
1116
|
const ret = target[prop].apply(target, args);
|
|
1098
1117
|
if (node) {
|
|
1099
|
-
const hasParent =
|
|
1118
|
+
const hasParent = isChildNode(node);
|
|
1100
1119
|
const key = hasParent ? node.key : "_";
|
|
1101
1120
|
const parentValue = hasParent ? getNodeValue(node.parent) : node.root;
|
|
1102
1121
|
parentValue[key] = prevValue;
|
|
@@ -1120,7 +1139,7 @@ function updateNodes(parent, obj, prevValue) {
|
|
|
1120
1139
|
}
|
|
1121
1140
|
__devUpdateNodes.add(obj);
|
|
1122
1141
|
}
|
|
1123
|
-
if (isObject(obj) && obj
|
|
1142
|
+
if (isObject(obj) && isOpaqueObject(obj) || isObject(prevValue) && isOpaqueObject(prevValue)) {
|
|
1124
1143
|
const isDiff = obj !== prevValue;
|
|
1125
1144
|
if (isDiff) {
|
|
1126
1145
|
if (parent.listeners || parent.listenersImmediate) {
|
|
@@ -1308,10 +1327,10 @@ var proxyHandler = {
|
|
|
1308
1327
|
if (p === symbolGetNode) {
|
|
1309
1328
|
return node;
|
|
1310
1329
|
}
|
|
1311
|
-
if (p === "apply") {
|
|
1330
|
+
if (p === "apply" || p === "call") {
|
|
1312
1331
|
const nodeValue = getNodeValue(node);
|
|
1313
1332
|
if (isFunction(nodeValue)) {
|
|
1314
|
-
return nodeValue
|
|
1333
|
+
return nodeValue[p];
|
|
1315
1334
|
}
|
|
1316
1335
|
}
|
|
1317
1336
|
let value = peekInternal(
|
|
@@ -1319,11 +1338,14 @@ var proxyHandler = {
|
|
|
1319
1338
|
/*activateRecursive*/
|
|
1320
1339
|
p === "get" || p === "peek"
|
|
1321
1340
|
);
|
|
1341
|
+
if (p === symbolIterator) {
|
|
1342
|
+
return !value || isPrimitive(value) ? void 0 : value[p];
|
|
1343
|
+
}
|
|
1322
1344
|
const targetNode = node.linkedToNode || (value == null ? void 0 : value[symbolGetNode]);
|
|
1323
1345
|
if (targetNode && p !== "onChange") {
|
|
1324
1346
|
return proxyHandler.get(targetNode, p, receiver);
|
|
1325
1347
|
}
|
|
1326
|
-
if (isMap(value) || value
|
|
1348
|
+
if (isMap(value) || isSet(value)) {
|
|
1327
1349
|
const ret = handlerMapSet(node, p, value);
|
|
1328
1350
|
if (ret !== void 0) {
|
|
1329
1351
|
return ret;
|
|
@@ -1353,7 +1375,7 @@ var proxyHandler = {
|
|
|
1353
1375
|
return property.get(node);
|
|
1354
1376
|
}
|
|
1355
1377
|
let vProp = value == null ? void 0 : value[p];
|
|
1356
|
-
if (isObject(value) && value
|
|
1378
|
+
if (isObject(value) && isOpaqueObject(value)) {
|
|
1357
1379
|
return vProp;
|
|
1358
1380
|
}
|
|
1359
1381
|
const fnOrComputed = (_a = node.functions) == null ? void 0 : _a.get(p);
|
|
@@ -1415,7 +1437,7 @@ var proxyHandler = {
|
|
|
1415
1437
|
return vProp.bind(value);
|
|
1416
1438
|
}
|
|
1417
1439
|
if (isPrimitive(vProp)) {
|
|
1418
|
-
if (
|
|
1440
|
+
if (p === "length" && isArray(value)) {
|
|
1419
1441
|
updateTracking(node, true);
|
|
1420
1442
|
return vProp;
|
|
1421
1443
|
}
|
|
@@ -1519,11 +1541,17 @@ function setKey(node, key, newValue, level) {
|
|
|
1519
1541
|
} else {
|
|
1520
1542
|
const { newValue: savedValue, prevValue } = setNodeValue(childNode, newValue);
|
|
1521
1543
|
const isPrim = isPrimitive(savedValue) || savedValue instanceof Date;
|
|
1522
|
-
if (!equals(savedValue, prevValue)) {
|
|
1523
|
-
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level);
|
|
1524
|
-
}
|
|
1525
1544
|
if (!isPrim) {
|
|
1526
|
-
|
|
1545
|
+
let parent = childNode;
|
|
1546
|
+
do {
|
|
1547
|
+
parent.needsExtract = true;
|
|
1548
|
+
parent.recursivelyAutoActivated = false;
|
|
1549
|
+
} while (parent = parent.parent);
|
|
1550
|
+
}
|
|
1551
|
+
const notify2 = !equals(savedValue, prevValue);
|
|
1552
|
+
const forceNotify = !notify2 && childNode.isComputing && !isPrim;
|
|
1553
|
+
if (notify2 || forceNotify) {
|
|
1554
|
+
updateNodesAndNotify(node, savedValue, prevValue, childNode, isPrim, isRoot, level, forceNotify);
|
|
1527
1555
|
}
|
|
1528
1556
|
extractFunctionOrComputed(node, key, savedValue);
|
|
1529
1557
|
}
|
|
@@ -1538,6 +1566,8 @@ function assign(node, value) {
|
|
|
1538
1566
|
const currentValue = getNodeValue(node);
|
|
1539
1567
|
if (isMap(currentValue)) {
|
|
1540
1568
|
value.forEach((value2, key) => currentValue.set(key, value2));
|
|
1569
|
+
} else {
|
|
1570
|
+
set(node, value);
|
|
1541
1571
|
}
|
|
1542
1572
|
} else {
|
|
1543
1573
|
node.isAssigning = (node.isAssigning || 0) + 1;
|
|
@@ -1551,7 +1581,7 @@ function assign(node, value) {
|
|
|
1551
1581
|
return proxy2;
|
|
1552
1582
|
}
|
|
1553
1583
|
function deleteFn(node, key) {
|
|
1554
|
-
if (key === void 0 &&
|
|
1584
|
+
if (key === void 0 && isChildNode(node)) {
|
|
1555
1585
|
key = node.key;
|
|
1556
1586
|
node = node.parent;
|
|
1557
1587
|
}
|
|
@@ -1571,7 +1601,8 @@ function deleteFn(node, key) {
|
|
|
1571
1601
|
function handlerMapSet(node, p, value) {
|
|
1572
1602
|
const vProp = value == null ? void 0 : value[p];
|
|
1573
1603
|
if (p === "size") {
|
|
1574
|
-
|
|
1604
|
+
updateTracking(node, true);
|
|
1605
|
+
return value[p];
|
|
1575
1606
|
} else if (isFunction(vProp)) {
|
|
1576
1607
|
return function(a, b, c) {
|
|
1577
1608
|
const l = arguments.length;
|
|
@@ -1582,23 +1613,16 @@ function handlerMapSet(node, p, value) {
|
|
|
1582
1613
|
}
|
|
1583
1614
|
} else if (p === "set") {
|
|
1584
1615
|
if (l === 2) {
|
|
1585
|
-
|
|
1586
|
-
const ret = valueMap.set(a, b);
|
|
1587
|
-
if (prev !== b) {
|
|
1588
|
-
updateNodesAndNotify(getChildNode(node, a), b, prev);
|
|
1589
|
-
}
|
|
1590
|
-
return ret;
|
|
1616
|
+
set(getChildNode(node, a), b);
|
|
1591
1617
|
} else if (l === 1 && isMap(value)) {
|
|
1592
1618
|
set(node, a);
|
|
1593
1619
|
}
|
|
1620
|
+
return getProxy(node);
|
|
1594
1621
|
} else if (p === "delete") {
|
|
1595
1622
|
if (l > 0) {
|
|
1596
1623
|
const prev = value.get ? valueMap.get(a) : a;
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
updateNodesAndNotify(getChildNode(node, a), void 0, prev);
|
|
1600
|
-
}
|
|
1601
|
-
return ret;
|
|
1624
|
+
deleteFn(node, a);
|
|
1625
|
+
return prev !== void 0;
|
|
1602
1626
|
}
|
|
1603
1627
|
} else if (p === "clear") {
|
|
1604
1628
|
const prev = new Map(valueMap);
|
|
@@ -1614,7 +1638,7 @@ function handlerMapSet(node, p, value) {
|
|
|
1614
1638
|
if (!value.has(p)) {
|
|
1615
1639
|
notify(node, ret, prev, 0);
|
|
1616
1640
|
}
|
|
1617
|
-
return
|
|
1641
|
+
return getProxy(node);
|
|
1618
1642
|
}
|
|
1619
1643
|
const fn = observableFns.get(p);
|
|
1620
1644
|
if (fn) {
|
|
@@ -1634,20 +1658,20 @@ function handlerMapSet(node, p, value) {
|
|
|
1634
1658
|
};
|
|
1635
1659
|
}
|
|
1636
1660
|
}
|
|
1637
|
-
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level) {
|
|
1661
|
+
function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRoot, level, forceNotify) {
|
|
1638
1662
|
if (!childNode)
|
|
1639
1663
|
childNode = node;
|
|
1640
1664
|
beginBatch();
|
|
1641
1665
|
if (isPrim === void 0) {
|
|
1642
1666
|
isPrim = isPrimitive(newValue);
|
|
1643
1667
|
}
|
|
1644
|
-
let hasADiff = isPrim;
|
|
1668
|
+
let hasADiff = forceNotify || isPrim;
|
|
1645
1669
|
let whenOptimizedOnlyIf = false;
|
|
1646
1670
|
if (!isPrim || prevValue && !isPrimitive(prevValue)) {
|
|
1647
1671
|
if ((process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test") && typeof __devUpdateNodes !== "undefined") {
|
|
1648
1672
|
__devUpdateNodes.clear();
|
|
1649
1673
|
}
|
|
1650
|
-
hasADiff = updateNodes(childNode, newValue, prevValue);
|
|
1674
|
+
hasADiff = hasADiff || updateNodes(childNode, newValue, prevValue);
|
|
1651
1675
|
if (isArray(newValue)) {
|
|
1652
1676
|
whenOptimizedOnlyIf = (newValue == null ? void 0 : newValue.length) !== (prevValue == null ? void 0 : prevValue.length);
|
|
1653
1677
|
}
|
|
@@ -1664,6 +1688,7 @@ function updateNodesAndNotify(node, newValue, prevValue, childNode, isPrim, isRo
|
|
|
1664
1688
|
endBatch();
|
|
1665
1689
|
}
|
|
1666
1690
|
function extractPromise(node, value, setter) {
|
|
1691
|
+
const numGets = node.numGets = (node.numGets || 0) + 1;
|
|
1667
1692
|
if (!node.state) {
|
|
1668
1693
|
node.state = createObservable(
|
|
1669
1694
|
{
|
|
@@ -1675,11 +1700,14 @@ function extractPromise(node, value, setter) {
|
|
|
1675
1700
|
);
|
|
1676
1701
|
}
|
|
1677
1702
|
value.then((value2) => {
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1703
|
+
if (numGets >= (node.getNumResolved || 0)) {
|
|
1704
|
+
node.getNumResolved = node.numGets;
|
|
1705
|
+
setter ? setter({ value: value2 }) : set(node, value2);
|
|
1706
|
+
node.state.assign({
|
|
1707
|
+
isLoaded: true,
|
|
1708
|
+
error: void 0
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1683
1711
|
}).catch((error) => {
|
|
1684
1712
|
node.state.error.set(error);
|
|
1685
1713
|
});
|
|
@@ -1696,6 +1724,7 @@ function extractFunctionOrComputed(node, k, v) {
|
|
|
1696
1724
|
const childNode = getChildNode(node, k, fn);
|
|
1697
1725
|
const targetNode = getNode(v);
|
|
1698
1726
|
const initialValue = peek(targetNode);
|
|
1727
|
+
setToObservable(childNode, v);
|
|
1699
1728
|
setNodeValue(childNode, initialValue);
|
|
1700
1729
|
return getNodeValue(childNode);
|
|
1701
1730
|
} else if (typeof v === "function") {
|
|
@@ -1728,7 +1757,9 @@ function peekInternal(node, activateRecursive) {
|
|
|
1728
1757
|
}
|
|
1729
1758
|
isFlushing = false;
|
|
1730
1759
|
let value = getNodeValue(node);
|
|
1731
|
-
|
|
1760
|
+
if (!globalState.isLoadingLocal) {
|
|
1761
|
+
value = checkLazy(node, value, !!activateRecursive);
|
|
1762
|
+
}
|
|
1732
1763
|
return value;
|
|
1733
1764
|
}
|
|
1734
1765
|
function checkLazy(node, value, activateRecursive) {
|
|
@@ -1743,10 +1774,12 @@ function checkLazy(node, value, activateRecursive) {
|
|
|
1743
1774
|
} else {
|
|
1744
1775
|
if (node.parent) {
|
|
1745
1776
|
const parentValue = getNodeValue(node.parent);
|
|
1746
|
-
if (
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1777
|
+
if (isFunction(value)) {
|
|
1778
|
+
if (parentValue) {
|
|
1779
|
+
delete parentValue[node.key];
|
|
1780
|
+
} else {
|
|
1781
|
+
node.root._ = void 0;
|
|
1782
|
+
}
|
|
1750
1783
|
}
|
|
1751
1784
|
}
|
|
1752
1785
|
value = activateNodeFunction(node, lazyFn);
|
|
@@ -1835,7 +1868,9 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1835
1868
|
var _a, _b, _c, _d;
|
|
1836
1869
|
if (isFirst) {
|
|
1837
1870
|
isFirst = false;
|
|
1838
|
-
|
|
1871
|
+
if (isFunction(getNodeValue(node))) {
|
|
1872
|
+
setNodeValue(node, void 0);
|
|
1873
|
+
}
|
|
1839
1874
|
} else if (!isFlushing && refreshFn) {
|
|
1840
1875
|
if (shouldIgnoreUnobserved(node, refreshFn)) {
|
|
1841
1876
|
ignoreThisUpdate = true;
|
|
@@ -1844,14 +1879,15 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1844
1879
|
}
|
|
1845
1880
|
let value = activateFn();
|
|
1846
1881
|
let didSetToObs = false;
|
|
1847
|
-
|
|
1848
|
-
|
|
1882
|
+
const isObs = isObservable(value);
|
|
1883
|
+
if (isObs || node.linkedToNode) {
|
|
1884
|
+
didSetToObs = isObs;
|
|
1849
1885
|
value = setToObservable(node, value);
|
|
1850
1886
|
}
|
|
1851
|
-
if (isFunction(value)) {
|
|
1887
|
+
if (isFunction(value) && value.length === 0) {
|
|
1852
1888
|
value = value();
|
|
1853
1889
|
}
|
|
1854
|
-
const activated = !
|
|
1890
|
+
const activated = !isObs ? value == null ? void 0 : value[symbolLinked] : void 0;
|
|
1855
1891
|
if (activated) {
|
|
1856
1892
|
node.activationState = activated;
|
|
1857
1893
|
value = void 0;
|
|
@@ -1906,16 +1942,14 @@ function activateNodeFunction(node, lazyFn) {
|
|
|
1906
1942
|
}
|
|
1907
1943
|
} else {
|
|
1908
1944
|
activatedValue = value;
|
|
1909
|
-
|
|
1945
|
+
const isLoaded = node.state.isLoaded.peek();
|
|
1946
|
+
if (isLoaded || !isFunction(value)) {
|
|
1910
1947
|
node.isComputing = true;
|
|
1911
1948
|
set(node, value);
|
|
1912
1949
|
node.isComputing = false;
|
|
1913
|
-
}
|
|
1914
|
-
|
|
1915
|
-
node.state.assign({
|
|
1916
|
-
isLoaded: true,
|
|
1917
|
-
error: void 0
|
|
1918
|
-
});
|
|
1950
|
+
}
|
|
1951
|
+
if (!isLoaded) {
|
|
1952
|
+
node.state.assign({ isLoaded: true, error: void 0 });
|
|
1919
1953
|
}
|
|
1920
1954
|
}
|
|
1921
1955
|
}
|
|
@@ -1956,14 +1990,14 @@ function activateNodeBase(node, value) {
|
|
|
1956
1990
|
if (allChanges.length > 0) {
|
|
1957
1991
|
let changes;
|
|
1958
1992
|
let value2;
|
|
1959
|
-
let
|
|
1960
|
-
let
|
|
1993
|
+
let isFromPersist = false;
|
|
1994
|
+
let isFromSync = false;
|
|
1961
1995
|
let getPrevious;
|
|
1962
1996
|
if (listenerParams) {
|
|
1963
1997
|
changes = listenerParams.changes;
|
|
1964
1998
|
value2 = listenerParams.value;
|
|
1965
|
-
|
|
1966
|
-
|
|
1999
|
+
isFromPersist = listenerParams.isFromPersist;
|
|
2000
|
+
isFromSync = listenerParams.isFromSync;
|
|
1967
2001
|
getPrevious = listenerParams.getPrevious;
|
|
1968
2002
|
} else {
|
|
1969
2003
|
changes = allChanges;
|
|
@@ -1983,8 +2017,8 @@ function activateNodeBase(node, value) {
|
|
|
1983
2017
|
setFn({
|
|
1984
2018
|
value: value2,
|
|
1985
2019
|
changes,
|
|
1986
|
-
|
|
1987
|
-
|
|
2020
|
+
isFromPersist,
|
|
2021
|
+
isFromSync,
|
|
1988
2022
|
getPrevious
|
|
1989
2023
|
});
|
|
1990
2024
|
node.isComputing = false;
|
|
@@ -2019,26 +2053,31 @@ function activateNodeBase(node, value) {
|
|
|
2019
2053
|
}
|
|
2020
2054
|
function setToObservable(node, value) {
|
|
2021
2055
|
var _a;
|
|
2022
|
-
const linkedNode = getNode(value);
|
|
2056
|
+
const linkedNode = value ? getNode(value) : void 0;
|
|
2023
2057
|
if (linkedNode !== node && (linkedNode == null ? void 0 : linkedNode.linkedToNode) !== node) {
|
|
2024
2058
|
node.linkedToNode = linkedNode;
|
|
2025
|
-
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
2026
|
-
linkedNode.linkedFromNodes.add(node);
|
|
2027
2059
|
(_a = node.linkedToNodeDispose) == null ? void 0 : _a.call(node);
|
|
2028
|
-
|
|
2029
|
-
linkedNode
|
|
2030
|
-
()
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2060
|
+
if (linkedNode) {
|
|
2061
|
+
linkedNode.linkedFromNodes || (linkedNode.linkedFromNodes = /* @__PURE__ */ new Set());
|
|
2062
|
+
linkedNode.linkedFromNodes.add(node);
|
|
2063
|
+
node.linkedToNodeDispose = onChange(
|
|
2064
|
+
linkedNode,
|
|
2065
|
+
() => {
|
|
2066
|
+
value = peekInternal(linkedNode);
|
|
2067
|
+
if (!isFunction(value)) {
|
|
2068
|
+
set(node, value);
|
|
2069
|
+
}
|
|
2070
|
+
},
|
|
2071
|
+
{ initial: true },
|
|
2072
|
+
/* @__PURE__ */ new Set([node])
|
|
2073
|
+
);
|
|
2074
|
+
}
|
|
2037
2075
|
}
|
|
2038
2076
|
return value;
|
|
2039
2077
|
}
|
|
2040
2078
|
function recursivelyAutoActivate(obj, node) {
|
|
2041
|
-
if (isObject(obj) || isArray(obj)) {
|
|
2079
|
+
if (!node.recursivelyAutoActivated && (isObject(obj) || isArray(obj)) && !isOpaqueObject(obj)) {
|
|
2080
|
+
node.recursivelyAutoActivated = true;
|
|
2042
2081
|
const pathStack = [];
|
|
2043
2082
|
const getNodeAtPath2 = () => {
|
|
2044
2083
|
var _a;
|
|
@@ -2056,27 +2095,29 @@ function recursivelyAutoActivate(obj, node) {
|
|
|
2056
2095
|
}
|
|
2057
2096
|
function recursivelyAutoActivateInner(obj, pathStack, getNodeAtPath2) {
|
|
2058
2097
|
var _a;
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2098
|
+
if ((isObject(obj) || isArray(obj)) && !isOpaqueObject(obj)) {
|
|
2099
|
+
for (const key in obj) {
|
|
2100
|
+
if (hasOwnProperty.call(obj, key)) {
|
|
2101
|
+
const value = obj[key];
|
|
2102
|
+
if (isObservable(value)) {
|
|
2103
|
+
const childNode = getNodeAtPath2();
|
|
2104
|
+
extractFunctionOrComputed(childNode, key, value);
|
|
2105
|
+
delete childNode.lazy;
|
|
2106
|
+
} else {
|
|
2107
|
+
const linkedOptions = isFunction(value) && ((_a = value.prototype) == null ? void 0 : _a[symbolLinked]);
|
|
2108
|
+
if (linkedOptions) {
|
|
2109
|
+
const activate = linkedOptions.activate;
|
|
2110
|
+
if (!activate || activate === "auto") {
|
|
2111
|
+
const childNode = getNodeAtPath2();
|
|
2112
|
+
peek(getChildNode(childNode, key, value));
|
|
2113
|
+
}
|
|
2073
2114
|
}
|
|
2074
2115
|
}
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2116
|
+
if (typeof value === "object") {
|
|
2117
|
+
pathStack.push({ key, value });
|
|
2118
|
+
recursivelyAutoActivateInner(value, pathStack, getNodeAtPath2);
|
|
2119
|
+
pathStack.pop();
|
|
2120
|
+
}
|
|
2080
2121
|
}
|
|
2081
2122
|
}
|
|
2082
2123
|
}
|
|
@@ -2132,16 +2173,6 @@ function observable(value) {
|
|
|
2132
2173
|
function observablePrimitive(value) {
|
|
2133
2174
|
return createObservable(value, true, extractPromise, getProxy, ObservablePrimitiveClass);
|
|
2134
2175
|
}
|
|
2135
|
-
function syncState(obs) {
|
|
2136
|
-
const node = getNode(obs);
|
|
2137
|
-
if (!node.state) {
|
|
2138
|
-
peekInternal(node);
|
|
2139
|
-
}
|
|
2140
|
-
if (!node.state) {
|
|
2141
|
-
node.state = observable({});
|
|
2142
|
-
}
|
|
2143
|
-
return node.state;
|
|
2144
|
-
}
|
|
2145
2176
|
|
|
2146
2177
|
// src/computed.ts
|
|
2147
2178
|
function computed(get2, set2) {
|
|
@@ -2150,45 +2181,6 @@ function computed(get2, set2) {
|
|
|
2150
2181
|
);
|
|
2151
2182
|
}
|
|
2152
2183
|
|
|
2153
|
-
// src/config.ts
|
|
2154
|
-
function configureLegendState({
|
|
2155
|
-
observableFunctions,
|
|
2156
|
-
observableProperties: observableProperties2,
|
|
2157
|
-
jsonReplacer,
|
|
2158
|
-
jsonReviver
|
|
2159
|
-
}) {
|
|
2160
|
-
if (observableFunctions) {
|
|
2161
|
-
for (const key in observableFunctions) {
|
|
2162
|
-
const fn = observableFunctions[key];
|
|
2163
|
-
observableFns.set(key, fn);
|
|
2164
|
-
ObservablePrimitiveClass.prototype[key] = function(...args) {
|
|
2165
|
-
return fn.call(this, this._node, ...args);
|
|
2166
|
-
};
|
|
2167
|
-
}
|
|
2168
|
-
}
|
|
2169
|
-
if (observableProperties2) {
|
|
2170
|
-
for (const key in observableProperties2) {
|
|
2171
|
-
const fns2 = observableProperties2[key];
|
|
2172
|
-
observableProperties.set(key, fns2);
|
|
2173
|
-
Object.defineProperty(ObservablePrimitiveClass.prototype, key, {
|
|
2174
|
-
configurable: true,
|
|
2175
|
-
get() {
|
|
2176
|
-
return fns2.get.call(this, this._node);
|
|
2177
|
-
},
|
|
2178
|
-
set(value) {
|
|
2179
|
-
return fns2.set.call(this, this._node, value);
|
|
2180
|
-
}
|
|
2181
|
-
});
|
|
2182
|
-
}
|
|
2183
|
-
}
|
|
2184
|
-
if (jsonReplacer) {
|
|
2185
|
-
globalState.replacer = jsonReplacer;
|
|
2186
|
-
}
|
|
2187
|
-
if (jsonReviver) {
|
|
2188
|
-
globalState.reviver = jsonReviver;
|
|
2189
|
-
}
|
|
2190
|
-
}
|
|
2191
|
-
|
|
2192
2184
|
// src/event.ts
|
|
2193
2185
|
function event() {
|
|
2194
2186
|
const obs = observable(0);
|
|
@@ -2219,66 +2211,33 @@ function proxy(get2, set2) {
|
|
|
2219
2211
|
);
|
|
2220
2212
|
}
|
|
2221
2213
|
|
|
2222
|
-
// src/
|
|
2223
|
-
function
|
|
2224
|
-
const
|
|
2225
|
-
if (
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
const { retry } = state;
|
|
2240
|
-
const e = { cancel: false };
|
|
2241
|
-
let value = void 0;
|
|
2242
|
-
if (waitFor) {
|
|
2243
|
-
value = whenReady(waitFor, () => {
|
|
2244
|
-
node.activationState.waitFor = void 0;
|
|
2245
|
-
return fn(e);
|
|
2246
|
-
});
|
|
2247
|
-
} else {
|
|
2248
|
-
value = fn(e);
|
|
2249
|
-
}
|
|
2250
|
-
if (isPromise(value) && retry) {
|
|
2251
|
-
let timeoutRetry;
|
|
2252
|
-
return new Promise((resolve) => {
|
|
2253
|
-
const run = () => {
|
|
2254
|
-
value.then((val) => {
|
|
2255
|
-
node.activationState.persistedRetry = false;
|
|
2256
|
-
resolve(val);
|
|
2257
|
-
}).catch(() => {
|
|
2258
|
-
state.attemptNum++;
|
|
2259
|
-
if (timeoutRetry) {
|
|
2260
|
-
clearTimeout(timeoutRetry);
|
|
2261
|
-
}
|
|
2262
|
-
if (!e.cancel) {
|
|
2263
|
-
timeoutRetry = createRetryTimeout(retry, state.attemptNum, () => {
|
|
2264
|
-
value = fn(e);
|
|
2265
|
-
run();
|
|
2266
|
-
});
|
|
2267
|
-
}
|
|
2268
|
-
}).finally(() => {
|
|
2269
|
-
node.activationState.persistedRetry = false;
|
|
2270
|
-
});
|
|
2271
|
-
};
|
|
2272
|
-
run();
|
|
2214
|
+
// src/syncState.ts
|
|
2215
|
+
function syncState(obs) {
|
|
2216
|
+
const node = getNode(obs);
|
|
2217
|
+
if (!node.state) {
|
|
2218
|
+
node.state = observable({
|
|
2219
|
+
isPersistLoaded: false,
|
|
2220
|
+
isLoaded: false,
|
|
2221
|
+
isPersistEnabled: true,
|
|
2222
|
+
isSyncEnabled: true,
|
|
2223
|
+
isGetting: false,
|
|
2224
|
+
isSetting: false,
|
|
2225
|
+
numPendingSets: 0,
|
|
2226
|
+
syncCount: 0,
|
|
2227
|
+
clearPersist: void 0,
|
|
2228
|
+
reset: () => Promise.resolve(),
|
|
2229
|
+
sync: () => Promise.resolve(),
|
|
2230
|
+
getPendingChanges: () => ({})
|
|
2273
2231
|
});
|
|
2274
2232
|
}
|
|
2275
|
-
return
|
|
2233
|
+
return node.state;
|
|
2276
2234
|
}
|
|
2277
2235
|
|
|
2278
2236
|
// index.ts
|
|
2279
2237
|
var internal = {
|
|
2280
2238
|
createPreviousHandler,
|
|
2281
2239
|
clone,
|
|
2240
|
+
deepMerge,
|
|
2282
2241
|
ensureNodeValue,
|
|
2283
2242
|
findIDKey,
|
|
2284
2243
|
get,
|
|
@@ -2292,7 +2251,6 @@ var internal = {
|
|
|
2292
2251
|
observableFns,
|
|
2293
2252
|
optimized,
|
|
2294
2253
|
peek,
|
|
2295
|
-
runWithRetry,
|
|
2296
2254
|
safeParse,
|
|
2297
2255
|
safeStringify,
|
|
2298
2256
|
set,
|
|
@@ -2311,7 +2269,6 @@ exports.beginBatch = beginBatch;
|
|
|
2311
2269
|
exports.beginTracking = beginTracking;
|
|
2312
2270
|
exports.computeSelector = computeSelector;
|
|
2313
2271
|
exports.computed = computed;
|
|
2314
|
-
exports.configureLegendState = configureLegendState;
|
|
2315
2272
|
exports.constructObjectWithPath = constructObjectWithPath;
|
|
2316
2273
|
exports.deconstructObjectWithPath = deconstructObjectWithPath;
|
|
2317
2274
|
exports.endBatch = endBatch;
|
|
@@ -2348,7 +2305,6 @@ exports.opaqueObject = opaqueObject;
|
|
|
2348
2305
|
exports.optimized = optimized;
|
|
2349
2306
|
exports.proxy = proxy;
|
|
2350
2307
|
exports.setAtPath = setAtPath;
|
|
2351
|
-
exports.setInObservableAtPath = setInObservableAtPath;
|
|
2352
2308
|
exports.setSilently = setSilently;
|
|
2353
2309
|
exports.setupTracking = setupTracking;
|
|
2354
2310
|
exports.shouldIgnoreUnobserved = shouldIgnoreUnobserved;
|