@yiin/reactive-proxy-state 1.0.43 → 2.0.0
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/README.md +41 -0
- package/dist/index.cjs +3306 -1091
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3299 -1077
- package/dist/location.d.ts +288 -0
- package/dist/reactive.d.ts +5 -1
- package/dist/utils.d.ts +150 -9
- package/dist/wrap-array.d.ts +2 -2
- package/dist/wrap-map.d.ts +2 -2
- package/dist/wrap-set.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4,60 +4,39 @@ var __defProp = Object.defineProperty;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
function __accessProp(key) {
|
|
8
|
-
return this[key];
|
|
9
|
-
}
|
|
10
|
-
var __toESMCache_node;
|
|
11
|
-
var __toESMCache_esm;
|
|
12
7
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
8
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
9
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
10
|
for (let key of __getOwnPropNames(mod))
|
|
23
11
|
if (!__hasOwnProp.call(to, key))
|
|
24
12
|
__defProp(to, key, {
|
|
25
|
-
get:
|
|
13
|
+
get: () => mod[key],
|
|
26
14
|
enumerable: true
|
|
27
15
|
});
|
|
28
|
-
if (canCache)
|
|
29
|
-
cache.set(mod, to);
|
|
30
16
|
return to;
|
|
31
17
|
};
|
|
18
|
+
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
32
19
|
var __toCommonJS = (from) => {
|
|
33
|
-
var entry =
|
|
20
|
+
var entry = __moduleCache.get(from), desc;
|
|
34
21
|
if (entry)
|
|
35
22
|
return entry;
|
|
36
23
|
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
-
});
|
|
44
|
-
}
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function")
|
|
25
|
+
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
26
|
+
get: () => from[key],
|
|
27
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
28
|
+
}));
|
|
45
29
|
__moduleCache.set(from, entry);
|
|
46
30
|
return entry;
|
|
47
31
|
};
|
|
48
|
-
var __moduleCache;
|
|
49
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
-
var __returnValue = (v) => v;
|
|
51
|
-
function __exportSetter(name, newValue) {
|
|
52
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
-
}
|
|
54
33
|
var __export = (target, all) => {
|
|
55
34
|
for (var name in all)
|
|
56
35
|
__defProp(target, name, {
|
|
57
36
|
get: all[name],
|
|
58
37
|
enumerable: true,
|
|
59
38
|
configurable: true,
|
|
60
|
-
set:
|
|
39
|
+
set: (newValue) => all[name] = () => newValue
|
|
61
40
|
});
|
|
62
41
|
};
|
|
63
42
|
|
|
@@ -85,7 +64,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
85
64
|
}
|
|
86
65
|
};
|
|
87
66
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
88
|
-
var
|
|
67
|
+
var hasOwn2 = (val, key) => hasOwnProperty.call(val, key);
|
|
89
68
|
var isArray = Array.isArray;
|
|
90
69
|
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
91
70
|
var isSet = (val) => toTypeString(val) === "[object Set]";
|
|
@@ -94,9 +73,9 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
94
73
|
var isFunction = (val) => typeof val === "function";
|
|
95
74
|
var isString = (val) => typeof val === "string";
|
|
96
75
|
var isSymbol = (val) => typeof val === "symbol";
|
|
97
|
-
var
|
|
76
|
+
var isObject7 = (val) => val !== null && typeof val === "object";
|
|
98
77
|
var isPromise = (val) => {
|
|
99
|
-
return (
|
|
78
|
+
return (isObject7(val) || isFunction(val)) && isFunction(val.then) && isFunction(val.catch);
|
|
100
79
|
};
|
|
101
80
|
var objectToString = Object.prototype.toString;
|
|
102
81
|
var toTypeString = (value) => objectToString.call(value);
|
|
@@ -298,7 +277,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
298
277
|
}
|
|
299
278
|
}
|
|
300
279
|
return res;
|
|
301
|
-
} else if (isString(value) ||
|
|
280
|
+
} else if (isString(value) || isObject7(value)) {
|
|
302
281
|
return value;
|
|
303
282
|
}
|
|
304
283
|
}
|
|
@@ -341,7 +320,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
341
320
|
res += normalized + " ";
|
|
342
321
|
}
|
|
343
322
|
}
|
|
344
|
-
} else if (
|
|
323
|
+
} else if (isObject7(value)) {
|
|
345
324
|
for (const name in value) {
|
|
346
325
|
if (value[name]) {
|
|
347
326
|
res += name + " ";
|
|
@@ -478,8 +457,8 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
478
457
|
if (aValidType || bValidType) {
|
|
479
458
|
return aValidType && bValidType ? looseCompareArrays(a, b) : false;
|
|
480
459
|
}
|
|
481
|
-
aValidType =
|
|
482
|
-
bValidType =
|
|
460
|
+
aValidType = isObject7(a);
|
|
461
|
+
bValidType = isObject7(b);
|
|
483
462
|
if (aValidType || bValidType) {
|
|
484
463
|
if (!aValidType || !bValidType) {
|
|
485
464
|
return false;
|
|
@@ -506,7 +485,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
506
485
|
return !!(val && val["__v_isRef"] === true);
|
|
507
486
|
};
|
|
508
487
|
var toDisplayString = (val) => {
|
|
509
|
-
return isString(val) ? val : val == null ? "" : isArray(val) ||
|
|
488
|
+
return isString(val) ? val : val == null ? "" : isArray(val) || isObject7(val) && (val.toString === objectToString || !isFunction(val.toString)) ? isRef3(val) ? toDisplayString(val.value) : JSON.stringify(val, replacer, 2) : String(val);
|
|
510
489
|
};
|
|
511
490
|
var replacer = (_key, val) => {
|
|
512
491
|
if (isRef3(val)) {
|
|
@@ -524,7 +503,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
524
503
|
};
|
|
525
504
|
} else if (isSymbol(val)) {
|
|
526
505
|
return stringifySymbol(val);
|
|
527
|
-
} else if (
|
|
506
|
+
} else if (isObject7(val) && !isArray(val) && !isPlainObject(val)) {
|
|
528
507
|
return String(val);
|
|
529
508
|
}
|
|
530
509
|
return val;
|
|
@@ -554,7 +533,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
554
533
|
exports2.getEscapedCssVarName = getEscapedCssVarName;
|
|
555
534
|
exports2.getGlobalThis = getGlobalThis;
|
|
556
535
|
exports2.hasChanged = hasChanged;
|
|
557
|
-
exports2.hasOwn =
|
|
536
|
+
exports2.hasOwn = hasOwn2;
|
|
558
537
|
exports2.hyphenate = hyphenate;
|
|
559
538
|
exports2.includeBooleanAttr = includeBooleanAttr;
|
|
560
539
|
exports2.invokeArrayFns = invokeArrayFns;
|
|
@@ -573,7 +552,7 @@ var require_shared_cjs = __commonJS((exports2) => {
|
|
|
573
552
|
exports2.isMap = isMap;
|
|
574
553
|
exports2.isMathMLTag = isMathMLTag;
|
|
575
554
|
exports2.isModelListener = isModelListener;
|
|
576
|
-
exports2.isObject =
|
|
555
|
+
exports2.isObject = isObject7;
|
|
577
556
|
exports2.isOn = isOn;
|
|
578
557
|
exports2.isPlainObject = isPlainObject;
|
|
579
558
|
exports2.isPromise = isPromise;
|
|
@@ -2378,7 +2357,10 @@ __export(exports_src, {
|
|
|
2378
2357
|
createBridgeEmitter: () => createBridgeEmitter,
|
|
2379
2358
|
computed: () => computed,
|
|
2380
2359
|
cleanupEffect: () => cleanupEffect,
|
|
2381
|
-
activeEffect: () => activeEffect
|
|
2360
|
+
activeEffect: () => activeEffect,
|
|
2361
|
+
UnsupportedStateError: () => UnsupportedStateError,
|
|
2362
|
+
SnapshotLimitError: () => SnapshotLimitError,
|
|
2363
|
+
SNAPSHOT_SHARED_COPY_LIMIT: () => SNAPSHOT_SHARED_COPY_LIMIT
|
|
2382
2364
|
});
|
|
2383
2365
|
module.exports = __toCommonJS(exports_src);
|
|
2384
2366
|
|
|
@@ -2396,40 +2378,50 @@ function unwrapForStore(value) {
|
|
|
2396
2378
|
if (Array.isArray(value)) {
|
|
2397
2379
|
for (let i = 0;i < value.length; i++) {
|
|
2398
2380
|
const child = value[i];
|
|
2399
|
-
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2400
|
-
value
|
|
2401
|
-
}
|
|
2381
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2382
|
+
storeRawChild(value, i, child);
|
|
2402
2383
|
}
|
|
2403
2384
|
} else if (!(value instanceof Map) && !(value instanceof Set) && !(value instanceof Date)) {
|
|
2404
2385
|
for (const key in value) {
|
|
2405
2386
|
if (!Object.prototype.hasOwnProperty.call(value, key))
|
|
2406
2387
|
continue;
|
|
2407
2388
|
const child = value[key];
|
|
2408
|
-
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2409
|
-
value
|
|
2410
|
-
}
|
|
2389
|
+
if (child != null && typeof child === "object" && child["__v_isReactive" /* IS_REACTIVE */])
|
|
2390
|
+
storeRawChild(value, key, child);
|
|
2411
2391
|
}
|
|
2412
2392
|
}
|
|
2413
2393
|
return value;
|
|
2414
2394
|
}
|
|
2415
|
-
var
|
|
2395
|
+
var lookupSetter = Object.prototype.__lookupSetter__;
|
|
2396
|
+
function storeRawChild(value, key, child) {
|
|
2397
|
+
if (lookupSetter === undefined) {
|
|
2398
|
+
if (Reflect.getOwnPropertyDescriptor(value, key)?.value === child)
|
|
2399
|
+
Reflect.set(value, key, toRaw(child));
|
|
2400
|
+
return;
|
|
2401
|
+
}
|
|
2402
|
+
if (lookupSetter.call(value, key) !== undefined)
|
|
2403
|
+
return;
|
|
2404
|
+
try {
|
|
2405
|
+
value[key] = toRaw(child);
|
|
2406
|
+
} catch {}
|
|
2407
|
+
}
|
|
2416
2408
|
var MAX_CACHE_SIZE = 1000;
|
|
2417
2409
|
var pathCache = new WeakMap;
|
|
2418
2410
|
var pathCacheSize = new WeakMap;
|
|
2419
|
-
var pathConcatCache = new Map;
|
|
2420
|
-
var MAX_PATH_CACHE_SIZE = 1000;
|
|
2421
2411
|
var globalSeen = new WeakMap;
|
|
2422
2412
|
var wrapperCache = new WeakMap;
|
|
2413
|
+
var locationNodes = new WeakMap;
|
|
2423
2414
|
var proxyStats = {
|
|
2424
2415
|
created: 0,
|
|
2425
2416
|
arrays: 0,
|
|
2426
2417
|
maps: 0,
|
|
2427
2418
|
sets: 0,
|
|
2428
2419
|
objects: 0,
|
|
2429
|
-
staleEvicted: 0
|
|
2420
|
+
staleEvicted: 0,
|
|
2421
|
+
detachedWrites: 0
|
|
2430
2422
|
};
|
|
2431
2423
|
function getProxyStats() {
|
|
2432
|
-
return { ...proxyStats, pathConcatCacheSize:
|
|
2424
|
+
return { ...proxyStats, pathConcatCacheSize: 0 };
|
|
2433
2425
|
}
|
|
2434
2426
|
function resetProxyStats() {
|
|
2435
2427
|
proxyStats.created = 0;
|
|
@@ -2438,41 +2430,7 @@ function resetProxyStats() {
|
|
|
2438
2430
|
proxyStats.sets = 0;
|
|
2439
2431
|
proxyStats.objects = 0;
|
|
2440
2432
|
proxyStats.staleEvicted = 0;
|
|
2441
|
-
|
|
2442
|
-
function evictDeep(value) {
|
|
2443
|
-
if (value == null || typeof value !== "object")
|
|
2444
|
-
return;
|
|
2445
|
-
value = toRaw(value);
|
|
2446
|
-
if (!globalSeen.has(value))
|
|
2447
|
-
return;
|
|
2448
|
-
globalSeen.delete(value);
|
|
2449
|
-
wrapperCache.delete(value);
|
|
2450
|
-
proxyStats.staleEvicted++;
|
|
2451
|
-
if (Array.isArray(value)) {
|
|
2452
|
-
for (let i = 0;i < value.length; i++) {
|
|
2453
|
-
if (value[i] != null && typeof value[i] === "object") {
|
|
2454
|
-
evictDeep(value[i]);
|
|
2455
|
-
}
|
|
2456
|
-
}
|
|
2457
|
-
} else if (value instanceof Map) {
|
|
2458
|
-
for (const v of value.values()) {
|
|
2459
|
-
if (v != null && typeof v === "object")
|
|
2460
|
-
evictDeep(v);
|
|
2461
|
-
}
|
|
2462
|
-
} else if (value instanceof Set) {
|
|
2463
|
-
for (const v of value) {
|
|
2464
|
-
if (v != null && typeof v === "object")
|
|
2465
|
-
evictDeep(v);
|
|
2466
|
-
}
|
|
2467
|
-
} else {
|
|
2468
|
-
const keys = Object.keys(value);
|
|
2469
|
-
for (let i = 0;i < keys.length; i++) {
|
|
2470
|
-
const child = value[keys[i]];
|
|
2471
|
-
if (child != null && typeof child === "object") {
|
|
2472
|
-
evictDeep(child);
|
|
2473
|
-
}
|
|
2474
|
-
}
|
|
2475
|
-
}
|
|
2433
|
+
proxyStats.detachedWrites = 0;
|
|
2476
2434
|
}
|
|
2477
2435
|
function cleanupPathCache(root) {
|
|
2478
2436
|
const cache = pathCache.get(root);
|
|
@@ -2488,23 +2446,11 @@ function cleanupPathCache(root) {
|
|
|
2488
2446
|
pathCacheSize.set(root, MAX_CACHE_SIZE - entriesToRemove);
|
|
2489
2447
|
}
|
|
2490
2448
|
}
|
|
2491
|
-
function
|
|
2492
|
-
if (pathConcatCache.size > MAX_PATH_CACHE_SIZE) {
|
|
2493
|
-
const entriesToRemove = Math.floor(MAX_PATH_CACHE_SIZE * 0.2);
|
|
2494
|
-
let count = 0;
|
|
2495
|
-
for (const key of pathConcatCache.keys()) {
|
|
2496
|
-
if (count >= entriesToRemove)
|
|
2497
|
-
break;
|
|
2498
|
-
pathConcatCache.delete(key);
|
|
2499
|
-
count++;
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
}
|
|
2503
|
-
function deepEqual(a, b, seen = globalSeen) {
|
|
2449
|
+
function deepEqual(a, b, seen) {
|
|
2504
2450
|
if (a === b)
|
|
2505
2451
|
return true;
|
|
2506
2452
|
if (a == null || b == null)
|
|
2507
|
-
return
|
|
2453
|
+
return false;
|
|
2508
2454
|
if (typeof a !== typeof b)
|
|
2509
2455
|
return false;
|
|
2510
2456
|
if (a instanceof Date && b instanceof Date)
|
|
@@ -2513,45 +2459,75 @@ function deepEqual(a, b, seen = globalSeen) {
|
|
|
2513
2459
|
return false;
|
|
2514
2460
|
if (Array.isArray(a) !== Array.isArray(b))
|
|
2515
2461
|
return false;
|
|
2516
|
-
if (seen
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
return deepEqualCache.get(a).get(b);
|
|
2521
|
-
}
|
|
2522
|
-
if (!deepEqualCache.has(a)) {
|
|
2523
|
-
deepEqualCache.set(a, new WeakMap);
|
|
2462
|
+
if (seen !== undefined) {
|
|
2463
|
+
if (seen.has(a))
|
|
2464
|
+
return seen.get(a) === b;
|
|
2465
|
+
seen.set(a, b);
|
|
2524
2466
|
}
|
|
2525
|
-
let result;
|
|
2526
2467
|
if (Array.isArray(a)) {
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2468
|
+
if (a.length !== b.length)
|
|
2469
|
+
return false;
|
|
2470
|
+
for (let i = 0;i < a.length; i++) {
|
|
2471
|
+
const left = a[i];
|
|
2472
|
+
if (left === undefined && !(i in a))
|
|
2473
|
+
continue;
|
|
2474
|
+
const right = b[i];
|
|
2475
|
+
if (left === right)
|
|
2476
|
+
continue;
|
|
2477
|
+
if (isObject(left) && isObject(right))
|
|
2478
|
+
seen ??= startSeen(a, b);
|
|
2479
|
+
if (!deepEqual(left, right, seen))
|
|
2480
|
+
return false;
|
|
2537
2481
|
}
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2482
|
+
return true;
|
|
2483
|
+
}
|
|
2484
|
+
if (a instanceof Map && b instanceof Map) {
|
|
2485
|
+
if (a.size !== b.size)
|
|
2486
|
+
return false;
|
|
2487
|
+
for (const [key, left] of a) {
|
|
2488
|
+
if (!b.has(key))
|
|
2489
|
+
return false;
|
|
2490
|
+
const right = b.get(key);
|
|
2491
|
+
if (left === right)
|
|
2492
|
+
continue;
|
|
2493
|
+
if (isObject(left) && isObject(right))
|
|
2494
|
+
seen ??= startSeen(a, b);
|
|
2495
|
+
if (!deepEqual(left, right, seen))
|
|
2496
|
+
return false;
|
|
2547
2497
|
}
|
|
2548
|
-
|
|
2549
|
-
const keysA = Object.keys(a);
|
|
2550
|
-
const keysB = Object.keys(b);
|
|
2551
|
-
result = keysA.length === keysB.length && keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(a[key], b[key], seen));
|
|
2498
|
+
return true;
|
|
2552
2499
|
}
|
|
2553
|
-
|
|
2554
|
-
|
|
2500
|
+
if (a instanceof Set && b instanceof Set) {
|
|
2501
|
+
if (a.size !== b.size)
|
|
2502
|
+
return false;
|
|
2503
|
+
for (const value of a) {
|
|
2504
|
+
if (!b.has(value))
|
|
2505
|
+
return false;
|
|
2506
|
+
}
|
|
2507
|
+
return true;
|
|
2508
|
+
}
|
|
2509
|
+
const keysA = Object.keys(a);
|
|
2510
|
+
if (keysA.length !== Object.keys(b).length)
|
|
2511
|
+
return false;
|
|
2512
|
+
for (let i = 0;i < keysA.length; i++) {
|
|
2513
|
+
const key = keysA[i];
|
|
2514
|
+
if (!hasOwn.call(b, key))
|
|
2515
|
+
return false;
|
|
2516
|
+
const left = a[key];
|
|
2517
|
+
const right = b[key];
|
|
2518
|
+
if (left === right)
|
|
2519
|
+
continue;
|
|
2520
|
+
if (isObject(left) && isObject(right))
|
|
2521
|
+
seen ??= startSeen(a, b);
|
|
2522
|
+
if (!deepEqual(left, right, seen))
|
|
2523
|
+
return false;
|
|
2524
|
+
}
|
|
2525
|
+
return true;
|
|
2526
|
+
}
|
|
2527
|
+
function startSeen(a, b) {
|
|
2528
|
+
const seen = new WeakMap;
|
|
2529
|
+
seen.set(a, b);
|
|
2530
|
+
return seen;
|
|
2555
2531
|
}
|
|
2556
2532
|
function setInPathCache(root, pathKey, value) {
|
|
2557
2533
|
if (!pathCache.has(root)) {
|
|
@@ -2587,21 +2563,6 @@ function evictDescendantsFromPathCache(root, pathKey) {
|
|
|
2587
2563
|
pathCacheSize.set(root, (pathCacheSize.get(root) ?? cache.size) - evicted);
|
|
2588
2564
|
}
|
|
2589
2565
|
}
|
|
2590
|
-
function getPathConcat(path) {
|
|
2591
|
-
const result = pathConcatCache.get(path);
|
|
2592
|
-
if (result !== undefined) {
|
|
2593
|
-
pathConcatCache.delete(path);
|
|
2594
|
-
pathConcatCache.set(path, result);
|
|
2595
|
-
}
|
|
2596
|
-
return result;
|
|
2597
|
-
}
|
|
2598
|
-
function setPathConcat(path, value) {
|
|
2599
|
-
if (pathConcatCache.has(path)) {
|
|
2600
|
-
pathConcatCache.delete(path);
|
|
2601
|
-
}
|
|
2602
|
-
pathConcatCache.set(path, value);
|
|
2603
|
-
cleanupPathConcatCache();
|
|
2604
|
-
}
|
|
2605
2566
|
function isObject(val) {
|
|
2606
2567
|
return val !== null && typeof val === "object";
|
|
2607
2568
|
}
|
|
@@ -2635,298 +2596,2095 @@ function traverse(value, seen = new Set) {
|
|
|
2635
2596
|
}
|
|
2636
2597
|
return value;
|
|
2637
2598
|
}
|
|
2638
|
-
|
|
2599
|
+
var SNAPSHOT_SHARED_COPY_LIMIT = 1e5;
|
|
2600
|
+
|
|
2601
|
+
class SnapshotLimitError extends RangeError {
|
|
2602
|
+
constructor(extraCopies) {
|
|
2603
|
+
super(`reactive-proxy-state: a snapshot would copy shared objects more than ` + `${SNAPSHOT_SHARED_COPY_LIMIT} extra times (counted ${extraCopies} before stopping; ` + `an object is copied once per place it holds). Nothing was changed. To remove such a ` + `graph, see "Shared graphs have a copy limit" under "Synchronization Limits" in the README`);
|
|
2604
|
+
this.name = "SnapshotLimitError";
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
|
|
2608
|
+
class UnsupportedStateError extends TypeError {
|
|
2609
|
+
constructor(problem) {
|
|
2610
|
+
super(`reactive-proxy-state: ${problem}. Nothing was changed. See "Supported inputs" under ` + `"Synchronization Limits" in the README`);
|
|
2611
|
+
this.name = "UnsupportedStateError";
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
var SNAPSHOT_CHECK_AFTER = SNAPSHOT_SHARED_COPY_LIMIT + 1;
|
|
2615
|
+
function cloneTree(value, named) {
|
|
2616
|
+
return copyTree(value, undefined, undefined, false, named);
|
|
2617
|
+
}
|
|
2618
|
+
var REACHES = Symbol("reaches");
|
|
2619
|
+
function cloneTreeUnless(value, container, named) {
|
|
2620
|
+
return copyUnless(value, container, false, named);
|
|
2621
|
+
}
|
|
2622
|
+
function cloneStored(value, container, named) {
|
|
2623
|
+
return copyUnless(value, container, true, named);
|
|
2624
|
+
}
|
|
2625
|
+
var copiedFresh = false;
|
|
2626
|
+
function copyUnless(value, container, checkFresh, named) {
|
|
2627
|
+
try {
|
|
2628
|
+
return copyTree(value, container, undefined, checkFresh, named);
|
|
2629
|
+
} catch (error) {
|
|
2630
|
+
if (error === reachedContainer) {
|
|
2631
|
+
copiedFresh = false;
|
|
2632
|
+
return REACHES;
|
|
2633
|
+
}
|
|
2634
|
+
throw error;
|
|
2635
|
+
}
|
|
2636
|
+
}
|
|
2637
|
+
function cloneTreeAfter(value, container, contents, named) {
|
|
2638
|
+
return copyTree(value, container, contents, false, named);
|
|
2639
|
+
}
|
|
2640
|
+
var reachedContainer = new Error("reactive-proxy-state: internal, a copy reached its container");
|
|
2641
|
+
function copyTree(value, container, contents, checkFresh, named) {
|
|
2639
2642
|
if (value === null || typeof value !== "object") {
|
|
2643
|
+
if (checkFresh)
|
|
2644
|
+
copiedFresh = true;
|
|
2640
2645
|
return value;
|
|
2641
2646
|
}
|
|
2642
|
-
|
|
2643
|
-
|
|
2647
|
+
const top = toRaw(value);
|
|
2648
|
+
if (top === value && top !== container) {
|
|
2649
|
+
const small = copySmall(value, container, checkFresh, named);
|
|
2650
|
+
if (small !== undefined)
|
|
2651
|
+
return small;
|
|
2652
|
+
}
|
|
2653
|
+
const base = cloneAncestors.length;
|
|
2654
|
+
const workBase = cloneWork.length;
|
|
2655
|
+
const outerTop = cloneTop;
|
|
2656
|
+
const outerCountdown = cloneCountdown;
|
|
2657
|
+
const outerContainer = cloneContainer;
|
|
2658
|
+
const outerContents = cloneContents;
|
|
2659
|
+
const outerFresh = cloneFresh;
|
|
2660
|
+
const outerFirst = cloneFirst;
|
|
2661
|
+
const outerSeen = cloneSeen;
|
|
2662
|
+
const outerBase = cloneBase;
|
|
2663
|
+
const outerIndex = cloneIndex;
|
|
2664
|
+
const outerNamed = cloneNamed;
|
|
2665
|
+
cloneTop = top;
|
|
2666
|
+
cloneCountdown = SNAPSHOT_CHECK_AFTER;
|
|
2667
|
+
cloneContainer = container;
|
|
2668
|
+
cloneContents = contents;
|
|
2669
|
+
cloneFresh = checkFresh && locationNodes.get(top) === undefined;
|
|
2670
|
+
cloneFirst = undefined;
|
|
2671
|
+
cloneSeen = undefined;
|
|
2672
|
+
cloneBase = base;
|
|
2673
|
+
cloneIndex = undefined;
|
|
2674
|
+
cloneNamed = named;
|
|
2675
|
+
try {
|
|
2676
|
+
const copy = cloneEntry(value, 0, named);
|
|
2677
|
+
if (checkFresh)
|
|
2678
|
+
copiedFresh = cloneFresh;
|
|
2679
|
+
return copy;
|
|
2680
|
+
} finally {
|
|
2681
|
+
cloneAncestors.length = base;
|
|
2682
|
+
cloneCopies.length = base;
|
|
2683
|
+
cloneWork.length = workBase;
|
|
2684
|
+
cloneTop = outerTop;
|
|
2685
|
+
cloneCountdown = outerCountdown;
|
|
2686
|
+
cloneContainer = outerContainer;
|
|
2687
|
+
cloneContents = outerContents;
|
|
2688
|
+
cloneFresh = outerFresh;
|
|
2689
|
+
cloneFirst = outerFirst;
|
|
2690
|
+
cloneSeen = outerSeen;
|
|
2691
|
+
cloneBase = outerBase;
|
|
2692
|
+
cloneIndex = outerIndex;
|
|
2693
|
+
cloneNamed = outerNamed;
|
|
2694
|
+
}
|
|
2695
|
+
}
|
|
2696
|
+
var cloneTop;
|
|
2697
|
+
var cloneCountdown = 0;
|
|
2698
|
+
var cloneContainer;
|
|
2699
|
+
var cloneContents;
|
|
2700
|
+
var cloneFresh = false;
|
|
2701
|
+
var cloneFirst;
|
|
2702
|
+
var cloneSeen;
|
|
2703
|
+
var cloneNamed = 0 /* None */;
|
|
2704
|
+
function copySmall(value, container, checkFresh, named) {
|
|
2705
|
+
if (!Array.isArray(value)) {
|
|
2706
|
+
const copy2 = copyLeaf(value);
|
|
2707
|
+
if (copy2 !== undefined && checkFresh)
|
|
2708
|
+
copiedFresh = locationNodes.get(value) === undefined;
|
|
2709
|
+
return copy2;
|
|
2710
|
+
}
|
|
2711
|
+
const length = value.length;
|
|
2712
|
+
if (length > 8)
|
|
2713
|
+
return;
|
|
2714
|
+
if (named === 2 /* All */ && namedKeys(value) !== undefined)
|
|
2715
|
+
return;
|
|
2716
|
+
const copy = new Array(length);
|
|
2717
|
+
let fresh = checkFresh && locationNodes.get(value) === undefined;
|
|
2718
|
+
for (let i = 0;i < length; i++) {
|
|
2719
|
+
const item = value[i];
|
|
2720
|
+
if (item === null || typeof item !== "object") {
|
|
2721
|
+
if (item !== undefined || i in value)
|
|
2722
|
+
copy[i] = item;
|
|
2723
|
+
continue;
|
|
2724
|
+
}
|
|
2725
|
+
if (item === container || toRaw(item) !== item)
|
|
2726
|
+
return;
|
|
2727
|
+
const leaf = copyLeaf(item);
|
|
2728
|
+
if (leaf === undefined)
|
|
2729
|
+
return;
|
|
2730
|
+
copy[i] = leaf;
|
|
2731
|
+
if (fresh)
|
|
2732
|
+
fresh = locationNodes.get(item) === undefined && value.indexOf(item) === i;
|
|
2733
|
+
}
|
|
2734
|
+
if (checkFresh)
|
|
2735
|
+
copiedFresh = fresh;
|
|
2736
|
+
return copy;
|
|
2737
|
+
}
|
|
2738
|
+
function copyLeaf(value) {
|
|
2739
|
+
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
2740
|
+
return;
|
|
2741
|
+
const copy = {};
|
|
2742
|
+
for (const key in value) {
|
|
2743
|
+
if (!hasOwn.call(value, key))
|
|
2744
|
+
continue;
|
|
2745
|
+
const entry = value[key];
|
|
2746
|
+
if (entry !== null && typeof entry === "object")
|
|
2747
|
+
return;
|
|
2748
|
+
if (key === "__proto__")
|
|
2749
|
+
setData(copy, key, entry);
|
|
2750
|
+
else
|
|
2751
|
+
copy[key] = entry;
|
|
2644
2752
|
}
|
|
2753
|
+
if (Object.getOwnPropertySymbols(value).length !== 0)
|
|
2754
|
+
return;
|
|
2755
|
+
return copy;
|
|
2756
|
+
}
|
|
2757
|
+
function readsOf(identity) {
|
|
2758
|
+
if (identity !== cloneContainer)
|
|
2759
|
+
return identity;
|
|
2760
|
+
if (cloneContents === undefined)
|
|
2761
|
+
throw reachedContainer;
|
|
2762
|
+
return cloneContents;
|
|
2763
|
+
}
|
|
2764
|
+
function countCopy() {
|
|
2765
|
+
if (--cloneCountdown === 0) {
|
|
2766
|
+
if (cloneFresh)
|
|
2767
|
+
cloneCountdown = SNAPSHOT_CHECK_AFTER;
|
|
2768
|
+
else
|
|
2769
|
+
checkSharedCopies(cloneTop);
|
|
2770
|
+
}
|
|
2771
|
+
}
|
|
2772
|
+
function noteFresh(value) {
|
|
2645
2773
|
const identity = toRaw(value);
|
|
2646
|
-
if (
|
|
2647
|
-
|
|
2774
|
+
if (identity !== value || identity === cloneTop || locationNodes.get(identity) !== undefined) {
|
|
2775
|
+
cloneFresh = false;
|
|
2776
|
+
return;
|
|
2648
2777
|
}
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2778
|
+
const first = cloneFirst;
|
|
2779
|
+
if (first === undefined) {
|
|
2780
|
+
cloneFirst = identity;
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
if (identity === first) {
|
|
2784
|
+
cloneFresh = false;
|
|
2785
|
+
return;
|
|
2786
|
+
}
|
|
2787
|
+
let seen = cloneSeen;
|
|
2788
|
+
if (seen === undefined) {
|
|
2789
|
+
seen = cloneSeen = new Set;
|
|
2790
|
+
seen.add(first);
|
|
2791
|
+
}
|
|
2792
|
+
const size = seen.size;
|
|
2793
|
+
seen.add(identity);
|
|
2794
|
+
if (seen.size === size)
|
|
2795
|
+
cloneFresh = false;
|
|
2796
|
+
}
|
|
2797
|
+
function namedKeys(array) {
|
|
2798
|
+
const keys = Object.keys(array);
|
|
2799
|
+
let start = keys.length;
|
|
2800
|
+
while (start > 0 && !isIndexKey(keys[start - 1]))
|
|
2801
|
+
start--;
|
|
2802
|
+
const symbols = Object.getOwnPropertySymbols(array);
|
|
2803
|
+
let names = start === keys.length ? undefined : keys.slice(start);
|
|
2804
|
+
for (let i = 0;i < symbols.length; i++) {
|
|
2805
|
+
if (isEnumerable.call(array, symbols[i]))
|
|
2806
|
+
(names ??= []).push(symbols[i]);
|
|
2807
|
+
}
|
|
2808
|
+
return names;
|
|
2809
|
+
}
|
|
2810
|
+
function isIndexKey(key) {
|
|
2811
|
+
const length = key.length;
|
|
2812
|
+
if (length === 0 || length > 10)
|
|
2813
|
+
return false;
|
|
2814
|
+
const first = key.charCodeAt(0);
|
|
2815
|
+
if (first < 48 || first > 57 || first === 48 && length > 1)
|
|
2816
|
+
return false;
|
|
2817
|
+
for (let i = 1;i < length; i++) {
|
|
2818
|
+
const code = key.charCodeAt(i);
|
|
2819
|
+
if (code < 48 || code > 57)
|
|
2820
|
+
return false;
|
|
2821
|
+
}
|
|
2822
|
+
return length < 10 || Number(key) < 4294967295;
|
|
2823
|
+
}
|
|
2824
|
+
function setData(object, key, value) {
|
|
2825
|
+
Object.defineProperty(object, key, { value, writable: true, enumerable: true, configurable: true });
|
|
2826
|
+
}
|
|
2827
|
+
function checkSharedCopies(value) {
|
|
2828
|
+
const walk = { extra: 0, low: Infinity, marks: new Map };
|
|
2829
|
+
walkCopies(value, walk);
|
|
2830
|
+
if (walk.extra > SNAPSHOT_SHARED_COPY_LIMIT)
|
|
2831
|
+
throw new SnapshotLimitError(walk.extra);
|
|
2832
|
+
}
|
|
2833
|
+
function walkCopies(top, walk) {
|
|
2834
|
+
const frames = [];
|
|
2835
|
+
enterCopies(top, 0, walk, frames);
|
|
2836
|
+
while (frames.length > 0) {
|
|
2837
|
+
const frame = frames[frames.length - 1];
|
|
2838
|
+
if (frame.next < frame.entries.length && walk.extra <= SNAPSHOT_SHARED_COPY_LIMIT) {
|
|
2839
|
+
const entry = frame.entries[frame.next++];
|
|
2840
|
+
if (entry === null || typeof entry !== "object") {
|
|
2841
|
+
walk.low = Infinity;
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
const size = enterCopies(entry, frame.depth + 1, walk, frames);
|
|
2845
|
+
if (frames[frames.length - 1] !== frame)
|
|
2846
|
+
continue;
|
|
2847
|
+
frame.size += size;
|
|
2848
|
+
if (walk.low < frame.low)
|
|
2849
|
+
frame.low = walk.low;
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
frames.pop();
|
|
2853
|
+
walk.marks.set(frame.identity, frame.low > frame.depth ? frame.size : -1);
|
|
2854
|
+
walk.low = frame.low;
|
|
2855
|
+
const below = frames[frames.length - 1];
|
|
2856
|
+
if (below !== undefined) {
|
|
2857
|
+
below.size += frame.size;
|
|
2858
|
+
if (frame.low < below.low)
|
|
2859
|
+
below.low = frame.low;
|
|
2654
2860
|
}
|
|
2655
|
-
return newArray;
|
|
2656
2861
|
}
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2862
|
+
}
|
|
2863
|
+
function enterCopies(value, depth, walk, frames) {
|
|
2864
|
+
const identity = toRaw(value);
|
|
2865
|
+
const source = identity === cloneContainer ? readsOf(identity) : identity;
|
|
2866
|
+
const marks = walk.marks;
|
|
2867
|
+
const mark = marks.get(identity);
|
|
2868
|
+
if (mark !== undefined) {
|
|
2869
|
+
if (mark <= -2) {
|
|
2870
|
+
walk.low = -mark - 2;
|
|
2871
|
+
return 0;
|
|
2872
|
+
}
|
|
2873
|
+
walk.low = Infinity;
|
|
2874
|
+
if (mark > 0) {
|
|
2875
|
+
walk.extra += mark;
|
|
2876
|
+
return mark;
|
|
2877
|
+
}
|
|
2878
|
+
walk.extra++;
|
|
2879
|
+
}
|
|
2880
|
+
if (walk.extra > SNAPSHOT_SHARED_COPY_LIMIT) {
|
|
2881
|
+
if (mark === undefined)
|
|
2882
|
+
marks.set(identity, 1);
|
|
2883
|
+
walk.low = Infinity;
|
|
2884
|
+
return 1;
|
|
2885
|
+
}
|
|
2886
|
+
marks.set(identity, -(depth + 2));
|
|
2887
|
+
frames.push({ identity, depth, entries: entriesOf(source, identity), next: 0, size: 1, low: Infinity });
|
|
2888
|
+
return 0;
|
|
2889
|
+
}
|
|
2890
|
+
function entriesOf(source, identity) {
|
|
2891
|
+
if (Array.isArray(source)) {
|
|
2892
|
+
const names = keepsNamed(cloneNamed, identity === cloneTop ? 0 : 1) ? namedKeys(source) : undefined;
|
|
2893
|
+
if (names === undefined)
|
|
2894
|
+
return source;
|
|
2895
|
+
const entries2 = source.slice();
|
|
2896
|
+
for (let i = 0;i < names.length; i++)
|
|
2897
|
+
entries2.push(source[names[i]]);
|
|
2898
|
+
return entries2;
|
|
2899
|
+
}
|
|
2900
|
+
const entries = [];
|
|
2901
|
+
if (source instanceof Map) {
|
|
2902
|
+
for (const [key, entry] of Map.prototype.entries.call(source))
|
|
2903
|
+
entries.push(key, entry);
|
|
2904
|
+
} else if (source instanceof Set) {
|
|
2905
|
+
for (const entry of Set.prototype.values.call(source))
|
|
2906
|
+
entries.push(entry);
|
|
2907
|
+
}
|
|
2908
|
+
for (const key in source)
|
|
2909
|
+
if (hasOwn.call(source, key))
|
|
2910
|
+
entries.push(source[key]);
|
|
2911
|
+
const symbolKeys = Object.getOwnPropertySymbols(source);
|
|
2912
|
+
for (let i = 0;i < symbolKeys.length; i++) {
|
|
2913
|
+
if (isEnumerable.call(source, symbolKeys[i]))
|
|
2914
|
+
entries.push(source[symbolKeys[i]]);
|
|
2915
|
+
}
|
|
2916
|
+
return entries;
|
|
2917
|
+
}
|
|
2918
|
+
var cloneAncestors = [];
|
|
2919
|
+
var cloneCopies = [];
|
|
2920
|
+
var cloneBase = 0;
|
|
2921
|
+
var cloneIndex;
|
|
2922
|
+
var DEEP_PATH = 64;
|
|
2923
|
+
var cloneWork = [];
|
|
2924
|
+
var FILL_DEPTH = 256;
|
|
2925
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
2926
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
|
2927
|
+
function enterPath(identity, copy, depth) {
|
|
2928
|
+
cloneAncestors.push(identity);
|
|
2929
|
+
cloneCopies.push(copy);
|
|
2930
|
+
if (depth < DEEP_PATH)
|
|
2931
|
+
return;
|
|
2932
|
+
if (cloneIndex !== undefined) {
|
|
2933
|
+
cloneIndex.set(identity, copy);
|
|
2934
|
+
return;
|
|
2664
2935
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2936
|
+
cloneIndex = new Map;
|
|
2937
|
+
for (let i = cloneBase;i < cloneAncestors.length; i++)
|
|
2938
|
+
cloneIndex.set(cloneAncestors[i], cloneCopies[i]);
|
|
2939
|
+
}
|
|
2940
|
+
function leavePath(length) {
|
|
2941
|
+
const ancestors = cloneAncestors;
|
|
2942
|
+
const index = cloneIndex;
|
|
2943
|
+
while (ancestors.length > length) {
|
|
2944
|
+
const identity = ancestors.pop();
|
|
2945
|
+
cloneCopies.pop();
|
|
2946
|
+
if (index !== undefined)
|
|
2947
|
+
index.delete(identity);
|
|
2948
|
+
}
|
|
2949
|
+
if (index !== undefined && length - cloneBase <= DEEP_PATH)
|
|
2950
|
+
cloneIndex = undefined;
|
|
2951
|
+
}
|
|
2952
|
+
function cloneValue(value, depth, named) {
|
|
2953
|
+
if (value === null || typeof value !== "object")
|
|
2954
|
+
return value;
|
|
2955
|
+
if (cloneFresh)
|
|
2956
|
+
noteFresh(value);
|
|
2957
|
+
return cloneEntry(value, depth, named);
|
|
2958
|
+
}
|
|
2959
|
+
function keepsNamed(named, depth) {
|
|
2960
|
+
return named === 2 /* All */ || named === 1 /* Below */ && depth > 0;
|
|
2961
|
+
}
|
|
2962
|
+
function cloneEntry(value, depth, named) {
|
|
2963
|
+
const identity = toRaw(value);
|
|
2964
|
+
if (identity === cloneContainer)
|
|
2965
|
+
value = readsOf(identity);
|
|
2966
|
+
if (depth > DEEP_PATH) {
|
|
2967
|
+
const ancestor = cloneIndex.get(identity);
|
|
2968
|
+
if (ancestor !== undefined)
|
|
2969
|
+
return ancestor;
|
|
2970
|
+
} else {
|
|
2971
|
+
const ancestors = cloneAncestors;
|
|
2972
|
+
for (let i = ancestors.length - 1, stop = ancestors.length - depth;i >= stop; i--) {
|
|
2973
|
+
if (ancestors[i] === identity)
|
|
2974
|
+
return cloneCopies[i];
|
|
2975
|
+
}
|
|
2672
2976
|
}
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2977
|
+
countCopy();
|
|
2978
|
+
let copy;
|
|
2979
|
+
let kind;
|
|
2980
|
+
if (Array.isArray(value)) {
|
|
2981
|
+
copy = new Array(value.length);
|
|
2982
|
+
kind = 1 /* Array */;
|
|
2983
|
+
} else {
|
|
2984
|
+
const prototype = Object.getPrototypeOf(value);
|
|
2985
|
+
if (prototype === Object.prototype) {
|
|
2986
|
+
copy = {};
|
|
2987
|
+
kind = 0 /* Object */;
|
|
2988
|
+
} else if (value instanceof Date) {
|
|
2989
|
+
copy = new Date(value.getTime());
|
|
2990
|
+
kind = 0 /* Object */;
|
|
2991
|
+
} else if (value instanceof Map) {
|
|
2992
|
+
copy = new Map;
|
|
2993
|
+
kind = 2 /* Map */;
|
|
2994
|
+
} else if (value instanceof Set) {
|
|
2995
|
+
copy = new Set;
|
|
2996
|
+
kind = 3 /* Set */;
|
|
2997
|
+
} else {
|
|
2998
|
+
copy = Object.create(prototype);
|
|
2999
|
+
kind = 0 /* Object */;
|
|
2678
3000
|
}
|
|
2679
3001
|
}
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
3002
|
+
if (depth >= FILL_DEPTH - 1) {
|
|
3003
|
+
cloneDeep(kind, value, identity, copy, depth, named);
|
|
3004
|
+
return copy;
|
|
3005
|
+
}
|
|
3006
|
+
const below = depth + 1;
|
|
3007
|
+
let pushed = false;
|
|
3008
|
+
if (kind === 0 /* Object */) {
|
|
3009
|
+
for (const key in value) {
|
|
3010
|
+
if (!hasOwn.call(value, key))
|
|
3011
|
+
continue;
|
|
3012
|
+
let child = value[key];
|
|
3013
|
+
if (child !== null && typeof child === "object") {
|
|
3014
|
+
if (!pushed) {
|
|
3015
|
+
pushed = true;
|
|
3016
|
+
enterPath(identity, copy, depth);
|
|
3017
|
+
}
|
|
3018
|
+
if (cloneFresh)
|
|
3019
|
+
noteFresh(child);
|
|
3020
|
+
child = cloneEntry(child, below, named);
|
|
3021
|
+
}
|
|
3022
|
+
if (key === "__proto__")
|
|
3023
|
+
setData(copy, key, child);
|
|
3024
|
+
else
|
|
3025
|
+
copy[key] = child;
|
|
3026
|
+
}
|
|
3027
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3028
|
+
if (symbolKeys.length !== 0)
|
|
3029
|
+
pushed = fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed);
|
|
3030
|
+
} else if (kind === 1 /* Array */) {
|
|
3031
|
+
const length = copy.length;
|
|
3032
|
+
for (let i = 0;i < length; i++) {
|
|
3033
|
+
const child = value[i];
|
|
3034
|
+
if (child === null || typeof child !== "object") {
|
|
3035
|
+
if (child !== undefined || i in value)
|
|
3036
|
+
copy[i] = child;
|
|
3037
|
+
continue;
|
|
3038
|
+
}
|
|
3039
|
+
if (!pushed) {
|
|
3040
|
+
pushed = true;
|
|
3041
|
+
enterPath(identity, copy, depth);
|
|
3042
|
+
}
|
|
3043
|
+
if (cloneFresh)
|
|
3044
|
+
noteFresh(child);
|
|
3045
|
+
copy[i] = cloneEntry(child, below, named);
|
|
2685
3046
|
}
|
|
3047
|
+
if (keepsNamed(named, depth))
|
|
3048
|
+
pushed = fillNamed(value, identity, copy, depth, named, pushed);
|
|
3049
|
+
} else {
|
|
3050
|
+
pushed = kind === 2 /* Map */ ? fillMap(value, identity, copy, depth, named) : fillSet(value, identity, copy, depth, named);
|
|
2686
3051
|
}
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
3052
|
+
if (pushed) {
|
|
3053
|
+
if (depth < DEEP_PATH) {
|
|
3054
|
+
cloneAncestors.pop();
|
|
3055
|
+
cloneCopies.pop();
|
|
3056
|
+
} else {
|
|
3057
|
+
leavePath(cloneAncestors.length - 1);
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
return copy;
|
|
2694
3061
|
}
|
|
2695
|
-
function
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
3062
|
+
function cloneDeep(kind, value, identity, copy, depth, named) {
|
|
3063
|
+
const pathLength = cloneAncestors.length;
|
|
3064
|
+
if (depth >= FILL_DEPTH) {
|
|
3065
|
+
cloneWork.push(kind, value, identity, copy, pathLength);
|
|
3066
|
+
return;
|
|
3067
|
+
}
|
|
3068
|
+
const workBase = cloneWork.length;
|
|
3069
|
+
fill(kind, value, identity, copy, depth, named);
|
|
3070
|
+
fillWaiting(workBase);
|
|
3071
|
+
leavePath(pathLength);
|
|
2700
3072
|
}
|
|
2701
|
-
function
|
|
2702
|
-
if (
|
|
2703
|
-
|
|
3073
|
+
function fill(kind, value, identity, copy, depth, named) {
|
|
3074
|
+
if (kind === 0 /* Object */)
|
|
3075
|
+
fillObject(value, identity, copy, depth, named);
|
|
3076
|
+
else if (kind === 1 /* Array */)
|
|
3077
|
+
fillArray(value, identity, copy, depth, named);
|
|
3078
|
+
else if (kind === 2 /* Map */)
|
|
3079
|
+
fillMap(value, identity, copy, depth, named);
|
|
2704
3080
|
else
|
|
2705
|
-
|
|
3081
|
+
fillSet(value, identity, copy, depth, named);
|
|
2706
3082
|
}
|
|
2707
|
-
function
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
3083
|
+
function fillWaiting(workBase) {
|
|
3084
|
+
const work = cloneWork;
|
|
3085
|
+
while (work.length > workBase) {
|
|
3086
|
+
const at = work.length - 5;
|
|
3087
|
+
const kind = work[at];
|
|
3088
|
+
const value = work[at + 1];
|
|
3089
|
+
const identity = work[at + 2];
|
|
3090
|
+
const copy = work[at + 3];
|
|
3091
|
+
const pathLength = work[at + 4];
|
|
3092
|
+
work.length = at;
|
|
3093
|
+
if (cloneAncestors.length !== pathLength)
|
|
3094
|
+
leavePath(pathLength);
|
|
3095
|
+
fill(kind, value, identity, copy, FILL_DEPTH, cloneNamed);
|
|
2716
3096
|
}
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
3097
|
+
}
|
|
3098
|
+
function fillObject(value, identity, copy, depth, named) {
|
|
3099
|
+
const below = depth + 1;
|
|
3100
|
+
let pushed = false;
|
|
3101
|
+
for (const key in value) {
|
|
3102
|
+
if (!hasOwn.call(value, key))
|
|
3103
|
+
continue;
|
|
3104
|
+
let child = value[key];
|
|
3105
|
+
if (child !== null && typeof child === "object") {
|
|
3106
|
+
if (!pushed) {
|
|
3107
|
+
pushed = true;
|
|
3108
|
+
enterPath(identity, copy, depth);
|
|
3109
|
+
}
|
|
3110
|
+
if (cloneFresh)
|
|
3111
|
+
noteFresh(child);
|
|
3112
|
+
child = cloneEntry(child, below, named);
|
|
3113
|
+
}
|
|
3114
|
+
if (key === "__proto__")
|
|
3115
|
+
setData(copy, key, child);
|
|
3116
|
+
else
|
|
3117
|
+
copy[key] = child;
|
|
2720
3118
|
}
|
|
2721
|
-
const
|
|
2722
|
-
|
|
2723
|
-
return cached;
|
|
2724
|
-
evictDescendantsFromPathCache(root, pathKey);
|
|
2725
|
-
return;
|
|
3119
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3120
|
+
return symbolKeys.length === 0 ? pushed : fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed);
|
|
2726
3121
|
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
3122
|
+
function fillSymbols(value, identity, copy, depth, named, symbolKeys, pushed) {
|
|
3123
|
+
const below = depth + 1;
|
|
3124
|
+
for (let i = 0;i < symbolKeys.length; i++) {
|
|
3125
|
+
const symbolKey = symbolKeys[i];
|
|
3126
|
+
if (!isEnumerable.call(value, symbolKey))
|
|
3127
|
+
continue;
|
|
3128
|
+
const child = value[symbolKey];
|
|
3129
|
+
if (child !== null && typeof child === "object" && !pushed) {
|
|
3130
|
+
pushed = true;
|
|
3131
|
+
enterPath(identity, copy, depth);
|
|
3132
|
+
}
|
|
3133
|
+
copy[symbolKey] = cloneValue(child, below, named);
|
|
3134
|
+
}
|
|
3135
|
+
return pushed;
|
|
3136
|
+
}
|
|
3137
|
+
function fillArray(value, identity, copy, depth, named) {
|
|
3138
|
+
const below = depth + 1;
|
|
3139
|
+
let pushed = false;
|
|
3140
|
+
const length = copy.length;
|
|
3141
|
+
for (let i = 0;i < length; i++) {
|
|
3142
|
+
const child = value[i];
|
|
3143
|
+
if (child === null || typeof child !== "object") {
|
|
3144
|
+
if (child !== undefined || i in value)
|
|
3145
|
+
copy[i] = child;
|
|
3146
|
+
continue;
|
|
3147
|
+
}
|
|
3148
|
+
if (!pushed) {
|
|
3149
|
+
pushed = true;
|
|
3150
|
+
enterPath(identity, copy, depth);
|
|
3151
|
+
}
|
|
3152
|
+
if (cloneFresh)
|
|
3153
|
+
noteFresh(child);
|
|
3154
|
+
copy[i] = cloneEntry(child, below, named);
|
|
3155
|
+
}
|
|
3156
|
+
return keepsNamed(named, depth) ? fillNamed(value, identity, copy, depth, named, pushed) : pushed;
|
|
3157
|
+
}
|
|
3158
|
+
function fillNamed(value, identity, copy, depth, named, pushed) {
|
|
3159
|
+
const names = namedKeys(value);
|
|
3160
|
+
if (names === undefined)
|
|
3161
|
+
return pushed;
|
|
3162
|
+
const below = depth + 1;
|
|
3163
|
+
for (let i = 0;i < names.length; i++) {
|
|
3164
|
+
const child = value[names[i]];
|
|
3165
|
+
if (child !== null && typeof child === "object" && !pushed) {
|
|
3166
|
+
pushed = true;
|
|
3167
|
+
enterPath(identity, copy, depth);
|
|
3168
|
+
}
|
|
3169
|
+
setData(copy, names[i], cloneValue(child, below, named));
|
|
3170
|
+
}
|
|
3171
|
+
return pushed;
|
|
3172
|
+
}
|
|
3173
|
+
function fillMap(value, identity, copy, depth, named) {
|
|
3174
|
+
const below = depth + 1;
|
|
3175
|
+
enterPath(identity, copy, depth);
|
|
3176
|
+
const entries = toRaw(value);
|
|
3177
|
+
Map.prototype.forEach.call(entries, (entry, key) => {
|
|
3178
|
+
const keyCopy = cloneValue(key, below, named);
|
|
3179
|
+
copy.set(nameMember(key, keyCopy, entries, false), cloneValue(entry, below, named));
|
|
3180
|
+
});
|
|
3181
|
+
fillCollectionProperties(entries, copy, below, named);
|
|
3182
|
+
return true;
|
|
3183
|
+
}
|
|
3184
|
+
function fillSet(value, identity, copy, depth, named) {
|
|
3185
|
+
const below = depth + 1;
|
|
3186
|
+
enterPath(identity, copy, depth);
|
|
3187
|
+
const members = toRaw(value);
|
|
3188
|
+
let later;
|
|
3189
|
+
Set.prototype.forEach.call(members, (entry) => {
|
|
3190
|
+
if (entry === null || typeof entry !== "object") {
|
|
3191
|
+
copy.add(entry);
|
|
2731
3192
|
return;
|
|
2732
3193
|
}
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
},
|
|
2738
|
-
"array-push": function(targetArray, _keyIgnored, event) {
|
|
2739
|
-
if (!Array.isArray(targetArray)) {
|
|
2740
|
-
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
3194
|
+
const raw = toRaw(entry);
|
|
3195
|
+
if (raw !== entry && later === undefined && Set.prototype.has.call(members, raw))
|
|
3196
|
+
later = laterTwins(members);
|
|
3197
|
+
if (later !== undefined && later.has(entry))
|
|
2741
3198
|
return;
|
|
2742
|
-
|
|
2743
|
-
if (
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
}
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
3199
|
+
const entryCopy = cloneValue(entry, below, named);
|
|
3200
|
+
if (copyingPayload)
|
|
3201
|
+
nameCopyOfCopy(entry, entryCopy);
|
|
3202
|
+
else
|
|
3203
|
+
nameRaw(raw, collectionIdentities.members.get(raw), entry, entryCopy, members, false);
|
|
3204
|
+
copy.add(entryCopy);
|
|
3205
|
+
});
|
|
3206
|
+
fillCollectionProperties(members, copy, below, named);
|
|
3207
|
+
return true;
|
|
3208
|
+
}
|
|
3209
|
+
function laterTwins(set) {
|
|
3210
|
+
const seen = new Set;
|
|
3211
|
+
const later = new Set;
|
|
3212
|
+
Set.prototype.forEach.call(set, (member) => {
|
|
3213
|
+
if (member === null || typeof member !== "object")
|
|
2752
3214
|
return;
|
|
3215
|
+
const raw = toRaw(member);
|
|
3216
|
+
if (seen.has(raw))
|
|
3217
|
+
later.add(member);
|
|
3218
|
+
else
|
|
3219
|
+
seen.add(raw);
|
|
3220
|
+
});
|
|
3221
|
+
return later;
|
|
3222
|
+
}
|
|
3223
|
+
function fillCollectionProperties(value, copy, depth, named) {
|
|
3224
|
+
for (const key in value) {
|
|
3225
|
+
if (hasOwn.call(value, key))
|
|
3226
|
+
setData(copy, key, cloneValue(value[key], depth, named));
|
|
3227
|
+
}
|
|
3228
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
3229
|
+
for (let i = 0;i < symbols.length; i++) {
|
|
3230
|
+
if (isEnumerable.call(value, symbols[i]))
|
|
3231
|
+
setData(copy, symbols[i], cloneValue(value[symbols[i]], depth, named));
|
|
3232
|
+
}
|
|
3233
|
+
}
|
|
3234
|
+
var collectionIdentityKey = Symbol.for("@yiin/reactive-proxy-state.collection-identities.v4");
|
|
3235
|
+
var collectionIdentities = Reflect.get(globalThis, collectionIdentityKey) ?? { members: new WeakMap, copies: new WeakMap, indexes: new WeakMap, overrides: new WeakMap, watches: new WeakMap };
|
|
3236
|
+
if (!Reflect.has(globalThis, collectionIdentityKey)) {
|
|
3237
|
+
Object.defineProperty(globalThis, collectionIdentityKey, { value: collectionIdentities });
|
|
3238
|
+
}
|
|
3239
|
+
function ownToken(member) {
|
|
3240
|
+
const token = { shared: false };
|
|
3241
|
+
collectionIdentities.members.set(member, token);
|
|
3242
|
+
return token;
|
|
3243
|
+
}
|
|
3244
|
+
function nameMember(member, copy, collection, entering) {
|
|
3245
|
+
if (member === null || typeof member !== "object" || copy === null || typeof copy !== "object")
|
|
3246
|
+
return copy;
|
|
3247
|
+
if (copyingPayload) {
|
|
3248
|
+
nameCopyOfCopy(member, copy);
|
|
3249
|
+
return copy;
|
|
3250
|
+
}
|
|
3251
|
+
const raw = toRaw(member);
|
|
3252
|
+
const own = collectionIdentities.members.get(raw);
|
|
3253
|
+
if (own === undefined || own.shared)
|
|
3254
|
+
return nameRaw(raw, own, member, copy, collection, entering);
|
|
3255
|
+
if (copy !== member)
|
|
3256
|
+
collectionIdentities.copies.set(copy, own);
|
|
3257
|
+
return copy;
|
|
3258
|
+
}
|
|
3259
|
+
function nameKey(event, key, collection, entering) {
|
|
3260
|
+
const raw = toRaw(key);
|
|
3261
|
+
const own = collectionIdentities.members.get(raw);
|
|
3262
|
+
if (own === undefined) {
|
|
3263
|
+
if (entering)
|
|
3264
|
+
ownToken(raw);
|
|
3265
|
+
else
|
|
3266
|
+
namedInPlace(raw, collection);
|
|
3267
|
+
return;
|
|
3268
|
+
}
|
|
3269
|
+
if (!own.shared)
|
|
3270
|
+
return;
|
|
3271
|
+
event.key = nameRaw(raw, own, key, key, collection, entering);
|
|
3272
|
+
}
|
|
3273
|
+
function nameRaw(raw, own, member, copy, collection, entering) {
|
|
3274
|
+
let token;
|
|
3275
|
+
if (own === undefined)
|
|
3276
|
+
token = entering ? ownToken(raw) : namedInPlace(raw, collection);
|
|
3277
|
+
else if (!own.shared)
|
|
3278
|
+
token = own;
|
|
3279
|
+
else
|
|
3280
|
+
token = sharedTokenIn(raw, own, collection, entering);
|
|
3281
|
+
if (copy !== member) {
|
|
3282
|
+
collectionIdentities.copies.set(copy, token);
|
|
3283
|
+
return copy;
|
|
3284
|
+
}
|
|
3285
|
+
return own === undefined || token === own ? copy : carrier(raw, token);
|
|
3286
|
+
}
|
|
3287
|
+
function namedInPlace(member, collection) {
|
|
3288
|
+
const origin = collectionIdentities.copies.get(member);
|
|
3289
|
+
if (origin === undefined)
|
|
3290
|
+
return ownToken(member);
|
|
3291
|
+
const index = replicaIndex(collection, true);
|
|
3292
|
+
const held = heldMember(collection, index, origin);
|
|
3293
|
+
if (held !== undefined && held !== member) {
|
|
3294
|
+
const token = ownToken(member);
|
|
3295
|
+
index.byToken.set(token, member);
|
|
3296
|
+
return token;
|
|
3297
|
+
}
|
|
3298
|
+
origin.shared = true;
|
|
3299
|
+
collectionIdentities.members.set(member, origin);
|
|
3300
|
+
index.byToken.set(origin, member);
|
|
3301
|
+
return origin;
|
|
3302
|
+
}
|
|
3303
|
+
function sharedTokenIn(member, token, collection, entering) {
|
|
3304
|
+
let inCollection = collectionIdentities.overrides.get(collection);
|
|
3305
|
+
const current = inCollection?.get(member) ?? token;
|
|
3306
|
+
if (!entering)
|
|
3307
|
+
return current;
|
|
3308
|
+
const index = replicaIndex(collection, true);
|
|
3309
|
+
const held = heldMember(collection, index, current);
|
|
3310
|
+
if (held === undefined || held === member)
|
|
3311
|
+
return current;
|
|
3312
|
+
const other = { shared: false };
|
|
3313
|
+
if (inCollection === undefined)
|
|
3314
|
+
collectionIdentities.overrides.set(collection, inCollection = new WeakMap);
|
|
3315
|
+
inCollection.set(member, other);
|
|
3316
|
+
index.byToken.set(other, member);
|
|
3317
|
+
return other;
|
|
3318
|
+
}
|
|
3319
|
+
function carrier(member, token) {
|
|
3320
|
+
const copy = cloneTree(member, 2 /* All */);
|
|
3321
|
+
collectionIdentities.copies.set(copy, token);
|
|
3322
|
+
return copy;
|
|
3323
|
+
}
|
|
3324
|
+
function nameCopyOfCopy(source, copy) {
|
|
3325
|
+
if (source === null || typeof source !== "object" || copy === null || typeof copy !== "object")
|
|
3326
|
+
return;
|
|
3327
|
+
const token = collectionIdentities.copies.get(source) ?? collectionIdentities.members.get(source);
|
|
3328
|
+
if (token !== undefined)
|
|
3329
|
+
collectionIdentities.copies.set(copy, token);
|
|
3330
|
+
}
|
|
3331
|
+
var copyingPayload = false;
|
|
3332
|
+
function copyingPayloads(run) {
|
|
3333
|
+
const outer = copyingPayload;
|
|
3334
|
+
copyingPayload = true;
|
|
3335
|
+
try {
|
|
3336
|
+
return run();
|
|
3337
|
+
} finally {
|
|
3338
|
+
copyingPayload = outer;
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
function eventToken(member) {
|
|
3342
|
+
const raw = toRaw(member);
|
|
3343
|
+
return collectionIdentities.members.get(raw) ?? collectionIdentities.copies.get(raw);
|
|
3344
|
+
}
|
|
3345
|
+
function replicaIndex(collection, member) {
|
|
3346
|
+
let index = collectionIdentities.indexes.get(collection);
|
|
3347
|
+
const size = collection.size;
|
|
3348
|
+
if (index === undefined || index.size !== size || index.member !== member) {
|
|
3349
|
+
const byToken = new Map;
|
|
3350
|
+
const overrides = member ? collectionIdentities.overrides.get(collection) : undefined;
|
|
3351
|
+
const members = collection instanceof Map ? Map.prototype.keys.call(collection) : Set.prototype.values.call(collection);
|
|
3352
|
+
for (const held of members) {
|
|
3353
|
+
if (held === null || typeof held !== "object")
|
|
3354
|
+
continue;
|
|
3355
|
+
const raw = toRaw(held);
|
|
3356
|
+
if (member) {
|
|
3357
|
+
const own = overrides?.get(raw) ?? collectionIdentities.members.get(raw);
|
|
3358
|
+
if (own !== undefined) {
|
|
3359
|
+
byToken.set(own, held);
|
|
3360
|
+
continue;
|
|
3361
|
+
}
|
|
3362
|
+
const origin = collectionIdentities.copies.get(raw);
|
|
3363
|
+
if (origin !== undefined && !byToken.has(origin))
|
|
3364
|
+
byToken.set(origin, held);
|
|
3365
|
+
} else {
|
|
3366
|
+
const token = collectionIdentities.copies.get(raw) ?? collectionIdentities.members.get(raw);
|
|
3367
|
+
if (token !== undefined && !byToken.has(token))
|
|
3368
|
+
byToken.set(token, held);
|
|
3369
|
+
}
|
|
2753
3370
|
}
|
|
2754
|
-
|
|
2755
|
-
|
|
3371
|
+
index = { byToken, size, member };
|
|
3372
|
+
collectionIdentities.indexes.set(collection, index);
|
|
3373
|
+
const watch = indexWatches.get(collection);
|
|
3374
|
+
if (watch !== undefined)
|
|
3375
|
+
watch.indexed = true;
|
|
3376
|
+
}
|
|
3377
|
+
return index;
|
|
3378
|
+
}
|
|
3379
|
+
var indexWatches = collectionIdentities.watches;
|
|
3380
|
+
function watchIndex(collection) {
|
|
3381
|
+
const watch = { indexed: collectionIdentities.indexes.has(collection) };
|
|
3382
|
+
indexWatches.set(collection, watch);
|
|
3383
|
+
return watch;
|
|
3384
|
+
}
|
|
3385
|
+
function heldToken(collection, member) {
|
|
3386
|
+
return collectionIdentities.overrides.get(collection)?.get(member) ?? collectionIdentities.members.get(member);
|
|
3387
|
+
}
|
|
3388
|
+
function indexAdded(collection, member) {
|
|
3389
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3390
|
+
if (index === undefined)
|
|
3391
|
+
return;
|
|
3392
|
+
if (!index.member || index.size !== collection.size - 1) {
|
|
3393
|
+
collectionIdentities.indexes.delete(collection);
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
index.size = collection.size;
|
|
3397
|
+
if (member === null || typeof member !== "object")
|
|
3398
|
+
return;
|
|
3399
|
+
const raw = toRaw(member);
|
|
3400
|
+
const own = heldToken(collection, raw);
|
|
3401
|
+
if (own !== undefined) {
|
|
3402
|
+
index.byToken.set(own, member);
|
|
3403
|
+
return;
|
|
3404
|
+
}
|
|
3405
|
+
const origin = collectionIdentities.copies.get(raw);
|
|
3406
|
+
if (origin !== undefined && !index.byToken.has(origin))
|
|
3407
|
+
index.byToken.set(origin, member);
|
|
3408
|
+
}
|
|
3409
|
+
function indexRemoved(collection, member) {
|
|
3410
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3411
|
+
if (index === undefined)
|
|
3412
|
+
return;
|
|
3413
|
+
if (!index.member || index.size !== collection.size + 1) {
|
|
3414
|
+
collectionIdentities.indexes.delete(collection);
|
|
3415
|
+
return;
|
|
3416
|
+
}
|
|
3417
|
+
index.size = collection.size;
|
|
3418
|
+
if (member === null || typeof member !== "object")
|
|
3419
|
+
return;
|
|
3420
|
+
const raw = toRaw(member);
|
|
3421
|
+
const token = heldToken(collection, raw) ?? collectionIdentities.copies.get(raw);
|
|
3422
|
+
if (token !== undefined && index.byToken.get(token) === member)
|
|
3423
|
+
index.byToken.delete(token);
|
|
3424
|
+
}
|
|
3425
|
+
function keepIndexSize(collection) {
|
|
3426
|
+
const index = collectionIdentities.indexes.get(collection);
|
|
3427
|
+
if (index !== undefined)
|
|
3428
|
+
index.size = collection.size;
|
|
3429
|
+
}
|
|
3430
|
+
function heldMember(raw, index, token) {
|
|
3431
|
+
const held = index.byToken.get(token);
|
|
3432
|
+
return held !== undefined && raw.has(held) ? held : undefined;
|
|
3433
|
+
}
|
|
3434
|
+
function newMember(raw, member, token, reactive) {
|
|
3435
|
+
let added = member;
|
|
3436
|
+
if (raw.has(member)) {
|
|
3437
|
+
added = cloneTree(member, 2 /* All */);
|
|
3438
|
+
collectionIdentities.copies.set(added, token);
|
|
3439
|
+
}
|
|
3440
|
+
if (reactive && !collectionIdentities.members.has(added)) {
|
|
3441
|
+
token.shared = true;
|
|
3442
|
+
collectionIdentities.members.set(added, token);
|
|
3443
|
+
}
|
|
3444
|
+
return added;
|
|
3445
|
+
}
|
|
3446
|
+
function objectToken(value) {
|
|
3447
|
+
return value !== null && typeof value === "object" ? eventToken(value) : undefined;
|
|
3448
|
+
}
|
|
3449
|
+
function replicaAdd(set, value) {
|
|
3450
|
+
const raw = toRaw(set);
|
|
3451
|
+
const token = objectToken(value);
|
|
3452
|
+
if (token === undefined) {
|
|
3453
|
+
set.add(value);
|
|
3454
|
+
keepIndexSize(raw);
|
|
3455
|
+
return;
|
|
3456
|
+
}
|
|
3457
|
+
const index = replicaIndex(raw, raw !== set);
|
|
3458
|
+
if (heldMember(raw, index, token) !== undefined)
|
|
3459
|
+
return;
|
|
3460
|
+
const member = newMember(raw, toRaw(value), token, set !== raw);
|
|
3461
|
+
set.add(member);
|
|
3462
|
+
index.byToken.set(token, member);
|
|
3463
|
+
index.size = raw.size;
|
|
3464
|
+
}
|
|
3465
|
+
function replicaDelete(set, value) {
|
|
3466
|
+
const raw = toRaw(set);
|
|
3467
|
+
const token = objectToken(value);
|
|
3468
|
+
if (token === undefined) {
|
|
3469
|
+
set.delete(value);
|
|
3470
|
+
keepIndexSize(raw);
|
|
3471
|
+
return;
|
|
3472
|
+
}
|
|
3473
|
+
const index = replicaIndex(raw, raw !== set);
|
|
3474
|
+
const held = heldMember(raw, index, token);
|
|
3475
|
+
set.delete(held === undefined ? value : held);
|
|
3476
|
+
index.byToken.delete(token);
|
|
3477
|
+
index.size = raw.size;
|
|
3478
|
+
}
|
|
3479
|
+
function replicaMapSet(map, key, value) {
|
|
3480
|
+
const raw = toRaw(map);
|
|
3481
|
+
const token = objectToken(key);
|
|
3482
|
+
if (token === undefined) {
|
|
3483
|
+
map.set(key, value);
|
|
3484
|
+
keepIndexSize(raw);
|
|
3485
|
+
return;
|
|
3486
|
+
}
|
|
3487
|
+
const index = replicaIndex(raw, raw !== map);
|
|
3488
|
+
const held = heldMember(raw, index, token);
|
|
3489
|
+
if (held !== undefined) {
|
|
3490
|
+
map.set(held, value);
|
|
3491
|
+
return;
|
|
3492
|
+
}
|
|
3493
|
+
const member = newMember(raw, toRaw(key), token, map !== raw);
|
|
3494
|
+
map.set(member, value);
|
|
3495
|
+
index.byToken.set(token, member);
|
|
3496
|
+
index.size = raw.size;
|
|
3497
|
+
}
|
|
3498
|
+
function replicaMapDelete(map, key) {
|
|
3499
|
+
const raw = toRaw(map);
|
|
3500
|
+
const token = objectToken(key);
|
|
3501
|
+
if (token === undefined) {
|
|
3502
|
+
map.delete(key);
|
|
3503
|
+
keepIndexSize(raw);
|
|
3504
|
+
return;
|
|
3505
|
+
}
|
|
3506
|
+
const index = replicaIndex(raw, raw !== map);
|
|
3507
|
+
const held = heldMember(raw, index, token);
|
|
3508
|
+
map.delete(held === undefined ? key : held);
|
|
3509
|
+
index.byToken.delete(token);
|
|
3510
|
+
index.size = raw.size;
|
|
3511
|
+
}
|
|
3512
|
+
function forgetReplicaIndex(collection) {
|
|
3513
|
+
collectionIdentities.indexes.delete(toRaw(collection));
|
|
3514
|
+
}
|
|
3515
|
+
function deepClone(value, seen = new WeakMap) {
|
|
3516
|
+
if (value === null || typeof value !== "object") {
|
|
3517
|
+
return value;
|
|
3518
|
+
}
|
|
3519
|
+
if (value instanceof Date) {
|
|
3520
|
+
return new Date(value.getTime());
|
|
3521
|
+
}
|
|
3522
|
+
const identity = toRaw(value);
|
|
3523
|
+
if (seen.has(identity)) {
|
|
3524
|
+
return seen.get(identity);
|
|
3525
|
+
}
|
|
3526
|
+
if (Array.isArray(value)) {
|
|
3527
|
+
const newArray = [];
|
|
3528
|
+
seen.set(identity, newArray);
|
|
3529
|
+
for (let i = 0;i < value.length; i++) {
|
|
3530
|
+
newArray[i] = deepClone(value[i], seen);
|
|
2756
3531
|
}
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
3532
|
+
return newArray;
|
|
3533
|
+
}
|
|
3534
|
+
if (value instanceof Map) {
|
|
3535
|
+
const newMap = new Map;
|
|
3536
|
+
seen.set(identity, newMap);
|
|
3537
|
+
value.forEach((val, key) => {
|
|
3538
|
+
newMap.set(deepClone(key, seen), deepClone(val, seen));
|
|
3539
|
+
});
|
|
3540
|
+
return newMap;
|
|
3541
|
+
}
|
|
3542
|
+
if (value instanceof Set) {
|
|
3543
|
+
const newSet = new Set;
|
|
3544
|
+
seen.set(identity, newSet);
|
|
3545
|
+
value.forEach((val) => {
|
|
3546
|
+
newSet.add(deepClone(val, seen));
|
|
3547
|
+
});
|
|
3548
|
+
return newSet;
|
|
3549
|
+
}
|
|
3550
|
+
const newObject = Object.create(Object.getPrototypeOf(value));
|
|
3551
|
+
seen.set(identity, newObject);
|
|
3552
|
+
for (const key in value) {
|
|
3553
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
3554
|
+
newObject[key] = deepClone(value[key], seen);
|
|
2762
3555
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
3556
|
+
}
|
|
3557
|
+
const symbolKeys = Object.getOwnPropertySymbols(value);
|
|
3558
|
+
for (const symbolKey of symbolKeys) {
|
|
3559
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, symbolKey);
|
|
3560
|
+
if (descriptor && Object.prototype.propertyIsEnumerable.call(value, symbolKey)) {
|
|
3561
|
+
newObject[symbolKey] = deepClone(value[symbolKey], seen);
|
|
2766
3562
|
}
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
3563
|
+
}
|
|
3564
|
+
return newObject;
|
|
3565
|
+
}
|
|
3566
|
+
// src/location.ts
|
|
3567
|
+
class Place {
|
|
3568
|
+
parentRef;
|
|
3569
|
+
parentId;
|
|
3570
|
+
key;
|
|
3571
|
+
constructor(parent, key) {
|
|
3572
|
+
this.parentRef = new WeakRef(parent);
|
|
3573
|
+
this.parentId = parent.id;
|
|
3574
|
+
this.key = key;
|
|
3575
|
+
parent.childPlaces++;
|
|
3576
|
+
}
|
|
3577
|
+
get parent() {
|
|
3578
|
+
return this.parentRef.deref();
|
|
3579
|
+
}
|
|
3580
|
+
}
|
|
3581
|
+
function dropped(place) {
|
|
3582
|
+
const parent = place.parent;
|
|
3583
|
+
if (parent !== undefined)
|
|
3584
|
+
parent.childPlaces--;
|
|
3585
|
+
}
|
|
3586
|
+
var WIDE = 8;
|
|
3587
|
+
var nodes = locationNodes;
|
|
3588
|
+
var nodeCount = 0;
|
|
3589
|
+
var FAST_CHAIN_LIMIT = 256;
|
|
3590
|
+
function isObject2(value) {
|
|
3591
|
+
return value !== null && typeof value === "object";
|
|
3592
|
+
}
|
|
3593
|
+
function getLocationNode(raw) {
|
|
3594
|
+
return nodes.get(raw);
|
|
3595
|
+
}
|
|
3596
|
+
function ensureLocationNode(raw) {
|
|
3597
|
+
let node = nodes.get(raw);
|
|
3598
|
+
if (node === undefined) {
|
|
3599
|
+
node = {
|
|
3600
|
+
id: ++nodeCount,
|
|
3601
|
+
raw,
|
|
3602
|
+
kind: raw instanceof Map ? 1 /* Map */ : raw instanceof Set ? 2 /* Set */ : 0 /* Plain */,
|
|
3603
|
+
places: [],
|
|
3604
|
+
root: undefined,
|
|
3605
|
+
scope: undefined,
|
|
3606
|
+
proxy: undefined,
|
|
3607
|
+
evicted: undefined,
|
|
3608
|
+
relinked: 0,
|
|
3609
|
+
relinkedPlaces: 0,
|
|
3610
|
+
lostLink: false,
|
|
3611
|
+
dataOnly: undefined,
|
|
3612
|
+
childPlaces: 0,
|
|
3613
|
+
walk: 0,
|
|
3614
|
+
touched: 0,
|
|
3615
|
+
pruned: 0,
|
|
3616
|
+
index: undefined
|
|
3617
|
+
};
|
|
3618
|
+
nodes.set(raw, node);
|
|
3619
|
+
}
|
|
3620
|
+
return node;
|
|
3621
|
+
}
|
|
3622
|
+
function writesThroughSetter(target, prop, node) {
|
|
3623
|
+
let dataOnly = node.dataOnly;
|
|
3624
|
+
if (dataOnly === undefined)
|
|
3625
|
+
dataOnly = node.dataOnly = hasNoOwnAccessor(target);
|
|
3626
|
+
if (dataOnly)
|
|
3627
|
+
return false;
|
|
3628
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
3629
|
+
return descriptor !== undefined && descriptor.set !== undefined;
|
|
3630
|
+
}
|
|
3631
|
+
function hasNoOwnAccessor(target) {
|
|
3632
|
+
const keys = Reflect.ownKeys(target);
|
|
3633
|
+
if (keys.length > 64)
|
|
3634
|
+
return false;
|
|
3635
|
+
for (let i = 0;i < keys.length; i++) {
|
|
3636
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, keys[i]);
|
|
3637
|
+
if (descriptor.get !== undefined || descriptor.set !== undefined)
|
|
3638
|
+
return false;
|
|
3639
|
+
}
|
|
3640
|
+
return true;
|
|
3641
|
+
}
|
|
3642
|
+
function holdsIn(parent, key, raw) {
|
|
3643
|
+
if (parent === undefined)
|
|
3644
|
+
return false;
|
|
3645
|
+
const container = parent.raw;
|
|
3646
|
+
switch (parent.kind) {
|
|
3647
|
+
case 1 /* Map */: {
|
|
3648
|
+
const held = container.get(key);
|
|
3649
|
+
return held === raw || proxyOf(held, raw);
|
|
2771
3650
|
}
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
return;
|
|
3651
|
+
case 2 /* Set */:
|
|
3652
|
+
return container.has(raw);
|
|
3653
|
+
default: {
|
|
3654
|
+
const held = container[key];
|
|
3655
|
+
return held === raw || proxyOf(held, raw);
|
|
2777
3656
|
}
|
|
2778
|
-
|
|
2779
|
-
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
function proxyOf(held, raw) {
|
|
3660
|
+
return isObject2(held) && held["__v_raw" /* RAW */] !== undefined && toRaw(held) === raw;
|
|
3661
|
+
}
|
|
3662
|
+
function holds(place, raw) {
|
|
3663
|
+
return holdsIn(place.parent, place.key, raw);
|
|
3664
|
+
}
|
|
3665
|
+
function segment(parent, key, raw) {
|
|
3666
|
+
if (parent.kind === 2 /* Set */) {
|
|
3667
|
+
let index = 0;
|
|
3668
|
+
for (const member of parent.raw) {
|
|
3669
|
+
if (member === raw)
|
|
3670
|
+
break;
|
|
3671
|
+
index++;
|
|
2780
3672
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
3673
|
+
return String(index);
|
|
3674
|
+
}
|
|
3675
|
+
return String(key);
|
|
3676
|
+
}
|
|
3677
|
+
function samePlace(place, parent, key) {
|
|
3678
|
+
return place.parentId === parent.id && (parent.kind === 2 /* Set */ || place.key === key);
|
|
3679
|
+
}
|
|
3680
|
+
function chain(node, tail) {
|
|
3681
|
+
let reversed;
|
|
3682
|
+
let current = node;
|
|
3683
|
+
for (let steps = 0;steps < FAST_CHAIN_LIMIT; steps++) {
|
|
3684
|
+
const places = current.places;
|
|
3685
|
+
const root = current.root;
|
|
3686
|
+
if (root !== undefined) {
|
|
3687
|
+
if (places.length !== 0)
|
|
3688
|
+
return;
|
|
3689
|
+
return { root, paths: [buildPath(root.path, reversed, tail)] };
|
|
3690
|
+
}
|
|
3691
|
+
if (places.length !== 1)
|
|
3692
|
+
return places.length === 0 ? null : undefined;
|
|
3693
|
+
const place = places[0];
|
|
3694
|
+
const parent = place.parent;
|
|
3695
|
+
if (!holdsIn(parent, place.key, current.raw)) {
|
|
3696
|
+
dropped(place);
|
|
3697
|
+
current.places = [];
|
|
3698
|
+
return null;
|
|
2786
3699
|
}
|
|
2787
|
-
|
|
2788
|
-
|
|
3700
|
+
(reversed ??= []).push(segment(parent, place.key, current.raw));
|
|
3701
|
+
current = parent;
|
|
3702
|
+
}
|
|
3703
|
+
return;
|
|
3704
|
+
}
|
|
3705
|
+
function findAll(node, tail, firstOnly) {
|
|
3706
|
+
const out = [];
|
|
3707
|
+
const segments = [];
|
|
3708
|
+
const visiting = new Set;
|
|
3709
|
+
const frames = [];
|
|
3710
|
+
const enter = (entered) => {
|
|
3711
|
+
visiting.add(entered);
|
|
3712
|
+
const root = entered.root;
|
|
3713
|
+
if (root !== undefined)
|
|
3714
|
+
out.push({ root, path: buildPath(root.path, segments, tail) });
|
|
3715
|
+
frames.push({ node: entered, places: entered.places, next: 0, stale: false });
|
|
3716
|
+
};
|
|
3717
|
+
enter(node);
|
|
3718
|
+
while (frames.length > 0) {
|
|
3719
|
+
const frame = frames[frames.length - 1];
|
|
3720
|
+
const current = frame.node;
|
|
3721
|
+
if (frame.next < frame.places.length && !(firstOnly && out.length > 0)) {
|
|
3722
|
+
const place = frame.places[frame.next++];
|
|
3723
|
+
const parent = place.parent;
|
|
3724
|
+
if (!holdsIn(parent, place.key, current.raw)) {
|
|
3725
|
+
frame.stale = true;
|
|
3726
|
+
continue;
|
|
3727
|
+
}
|
|
3728
|
+
if (visiting.has(parent))
|
|
3729
|
+
continue;
|
|
3730
|
+
segments.push(segment(parent, place.key, current.raw));
|
|
3731
|
+
enter(parent);
|
|
3732
|
+
continue;
|
|
3733
|
+
}
|
|
3734
|
+
frames.pop();
|
|
3735
|
+
if (frame.stale)
|
|
3736
|
+
current.places = keepPlaces(frame.places, (place) => holds(place, current.raw));
|
|
3737
|
+
visiting.delete(current);
|
|
3738
|
+
if (frames.length > 0)
|
|
3739
|
+
segments.pop();
|
|
3740
|
+
}
|
|
3741
|
+
return out;
|
|
3742
|
+
}
|
|
3743
|
+
function buildPath(base, reversed, tail) {
|
|
3744
|
+
const middle = reversed === undefined ? 0 : reversed.length;
|
|
3745
|
+
const path = new Array(base.length + middle + (tail === undefined ? 0 : 1));
|
|
3746
|
+
let index = 0;
|
|
3747
|
+
for (let i = 0;i < base.length; i++)
|
|
3748
|
+
path[index++] = base[i];
|
|
3749
|
+
for (let i = middle - 1;i >= 0; i--)
|
|
3750
|
+
path[index++] = reversed[i];
|
|
3751
|
+
if (tail !== undefined)
|
|
3752
|
+
path[index] = String(tail);
|
|
3753
|
+
return path;
|
|
3754
|
+
}
|
|
3755
|
+
function locate(node, tail) {
|
|
3756
|
+
const single = chain(node, tail);
|
|
3757
|
+
if (single !== undefined) {
|
|
3758
|
+
if (single === null) {
|
|
3759
|
+
proxyStats.detachedWrites++;
|
|
2789
3760
|
return;
|
|
2790
3761
|
}
|
|
2791
|
-
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
3762
|
+
return single.root.emit === undefined ? undefined : single;
|
|
3763
|
+
}
|
|
3764
|
+
const found = findAll(node, tail, false);
|
|
3765
|
+
if (found.length === 0) {
|
|
3766
|
+
proxyStats.detachedWrites++;
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
let root = found[0].root;
|
|
3770
|
+
for (let i = 1;i < found.length; i++) {
|
|
3771
|
+
if (found[i].root !== root) {
|
|
3772
|
+
if (node.scope !== undefined && found.some((entry) => entry.root === node.scope)) {
|
|
3773
|
+
root = node.scope;
|
|
3774
|
+
}
|
|
3775
|
+
break;
|
|
2797
3776
|
}
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
3777
|
+
}
|
|
3778
|
+
if (root.emit === undefined)
|
|
3779
|
+
return;
|
|
3780
|
+
const paths = [];
|
|
3781
|
+
for (let i = 0;i < found.length; i++) {
|
|
3782
|
+
if (found[i].root === root)
|
|
3783
|
+
paths.push(found[i].path);
|
|
3784
|
+
}
|
|
3785
|
+
return { root, paths };
|
|
3786
|
+
}
|
|
3787
|
+
function isAttached(node) {
|
|
3788
|
+
const single = chain(node, undefined);
|
|
3789
|
+
if (single !== undefined)
|
|
3790
|
+
return single !== null;
|
|
3791
|
+
return findAll(node, undefined, true).length > 0;
|
|
3792
|
+
}
|
|
3793
|
+
function attachedBefore(node, former) {
|
|
3794
|
+
let current = node;
|
|
3795
|
+
for (let steps = 0;steps < FAST_CHAIN_LIMIT; steps++) {
|
|
3796
|
+
if (current.root !== undefined || current === former)
|
|
3797
|
+
return true;
|
|
3798
|
+
const places = current.places;
|
|
3799
|
+
if (places.length !== 1)
|
|
3800
|
+
break;
|
|
3801
|
+
const place = places[0];
|
|
3802
|
+
const parent = place.parent;
|
|
3803
|
+
if (!holdsIn(parent, place.key, current.raw))
|
|
3804
|
+
return false;
|
|
3805
|
+
current = parent;
|
|
3806
|
+
}
|
|
3807
|
+
if (current.root !== undefined || current === former)
|
|
3808
|
+
return true;
|
|
3809
|
+
const visited = new Set;
|
|
3810
|
+
visited.add(current);
|
|
3811
|
+
const stack = [current];
|
|
3812
|
+
const next = [0];
|
|
3813
|
+
while (stack.length > 0) {
|
|
3814
|
+
const top = stack.length - 1;
|
|
3815
|
+
const at = stack[top];
|
|
3816
|
+
const places = at.places;
|
|
3817
|
+
if (next[top] >= places.length) {
|
|
3818
|
+
stack.pop();
|
|
3819
|
+
next.pop();
|
|
3820
|
+
continue;
|
|
3821
|
+
}
|
|
3822
|
+
const place = places[next[top]++];
|
|
3823
|
+
const parent = place.parent;
|
|
3824
|
+
if (!holdsIn(parent, place.key, at.raw))
|
|
3825
|
+
continue;
|
|
3826
|
+
if (parent.root !== undefined || parent === former)
|
|
3827
|
+
return true;
|
|
3828
|
+
if (visited.has(parent))
|
|
3829
|
+
continue;
|
|
3830
|
+
visited.add(parent);
|
|
3831
|
+
stack.push(parent);
|
|
3832
|
+
next.push(0);
|
|
3833
|
+
}
|
|
3834
|
+
return false;
|
|
3835
|
+
}
|
|
3836
|
+
function dispatch(target, event) {
|
|
3837
|
+
const { root, paths } = target;
|
|
3838
|
+
if (paths.length === 1) {
|
|
3839
|
+
if (root.undelivered === undefined)
|
|
3840
|
+
root.emit(event);
|
|
3841
|
+
else
|
|
3842
|
+
deliver(root, [event]);
|
|
3843
|
+
return;
|
|
3844
|
+
}
|
|
3845
|
+
deliver(root, copyingPayloads(() => copiesPerPath(event, paths, root.async)));
|
|
3846
|
+
}
|
|
3847
|
+
function copiesPerPath(event, paths, async) {
|
|
3848
|
+
const removesValue = event.action === "set-delete";
|
|
3849
|
+
const events = [event];
|
|
3850
|
+
for (let i = 1;i < paths.length; i++) {
|
|
3851
|
+
const copy = { ...event, path: paths[i] };
|
|
3852
|
+
if (isObject2(event.newValue))
|
|
3853
|
+
copy.newValue = cloneTree(event.newValue, event.action === "replace" ? 1 /* Below */ : 0 /* None */);
|
|
3854
|
+
if (isObject2(event.value) && !removesValue) {
|
|
3855
|
+
copy.value = cloneTree(event.value, 2 /* All */);
|
|
3856
|
+
nameCopyOfCopy(event.value, copy.value);
|
|
3857
|
+
}
|
|
3858
|
+
if (event.items !== undefined)
|
|
3859
|
+
copy.items = cloneTree(event.items, 1 /* Below */);
|
|
3860
|
+
if (async) {
|
|
3861
|
+
if (isObject2(event.oldValue))
|
|
3862
|
+
copy.oldValue = cloneTree(event.oldValue, 2 /* All */);
|
|
3863
|
+
if (event.oldValues !== undefined)
|
|
3864
|
+
copy.oldValues = cloneTree(event.oldValues, 1 /* Below */);
|
|
3865
|
+
if (removesValue) {
|
|
3866
|
+
copy.value = copy.oldValue;
|
|
3867
|
+
nameCopyOfCopy(event.value, copy.value);
|
|
3868
|
+
}
|
|
3869
|
+
}
|
|
3870
|
+
events.push(copy);
|
|
3871
|
+
}
|
|
3872
|
+
return events;
|
|
3873
|
+
}
|
|
3874
|
+
function deliver(root, events) {
|
|
3875
|
+
const emit = root.emit;
|
|
3876
|
+
let queue = root.undelivered;
|
|
3877
|
+
if (queue === undefined) {
|
|
3878
|
+
if (events.length === 1) {
|
|
3879
|
+
emit(events[0]);
|
|
2803
3880
|
return;
|
|
2804
3881
|
}
|
|
2805
|
-
|
|
2806
|
-
}
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
3882
|
+
queue = root.undelivered = { events, next: 0 };
|
|
3883
|
+
} else {
|
|
3884
|
+
for (let i = 0;i < events.length; i++)
|
|
3885
|
+
queue.events.push(events[i]);
|
|
3886
|
+
}
|
|
3887
|
+
let failed = false;
|
|
3888
|
+
let failure;
|
|
3889
|
+
while (queue.next < queue.events.length) {
|
|
3890
|
+
try {
|
|
3891
|
+
emit(queue.events[queue.next++]);
|
|
3892
|
+
} catch (error) {
|
|
3893
|
+
if (!failed) {
|
|
3894
|
+
failed = true;
|
|
3895
|
+
failure = error;
|
|
3896
|
+
}
|
|
2811
3897
|
}
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
3898
|
+
}
|
|
3899
|
+
if (root.undelivered === queue)
|
|
3900
|
+
root.undelivered = undefined;
|
|
3901
|
+
if (failed)
|
|
3902
|
+
throw failure;
|
|
3903
|
+
}
|
|
3904
|
+
function copyPayload(event, target, container, held) {
|
|
3905
|
+
if (event === undefined)
|
|
3906
|
+
return 1 /* Done */;
|
|
3907
|
+
const removed = target.root.async;
|
|
3908
|
+
const { newValue, oldValue, value, items, oldValues } = event;
|
|
3909
|
+
const stored = event.action !== "set-delete";
|
|
3910
|
+
let fresh = true;
|
|
3911
|
+
let newCopy = newValue;
|
|
3912
|
+
if (isObject2(newValue)) {
|
|
3913
|
+
newCopy = held === undefined ? cloneStored(newValue, container, event.action === "replace" ? 1 /* Below */ : 0 /* None */) : cloneTreeUnless(newValue, container, event.action === "replace" ? 1 /* Below */ : 0 /* None */);
|
|
3914
|
+
if (newCopy === REACHES)
|
|
3915
|
+
return 0 /* Reaches */;
|
|
3916
|
+
fresh = held === undefined && copiedFresh;
|
|
3917
|
+
}
|
|
3918
|
+
let valueCopy = value;
|
|
3919
|
+
if (isObject2(value) && stored) {
|
|
3920
|
+
valueCopy = cloneStored(value, container, 2 /* All */);
|
|
3921
|
+
if (valueCopy === REACHES)
|
|
3922
|
+
return 0 /* Reaches */;
|
|
3923
|
+
fresh &&= copiedFresh;
|
|
3924
|
+
}
|
|
3925
|
+
let itemsCopy = items;
|
|
3926
|
+
if (items !== undefined && holdsObject(items)) {
|
|
3927
|
+
itemsCopy = cloneStored(items, container, 1 /* Below */);
|
|
3928
|
+
if (itemsCopy === REACHES)
|
|
3929
|
+
return 0 /* Reaches */;
|
|
3930
|
+
fresh &&= copiedFresh;
|
|
3931
|
+
}
|
|
3932
|
+
if (removed) {
|
|
3933
|
+
const oldCopy = isObject2(oldValue) ? cloneTreeUnless(oldValue, container, 2 /* All */) : oldValue;
|
|
3934
|
+
if (oldCopy === REACHES)
|
|
3935
|
+
return 0 /* Reaches */;
|
|
3936
|
+
const oldValuesCopy = oldValues !== undefined && holdsObject(oldValues) ? cloneTreeUnless(oldValues, container, 1 /* Below */) : oldValues;
|
|
3937
|
+
if (oldValuesCopy === REACHES)
|
|
3938
|
+
return 0 /* Reaches */;
|
|
3939
|
+
if (isObject2(oldValue))
|
|
3940
|
+
event.oldValue = oldCopy;
|
|
3941
|
+
if (oldValues !== undefined)
|
|
3942
|
+
event.oldValues = oldValuesCopy;
|
|
3943
|
+
if (!stored)
|
|
3944
|
+
valueCopy = event.oldValue;
|
|
3945
|
+
}
|
|
3946
|
+
if (isObject2(newValue))
|
|
3947
|
+
event.newValue = newCopy;
|
|
3948
|
+
if (isObject2(value))
|
|
3949
|
+
event.value = nameMember(value, valueCopy, container, stored);
|
|
3950
|
+
if (items !== undefined)
|
|
3951
|
+
event.items = itemsCopy;
|
|
3952
|
+
return fresh ? 2 /* Fresh */ : 1 /* Done */;
|
|
3953
|
+
}
|
|
3954
|
+
function copyPayloadReaching(event, target, container, after) {
|
|
3955
|
+
refuseAccessors(event, target.root.async, container, after);
|
|
3956
|
+
copyPayloadAfter(event, target, container, after);
|
|
3957
|
+
}
|
|
3958
|
+
function copyPayloadAfter(event, target, container, after) {
|
|
3959
|
+
const { newValue, oldValue, value, items, oldValues } = event;
|
|
3960
|
+
const removed = target.root.async;
|
|
3961
|
+
const stored = event.action !== "set-delete";
|
|
3962
|
+
const newCopy = isObject2(newValue) ? cloneTreeAfter(newValue, container, after, event.action === "replace" ? 1 /* Below */ : 0 /* None */) : newValue;
|
|
3963
|
+
const oldCopy = removed && isObject2(oldValue) ? cloneTreeAfter(oldValue, container, after, 2 /* All */) : oldValue;
|
|
3964
|
+
const valueCopy = !isObject2(value) ? value : stored ? cloneTreeAfter(value, container, after, 2 /* All */) : oldCopy;
|
|
3965
|
+
const itemsCopy = items !== undefined && holdsObject(items) ? cloneTreeAfter(items, container, after, 1 /* Below */) : items;
|
|
3966
|
+
const oldValuesCopy = removed && oldValues !== undefined && holdsObject(oldValues) ? cloneTreeAfter(oldValues, container, after, 1 /* Below */) : oldValues;
|
|
3967
|
+
if (isObject2(newValue))
|
|
3968
|
+
event.newValue = newCopy;
|
|
3969
|
+
if (isObject2(oldValue))
|
|
3970
|
+
event.oldValue = oldCopy;
|
|
3971
|
+
if (isObject2(value))
|
|
3972
|
+
event.value = nameMember(value, valueCopy, container, stored);
|
|
3973
|
+
if (items !== undefined)
|
|
3974
|
+
event.items = itemsCopy;
|
|
3975
|
+
if (oldValues !== undefined)
|
|
3976
|
+
event.oldValues = oldValuesCopy;
|
|
3977
|
+
}
|
|
3978
|
+
function holdsObject(values) {
|
|
3979
|
+
for (let i = 0;i < values.length; i++)
|
|
3980
|
+
if (isObject2(values[i]))
|
|
3981
|
+
return true;
|
|
3982
|
+
return false;
|
|
3983
|
+
}
|
|
3984
|
+
function shallowCopy(container) {
|
|
3985
|
+
const copy = Array.isArray(container) ? container.slice() : container instanceof Map ? new Map(Map.prototype.entries.call(container)) : container instanceof Set ? new Set(Set.prototype.values.call(container)) : Object.create(Object.getPrototypeOf(container));
|
|
3986
|
+
const keys = Reflect.ownKeys(container);
|
|
3987
|
+
for (let i = 0;i < keys.length; i++) {
|
|
3988
|
+
const value = enumerableData(container, keys[i]);
|
|
3989
|
+
if (value !== NOT_ENUMERABLE)
|
|
3990
|
+
setData(copy, keys[i], value);
|
|
3991
|
+
}
|
|
3992
|
+
return copy;
|
|
3993
|
+
}
|
|
3994
|
+
var NOT_ENUMERABLE = Symbol("not enumerable");
|
|
3995
|
+
function enumerableData(object, key) {
|
|
3996
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
3997
|
+
if (!descriptor.enumerable)
|
|
3998
|
+
return NOT_ENUMERABLE;
|
|
3999
|
+
if (descriptor.get !== undefined || descriptor.set !== undefined) {
|
|
4000
|
+
throw new UnsupportedStateError(`the accessor property '${String(key)}' sits in a payload that reaches back into the ` + `object it is written to, and a getter cannot be read as it will be after the write`);
|
|
4001
|
+
}
|
|
4002
|
+
return descriptor.value;
|
|
4003
|
+
}
|
|
4004
|
+
function refuseAccessors(event, removed, container, after) {
|
|
4005
|
+
const pending = [event.newValue];
|
|
4006
|
+
if (event.action !== "set-delete")
|
|
4007
|
+
pending.push(event.value);
|
|
4008
|
+
if (event.items !== undefined)
|
|
4009
|
+
pending.push(event.items);
|
|
4010
|
+
if (removed) {
|
|
4011
|
+
pending.push(event.oldValue);
|
|
4012
|
+
if (event.oldValues !== undefined)
|
|
4013
|
+
pending.push(event.oldValues);
|
|
4014
|
+
}
|
|
4015
|
+
const seen = new Set;
|
|
4016
|
+
while (pending.length > 0) {
|
|
4017
|
+
const entry = pending.pop();
|
|
4018
|
+
if (!isObject2(entry))
|
|
4019
|
+
continue;
|
|
4020
|
+
let value = toRaw(entry);
|
|
4021
|
+
if (value === container)
|
|
4022
|
+
value = after;
|
|
4023
|
+
if (seen.has(value))
|
|
4024
|
+
continue;
|
|
4025
|
+
seen.add(value);
|
|
4026
|
+
if (Array.isArray(value)) {
|
|
4027
|
+
for (let i = 0;i < value.length; i++)
|
|
4028
|
+
pending.push(value[i]);
|
|
4029
|
+
} else if (value instanceof Map) {
|
|
4030
|
+
for (const [key, item] of Map.prototype.entries.call(value))
|
|
4031
|
+
pending.push(key, item);
|
|
4032
|
+
} else if (value instanceof Set) {
|
|
4033
|
+
for (const item of Set.prototype.values.call(value))
|
|
4034
|
+
pending.push(item);
|
|
4035
|
+
}
|
|
4036
|
+
const keys = Reflect.ownKeys(value);
|
|
4037
|
+
for (let i = 0;i < keys.length; i++) {
|
|
4038
|
+
const item = enumerableData(value, keys[i]);
|
|
4039
|
+
if (item !== NOT_ENUMERABLE)
|
|
4040
|
+
pending.push(item);
|
|
2818
4041
|
}
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
4042
|
+
}
|
|
4043
|
+
}
|
|
4044
|
+
function addPlace(node, parent, key) {
|
|
4045
|
+
if (findPlace(node, parent, key) !== undefined)
|
|
4046
|
+
return false;
|
|
4047
|
+
pushPlace(node, new Place(parent, key));
|
|
4048
|
+
return true;
|
|
4049
|
+
}
|
|
4050
|
+
function findPlace(node, parent, key) {
|
|
4051
|
+
const places = node.places;
|
|
4052
|
+
if (places.length <= WIDE) {
|
|
4053
|
+
for (let i = 0;i < places.length; i++) {
|
|
4054
|
+
if (samePlace(places[i], parent, key))
|
|
4055
|
+
return places[i];
|
|
4056
|
+
}
|
|
4057
|
+
return;
|
|
4058
|
+
}
|
|
4059
|
+
let index = node.index;
|
|
4060
|
+
if (index === undefined || index.places !== places || index.length !== places.length) {
|
|
4061
|
+
index = node.index = { places, length: places.length, byParent: new Map };
|
|
4062
|
+
for (let i = 0;i < places.length; i++)
|
|
4063
|
+
indexPlace(index.byParent, places[i]);
|
|
4064
|
+
}
|
|
4065
|
+
const entry = index.byParent.get(parent.id);
|
|
4066
|
+
if (entry === undefined)
|
|
4067
|
+
return;
|
|
4068
|
+
if (entry instanceof Place)
|
|
4069
|
+
return parent.kind === 2 /* Set */ || entry.key === key ? entry : undefined;
|
|
4070
|
+
return entry.get(key);
|
|
4071
|
+
}
|
|
4072
|
+
function indexPlace(byParent, place) {
|
|
4073
|
+
const entry = byParent.get(place.parentId);
|
|
4074
|
+
if (entry === undefined)
|
|
4075
|
+
byParent.set(place.parentId, place);
|
|
4076
|
+
else if (entry instanceof Place) {
|
|
4077
|
+
if (entry.key !== place.key)
|
|
4078
|
+
byParent.set(place.parentId, new Map([[entry.key, entry], [place.key, place]]));
|
|
4079
|
+
} else if (!entry.has(place.key))
|
|
4080
|
+
entry.set(place.key, place);
|
|
4081
|
+
}
|
|
4082
|
+
function pushPlace(node, place) {
|
|
4083
|
+
const places = node.places;
|
|
4084
|
+
places.push(place);
|
|
4085
|
+
const index = node.index;
|
|
4086
|
+
if (index !== undefined && index.places === places && index.length === places.length - 1) {
|
|
4087
|
+
index.length++;
|
|
4088
|
+
indexPlace(index.byParent, place);
|
|
4089
|
+
}
|
|
4090
|
+
}
|
|
4091
|
+
function prunePlaces(node) {
|
|
4092
|
+
const count = node.places.length;
|
|
4093
|
+
if (count > WIDE && count < 2 * node.pruned)
|
|
4094
|
+
return;
|
|
4095
|
+
let places = keepPlaces(node.places, (place) => holds(place, node.raw));
|
|
4096
|
+
if (places.length > 1) {
|
|
4097
|
+
const live = pruneScratch;
|
|
4098
|
+
live.length = places.length;
|
|
4099
|
+
let attached = 0;
|
|
4100
|
+
let parent;
|
|
4101
|
+
let parentAttached = false;
|
|
4102
|
+
for (let i = 0;i < places.length; i++) {
|
|
4103
|
+
const next = places[i].parent;
|
|
4104
|
+
if (next !== parent) {
|
|
4105
|
+
parent = next;
|
|
4106
|
+
parentAttached = isAttached(next);
|
|
4107
|
+
}
|
|
4108
|
+
live[i] = parentAttached;
|
|
4109
|
+
if (parentAttached)
|
|
4110
|
+
attached++;
|
|
4111
|
+
}
|
|
4112
|
+
if (attached > 0 && attached < places.length) {
|
|
4113
|
+
const kept = [];
|
|
4114
|
+
for (let i = 0;i < places.length; i++) {
|
|
4115
|
+
if (live[i])
|
|
4116
|
+
kept.push(places[i]);
|
|
4117
|
+
else {
|
|
4118
|
+
markLostLink(places[i].parent);
|
|
4119
|
+
dropped(places[i]);
|
|
4120
|
+
}
|
|
4121
|
+
}
|
|
4122
|
+
places = kept;
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
pruneScratch.length = 0;
|
|
4126
|
+
node.places = places;
|
|
4127
|
+
node.pruned = places.length;
|
|
4128
|
+
}
|
|
4129
|
+
var pruneScratch = [];
|
|
4130
|
+
function keepPlaces(places, keep) {
|
|
4131
|
+
const kept = [];
|
|
4132
|
+
for (let i = 0;i < places.length; i++) {
|
|
4133
|
+
if (keep(places[i]))
|
|
4134
|
+
kept.push(places[i]);
|
|
4135
|
+
else
|
|
4136
|
+
dropped(places[i]);
|
|
4137
|
+
}
|
|
4138
|
+
return kept;
|
|
4139
|
+
}
|
|
4140
|
+
function markLostLink(node) {
|
|
4141
|
+
if (node.lostLink)
|
|
4142
|
+
return;
|
|
4143
|
+
node.lostLink = true;
|
|
4144
|
+
const pending = [node];
|
|
4145
|
+
while (pending.length > 0) {
|
|
4146
|
+
const places = pending.pop().places;
|
|
4147
|
+
for (let i = 0;i < places.length; i++) {
|
|
4148
|
+
const parent = places[i].parent;
|
|
4149
|
+
if (parent !== undefined && !parent.lostLink) {
|
|
4150
|
+
parent.lostLink = true;
|
|
4151
|
+
pending.push(parent);
|
|
4152
|
+
}
|
|
4153
|
+
}
|
|
4154
|
+
}
|
|
4155
|
+
}
|
|
4156
|
+
function notePlace(node, parent, key) {
|
|
4157
|
+
const places = node.places;
|
|
4158
|
+
if (places.length === 1 && samePlace(places[0], parent, key))
|
|
4159
|
+
return;
|
|
4160
|
+
if (addPlace(node, parent, key) && node.places.length > 1)
|
|
4161
|
+
prunePlaces(node);
|
|
4162
|
+
}
|
|
4163
|
+
function detachPlace(value, parent, key) {
|
|
4164
|
+
const node = nodes.get(value);
|
|
4165
|
+
if (node !== undefined)
|
|
4166
|
+
removePlace(node, parent, key);
|
|
4167
|
+
}
|
|
4168
|
+
function removePlace(node, parent, key) {
|
|
4169
|
+
const places = node.places;
|
|
4170
|
+
if (places.length <= WIDE) {
|
|
4171
|
+
for (let i = 0;i < places.length; i++) {
|
|
4172
|
+
if (samePlace(places[i], parent, key)) {
|
|
4173
|
+
dropped(places[i]);
|
|
4174
|
+
places.splice(i, 1);
|
|
4175
|
+
node.index = undefined;
|
|
4176
|
+
return true;
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
return false;
|
|
4180
|
+
}
|
|
4181
|
+
const place = findPlace(node, parent, key);
|
|
4182
|
+
if (place === undefined)
|
|
4183
|
+
return false;
|
|
4184
|
+
const at = places.indexOf(place);
|
|
4185
|
+
if (at < 0) {
|
|
4186
|
+
node.index = undefined;
|
|
4187
|
+
return false;
|
|
4188
|
+
}
|
|
4189
|
+
dropped(place);
|
|
4190
|
+
places.splice(at, 1);
|
|
4191
|
+
const index = node.index;
|
|
4192
|
+
index.length--;
|
|
4193
|
+
const entry = index.byParent.get(place.parentId);
|
|
4194
|
+
if (entry === place)
|
|
4195
|
+
index.byParent.delete(place.parentId);
|
|
4196
|
+
else if (entry instanceof Map && entry.get(place.key) === place)
|
|
4197
|
+
entry.delete(place.key);
|
|
4198
|
+
return true;
|
|
4199
|
+
}
|
|
4200
|
+
function newWalk(touched, store, former, held, first) {
|
|
4201
|
+
return {
|
|
4202
|
+
id: ++stamps,
|
|
4203
|
+
store,
|
|
4204
|
+
firstId: nodeCount + 1,
|
|
4205
|
+
touched,
|
|
4206
|
+
seen: new Set,
|
|
4207
|
+
repeated: undefined,
|
|
4208
|
+
aliases: first?.repeated,
|
|
4209
|
+
created: undefined,
|
|
4210
|
+
revisit: first?.created,
|
|
4211
|
+
relinked: [],
|
|
4212
|
+
former,
|
|
4213
|
+
held
|
|
4214
|
+
};
|
|
4215
|
+
}
|
|
4216
|
+
function adoptFrame(raw, node, unknown, key) {
|
|
4217
|
+
let kind = 3 /* Object */;
|
|
4218
|
+
let keys;
|
|
4219
|
+
let entries;
|
|
4220
|
+
if (Array.isArray(raw))
|
|
4221
|
+
kind = 0 /* Array */;
|
|
4222
|
+
else if (raw instanceof Map) {
|
|
4223
|
+
kind = 1 /* Map */;
|
|
4224
|
+
entries = Map.prototype.entries.call(raw);
|
|
4225
|
+
} else if (raw instanceof Set) {
|
|
4226
|
+
kind = 2 /* Set */;
|
|
4227
|
+
entries = Set.prototype.values.call(raw);
|
|
4228
|
+
} else if (raw instanceof Date || ArrayBuffer.isView(raw))
|
|
4229
|
+
kind = 4 /* None */;
|
|
4230
|
+
else
|
|
4231
|
+
keys = Object.keys(raw);
|
|
4232
|
+
return { raw, node, unknown, key, kind, next: 0, keys, entries, childKey: undefined, swaps: undefined };
|
|
4233
|
+
}
|
|
4234
|
+
function nextChild(frame) {
|
|
4235
|
+
const raw = frame.raw;
|
|
4236
|
+
switch (frame.kind) {
|
|
4237
|
+
case 0 /* Array */:
|
|
4238
|
+
while (frame.next < raw.length) {
|
|
4239
|
+
const index = frame.next++;
|
|
4240
|
+
const child = raw[index];
|
|
4241
|
+
if (isObject2(child)) {
|
|
4242
|
+
frame.childKey = index;
|
|
4243
|
+
return child;
|
|
4244
|
+
}
|
|
4245
|
+
}
|
|
4246
|
+
return;
|
|
4247
|
+
case 1 /* Map */:
|
|
4248
|
+
for (;; ) {
|
|
4249
|
+
const step = frame.entries.next();
|
|
4250
|
+
if (step.done)
|
|
4251
|
+
return;
|
|
4252
|
+
const child = step.value[1];
|
|
4253
|
+
if (isObject2(child)) {
|
|
4254
|
+
frame.childKey = step.value[0];
|
|
4255
|
+
return child;
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
case 2 /* Set */:
|
|
4259
|
+
for (;; ) {
|
|
4260
|
+
const step = frame.entries.next();
|
|
4261
|
+
if (step.done)
|
|
4262
|
+
return;
|
|
4263
|
+
if (isObject2(step.value)) {
|
|
4264
|
+
frame.childKey = undefined;
|
|
4265
|
+
return step.value;
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
case 3 /* Object */: {
|
|
4269
|
+
const keys = frame.keys;
|
|
4270
|
+
while (frame.next < keys.length) {
|
|
4271
|
+
const key = keys[frame.next++];
|
|
4272
|
+
const child = raw[key];
|
|
4273
|
+
if (isObject2(child)) {
|
|
4274
|
+
frame.childKey = key;
|
|
4275
|
+
return child;
|
|
4276
|
+
}
|
|
4277
|
+
}
|
|
2824
4278
|
return;
|
|
2825
4279
|
}
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
4280
|
+
default:
|
|
4281
|
+
return;
|
|
4282
|
+
}
|
|
4283
|
+
}
|
|
4284
|
+
function enterAdopt(raw, key, walk, frames) {
|
|
4285
|
+
let node = nodes.get(raw);
|
|
4286
|
+
if (node !== undefined) {
|
|
4287
|
+
if (node.walk === walk.id)
|
|
4288
|
+
return node;
|
|
4289
|
+
node.walk = walk.id;
|
|
4290
|
+
if (!node.lostLink && walk.revisit?.has(raw) !== true) {
|
|
4291
|
+
if (attachedBefore(node, walk.former))
|
|
4292
|
+
return node;
|
|
4293
|
+
if (walk.aliases === undefined)
|
|
4294
|
+
(walk.created ??= new Set).add(raw);
|
|
4295
|
+
}
|
|
4296
|
+
if (node.lostLink)
|
|
4297
|
+
walk.relinked.push(node);
|
|
4298
|
+
frames.push(adoptFrame(raw, node, false, key));
|
|
4299
|
+
return node;
|
|
4300
|
+
}
|
|
4301
|
+
if (raw["__v_skip" /* SKIP */])
|
|
4302
|
+
return;
|
|
4303
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */]) {
|
|
4304
|
+
const target = toRaw(raw);
|
|
4305
|
+
if (frames.length > 0)
|
|
4306
|
+
storeRaw(frames[frames.length - 1], key, raw, target);
|
|
4307
|
+
return enterAdopt(target, key, walk, frames);
|
|
4308
|
+
}
|
|
4309
|
+
const seen = walk.seen;
|
|
4310
|
+
const size = seen.size;
|
|
4311
|
+
seen.add(raw);
|
|
4312
|
+
if (seen.size === size) {
|
|
4313
|
+
(walk.repeated ??= new Set).add(raw);
|
|
4314
|
+
return;
|
|
4315
|
+
}
|
|
4316
|
+
if (walk.aliases?.has(raw))
|
|
4317
|
+
node = walkNode(raw, walk);
|
|
4318
|
+
if (walk.held?.has(raw))
|
|
4319
|
+
return node;
|
|
4320
|
+
frames.push(adoptFrame(raw, node, true, key));
|
|
4321
|
+
return node;
|
|
4322
|
+
}
|
|
4323
|
+
function walkNode(raw, walk) {
|
|
4324
|
+
const node = ensureLocationNode(raw);
|
|
4325
|
+
node.walk = walk.id;
|
|
4326
|
+
return node;
|
|
4327
|
+
}
|
|
4328
|
+
function storeRaw(frame, key, proxy, target) {
|
|
4329
|
+
const container = frame.raw;
|
|
4330
|
+
switch (frame.kind) {
|
|
4331
|
+
case 1 /* Map */:
|
|
4332
|
+
Map.prototype.set.call(container, key, target);
|
|
2831
4333
|
return;
|
|
4334
|
+
case 2 /* Set */:
|
|
4335
|
+
(frame.swaps ??= new Map).set(proxy, target);
|
|
4336
|
+
return;
|
|
4337
|
+
default: {
|
|
4338
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(container, key);
|
|
4339
|
+
if (descriptor !== undefined && descriptor.value === proxy)
|
|
4340
|
+
Reflect.set(container, key, target);
|
|
2832
4341
|
}
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
4342
|
+
}
|
|
4343
|
+
}
|
|
4344
|
+
function swapMembers(set, swaps) {
|
|
4345
|
+
const members = Array.from(Set.prototype.values.call(set));
|
|
4346
|
+
Set.prototype.clear.call(set);
|
|
4347
|
+
for (let i = 0;i < members.length; i++) {
|
|
4348
|
+
const member = members[i];
|
|
4349
|
+
Set.prototype.add.call(set, isObject2(member) && swaps.get(member) || member);
|
|
4350
|
+
}
|
|
4351
|
+
}
|
|
4352
|
+
function placeChild(frame, key, childNode, walk) {
|
|
4353
|
+
if (childNode === undefined)
|
|
4354
|
+
return;
|
|
4355
|
+
const parent = frame.node ??= walkNode(frame.raw, walk);
|
|
4356
|
+
if (parent.id < walk.firstId && childNode.id < walk.firstId) {
|
|
4357
|
+
if (walk.aliases !== undefined && !walk.aliases.has(childNode.raw))
|
|
4358
|
+
return;
|
|
4359
|
+
if (!addPlace(childNode, parent, key))
|
|
2839
4360
|
return;
|
|
4361
|
+
} else {
|
|
4362
|
+
pushPlace(childNode, new Place(parent, key));
|
|
4363
|
+
}
|
|
4364
|
+
touch(childNode, walk.store, walk.touched);
|
|
4365
|
+
}
|
|
4366
|
+
function touch(node, store, touched) {
|
|
4367
|
+
if (node.touched === store)
|
|
4368
|
+
return;
|
|
4369
|
+
node.touched = store;
|
|
4370
|
+
touched.push(node);
|
|
4371
|
+
}
|
|
4372
|
+
var stamps = 0;
|
|
4373
|
+
function walkFrames(frames, walk) {
|
|
4374
|
+
for (;; ) {
|
|
4375
|
+
const frame = frames[frames.length - 1];
|
|
4376
|
+
const child = nextChild(frame);
|
|
4377
|
+
if (child !== undefined) {
|
|
4378
|
+
const depth = frames.length;
|
|
4379
|
+
const childNode = enterAdopt(child, frame.childKey, walk, frames);
|
|
4380
|
+
if (frames.length === depth)
|
|
4381
|
+
placeChild(frame, frame.childKey, childNode, walk);
|
|
4382
|
+
continue;
|
|
4383
|
+
}
|
|
4384
|
+
frames.pop();
|
|
4385
|
+
if (frame.swaps !== undefined)
|
|
4386
|
+
swapMembers(frame.raw, frame.swaps);
|
|
4387
|
+
const node = frame.node;
|
|
4388
|
+
if (frame.unknown && node !== undefined && walk.aliases === undefined)
|
|
4389
|
+
(walk.created ??= new Set).add(frame.raw);
|
|
4390
|
+
if (frames.length === 0)
|
|
4391
|
+
return node;
|
|
4392
|
+
placeChild(frames[frames.length - 1], frame.key, node, walk);
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4395
|
+
function adopt(raw, walk) {
|
|
4396
|
+
const frames = [];
|
|
4397
|
+
const node = enterAdopt(raw, undefined, walk, frames);
|
|
4398
|
+
return frames.length === 0 ? node : walkFrames(frames, walk);
|
|
4399
|
+
}
|
|
4400
|
+
function adoptAll(touched, store, former, held, visit) {
|
|
4401
|
+
let walk = newWalk(touched, store, former, held);
|
|
4402
|
+
visit(walk);
|
|
4403
|
+
if (walk.repeated !== undefined) {
|
|
4404
|
+
const first = walk;
|
|
4405
|
+
walk = newWalk(touched, store, former, held, first);
|
|
4406
|
+
visit(walk);
|
|
4407
|
+
for (let i = 0;i < first.relinked.length; i++)
|
|
4408
|
+
first.relinked[i].lostLink = false;
|
|
4409
|
+
}
|
|
4410
|
+
for (let i = 0;i < walk.relinked.length; i++)
|
|
4411
|
+
walk.relinked[i].lostLink = false;
|
|
4412
|
+
}
|
|
4413
|
+
function pruneTouched(touched) {
|
|
4414
|
+
for (let i = 0;i < touched.length; i++) {
|
|
4415
|
+
if (touched[i].places.length > 1)
|
|
4416
|
+
prunePlaces(touched[i]);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
4419
|
+
function hasObjectChild(raw) {
|
|
4420
|
+
if (Array.isArray(raw)) {
|
|
4421
|
+
for (let i = 0;i < raw.length; i++)
|
|
4422
|
+
if (isObject2(raw[i]))
|
|
4423
|
+
return true;
|
|
4424
|
+
return false;
|
|
4425
|
+
}
|
|
4426
|
+
if (Object.getPrototypeOf(raw) !== Object.prototype) {
|
|
4427
|
+
if (raw instanceof Map || raw instanceof Set) {
|
|
4428
|
+
const entries = raw instanceof Map ? Map.prototype.values.call(raw) : Set.prototype.values.call(raw);
|
|
4429
|
+
for (const child of entries)
|
|
4430
|
+
if (isObject2(child))
|
|
4431
|
+
return true;
|
|
4432
|
+
return false;
|
|
2840
4433
|
}
|
|
2841
|
-
if (
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
4434
|
+
if (raw instanceof Date || ArrayBuffer.isView(raw))
|
|
4435
|
+
return false;
|
|
4436
|
+
}
|
|
4437
|
+
for (const key in raw) {
|
|
4438
|
+
if (Object.prototype.hasOwnProperty.call(raw, key) && isObject2(raw[key]))
|
|
4439
|
+
return true;
|
|
4440
|
+
}
|
|
4441
|
+
return false;
|
|
4442
|
+
}
|
|
4443
|
+
function insertedNeedWalk(inserted) {
|
|
4444
|
+
let fresh;
|
|
4445
|
+
for (let i = 0;i < inserted.length; i++) {
|
|
4446
|
+
const value = inserted[i];
|
|
4447
|
+
if (!isObject2(value))
|
|
4448
|
+
continue;
|
|
4449
|
+
const node = nodes.get(value);
|
|
4450
|
+
if (node !== undefined) {
|
|
4451
|
+
if (node.lostLink || !attachedBefore(node, undefined))
|
|
4452
|
+
return true;
|
|
4453
|
+
continue;
|
|
4454
|
+
}
|
|
4455
|
+
if (hasObjectChild(value))
|
|
4456
|
+
return true;
|
|
4457
|
+
if (inserted.length > 1) {
|
|
4458
|
+
if (fresh === undefined)
|
|
4459
|
+
fresh = new Set;
|
|
4460
|
+
else if (fresh.has(value))
|
|
4461
|
+
return true;
|
|
4462
|
+
fresh.add(value);
|
|
2860
4463
|
}
|
|
2861
4464
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
if (!
|
|
2866
|
-
console.warn("event path is invalid for action", event);
|
|
4465
|
+
return false;
|
|
4466
|
+
}
|
|
4467
|
+
function heldBefore(value, replaced) {
|
|
4468
|
+
if (!Array.isArray(value) || !Array.isArray(replaced))
|
|
2867
4469
|
return;
|
|
4470
|
+
let before;
|
|
4471
|
+
for (let i = 0;i < value.length; i++) {
|
|
4472
|
+
const item = value[i];
|
|
4473
|
+
if (!isObject2(item) || nodes.get(item) !== undefined)
|
|
4474
|
+
continue;
|
|
4475
|
+
if (before === undefined) {
|
|
4476
|
+
if (replaced.indexOf(item) === -1)
|
|
4477
|
+
return;
|
|
4478
|
+
before = new Set;
|
|
4479
|
+
for (let j = 0;j < replaced.length; j++)
|
|
4480
|
+
if (isObject2(replaced[j]))
|
|
4481
|
+
before.add(replaced[j]);
|
|
4482
|
+
}
|
|
4483
|
+
if (!before.has(item))
|
|
4484
|
+
return;
|
|
2868
4485
|
}
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
4486
|
+
return before;
|
|
4487
|
+
}
|
|
4488
|
+
function heldItems(value, replaced) {
|
|
4489
|
+
if (!isObject2(value) || !isObject2(replaced) || nodes.get(replaced) === undefined)
|
|
4490
|
+
return;
|
|
4491
|
+
return heldBefore(value, replaced);
|
|
4492
|
+
}
|
|
4493
|
+
function attachValue(value, parent, key, fresh, replaced, held) {
|
|
4494
|
+
if (fresh)
|
|
4495
|
+
return;
|
|
4496
|
+
const former = isObject2(replaced) ? nodes.get(replaced) : undefined;
|
|
4497
|
+
const existing = nodes.get(value);
|
|
4498
|
+
if (existing !== undefined && !existing.lostLink && attachedBefore(existing, former)) {
|
|
4499
|
+
if (addPlace(existing, parent, key) && existing.places.length > 1)
|
|
4500
|
+
prunePlaces(existing);
|
|
2872
4501
|
return;
|
|
2873
4502
|
}
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
4503
|
+
if (existing === undefined && !hasObjectChild(value))
|
|
4504
|
+
return;
|
|
4505
|
+
const touched = [];
|
|
4506
|
+
const store = ++stamps;
|
|
4507
|
+
adoptAll(touched, store, former, held, (walk) => {
|
|
4508
|
+
const node = adopt(value, walk);
|
|
4509
|
+
if (node !== undefined && addPlace(node, parent, key))
|
|
4510
|
+
touch(node, store, touched);
|
|
4511
|
+
});
|
|
4512
|
+
pruneTouched(touched);
|
|
4513
|
+
}
|
|
4514
|
+
function adoptRoot(node) {
|
|
4515
|
+
const touched = [];
|
|
4516
|
+
adoptAll(touched, ++stamps, undefined, undefined, (walk) => {
|
|
4517
|
+
node.walk = walk.id;
|
|
4518
|
+
walkFrames([adoptFrame(node.raw, node, false, undefined)], walk);
|
|
4519
|
+
});
|
|
4520
|
+
pruneTouched(touched);
|
|
4521
|
+
}
|
|
4522
|
+
function relinkArray(arrayNode, array, from, removed, inserted, insertedFresh = false) {
|
|
4523
|
+
if (insertedFresh)
|
|
4524
|
+
inserted = undefined;
|
|
4525
|
+
relink(arrayNode, array, from, removed, inserted, false);
|
|
4526
|
+
}
|
|
4527
|
+
function relinkReorder(arrayNode, array, removed, inserted) {
|
|
4528
|
+
relink(arrayNode, array, 0, removed, inserted, true);
|
|
4529
|
+
}
|
|
4530
|
+
function relink(arrayNode, array, from, removed, inserted, findAliases) {
|
|
4531
|
+
const touched = [];
|
|
4532
|
+
const store = ++stamps;
|
|
4533
|
+
if (inserted !== undefined && insertedNeedWalk(inserted)) {
|
|
4534
|
+
adoptAll(touched, store, undefined, undefined, (walk) => {
|
|
4535
|
+
for (let i = 0;i < inserted.length; i++) {
|
|
4536
|
+
const value = inserted[i];
|
|
4537
|
+
if (isObject2(value))
|
|
4538
|
+
adopt(value, walk);
|
|
2891
4539
|
}
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
4540
|
+
});
|
|
4541
|
+
}
|
|
4542
|
+
let removedNode = false;
|
|
4543
|
+
if (removed !== undefined) {
|
|
4544
|
+
for (let i = 0;i < removed.length; i++) {
|
|
4545
|
+
const value = removed[i];
|
|
4546
|
+
if (isObject2(value)) {
|
|
4547
|
+
const node = nodes.get(value);
|
|
4548
|
+
if (node !== undefined) {
|
|
4549
|
+
stripIndexes(node, arrayNode, from);
|
|
4550
|
+
removedNode = true;
|
|
4551
|
+
}
|
|
2895
4552
|
}
|
|
2896
|
-
targetForHandler = parent;
|
|
2897
|
-
keyForHandler = path[path.length - 1];
|
|
2898
4553
|
}
|
|
2899
|
-
}
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
if (
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
4554
|
+
}
|
|
4555
|
+
const call = ++relinkCalls;
|
|
4556
|
+
let firstIndex;
|
|
4557
|
+
let left = findAliases || removedNode || holdsNode(inserted) ? Infinity : arrayNode.childPlaces;
|
|
4558
|
+
for (let i = from;i < array.length && left > 0; i++) {
|
|
4559
|
+
const value = array[i];
|
|
4560
|
+
if (!isObject2(value))
|
|
4561
|
+
continue;
|
|
4562
|
+
let node = nodes.get(value);
|
|
4563
|
+
if (node === undefined) {
|
|
4564
|
+
if (!findAliases)
|
|
4565
|
+
continue;
|
|
4566
|
+
const first = (firstIndex ??= new Map).get(value);
|
|
4567
|
+
if (first === undefined) {
|
|
4568
|
+
firstIndex.set(value, i);
|
|
4569
|
+
continue;
|
|
2913
4570
|
}
|
|
2914
|
-
if (
|
|
2915
|
-
|
|
2916
|
-
|
|
4571
|
+
if (value["__v_skip" /* SKIP */])
|
|
4572
|
+
continue;
|
|
4573
|
+
node = ensureLocationNode(value);
|
|
4574
|
+
node.relinked = call;
|
|
4575
|
+
node.relinkedPlaces = 0;
|
|
4576
|
+
node.places.push(new Place(arrayNode, first));
|
|
4577
|
+
} else if (node.relinked !== call) {
|
|
4578
|
+
node.relinked = call;
|
|
4579
|
+
const places = node.places;
|
|
4580
|
+
if (places.length === 1 && places[0].parentId === arrayNode.id && typeof places[0].key === "number" && places[0].key >= from) {
|
|
4581
|
+
places[0].key = i;
|
|
4582
|
+
node.relinkedPlaces = 0;
|
|
4583
|
+
left--;
|
|
4584
|
+
continue;
|
|
2917
4585
|
}
|
|
2918
|
-
|
|
4586
|
+
node.relinkedPlaces = stripIndexes(node, arrayNode, from);
|
|
2919
4587
|
}
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
4588
|
+
if (node.relinkedPlaces > 0) {
|
|
4589
|
+
node.relinkedPlaces--;
|
|
4590
|
+
left--;
|
|
4591
|
+
}
|
|
4592
|
+
node.places.push(new Place(arrayNode, i));
|
|
4593
|
+
if (node.places.length > 1)
|
|
4594
|
+
touch(node, store, touched);
|
|
2923
4595
|
}
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
4596
|
+
pruneTouched(touched);
|
|
4597
|
+
}
|
|
4598
|
+
var relinkCalls = 0;
|
|
4599
|
+
function holdsNode(values) {
|
|
4600
|
+
if (values === undefined)
|
|
4601
|
+
return false;
|
|
4602
|
+
for (let i = 0;i < values.length; i++) {
|
|
4603
|
+
const value = values[i];
|
|
4604
|
+
if (isObject2(value) && nodes.get(value) !== undefined)
|
|
4605
|
+
return true;
|
|
4606
|
+
}
|
|
4607
|
+
return false;
|
|
4608
|
+
}
|
|
4609
|
+
function stripIndexes(node, arrayNode, from) {
|
|
4610
|
+
const places = node.places;
|
|
4611
|
+
let count = 0;
|
|
4612
|
+
for (let i = places.length - 1;i >= 0; i--) {
|
|
4613
|
+
const place = places[i];
|
|
4614
|
+
if (place.parentId === arrayNode.id && typeof place.key === "number" && place.key >= from) {
|
|
4615
|
+
arrayNode.childPlaces--;
|
|
4616
|
+
places.splice(i, 1);
|
|
4617
|
+
count++;
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
if (count > 0)
|
|
4621
|
+
node.index = undefined;
|
|
4622
|
+
return count;
|
|
4623
|
+
}
|
|
4624
|
+
function evictDeep(value, parent) {
|
|
4625
|
+
if (value == null || typeof value !== "object")
|
|
4626
|
+
return;
|
|
4627
|
+
const top = toRaw(value);
|
|
4628
|
+
if (globalSeen.get(top) === undefined)
|
|
4629
|
+
return;
|
|
4630
|
+
const pending = [parent, undefined, top];
|
|
4631
|
+
while (pending.length > 0) {
|
|
4632
|
+
const raw = pending.pop();
|
|
4633
|
+
const key = pending.pop();
|
|
4634
|
+
const container = pending.pop();
|
|
4635
|
+
const proxy = globalSeen.get(raw);
|
|
4636
|
+
if (proxy === undefined)
|
|
4637
|
+
continue;
|
|
4638
|
+
const node = nodes.get(raw);
|
|
4639
|
+
if (node !== undefined) {
|
|
4640
|
+
const places = node.places;
|
|
4641
|
+
const onlyUnderParent = container !== undefined && node.root === undefined && places.length === 1 && places[0].parentId === container.id;
|
|
4642
|
+
if (!onlyUnderParent) {
|
|
4643
|
+
if (container !== undefined && places.length > 1 && removePlace(node, container, key))
|
|
4644
|
+
markLostLink(container);
|
|
4645
|
+
if (isAttached(node))
|
|
4646
|
+
continue;
|
|
4647
|
+
}
|
|
4648
|
+
node.proxy = undefined;
|
|
4649
|
+
node.evicted = new WeakRef(proxy);
|
|
4650
|
+
}
|
|
4651
|
+
globalSeen.delete(raw);
|
|
4652
|
+
wrapperCache.delete(raw);
|
|
4653
|
+
proxyStats.staleEvicted++;
|
|
4654
|
+
if (Array.isArray(raw)) {
|
|
4655
|
+
for (let i = 0;i < raw.length; i++)
|
|
4656
|
+
pushProxied(raw[i], node, i, pending);
|
|
4657
|
+
} else if (raw instanceof Map) {
|
|
4658
|
+
Map.prototype.forEach.call(raw, (child, key2) => pushProxied(child, node, key2, pending));
|
|
4659
|
+
} else if (raw instanceof Set) {
|
|
4660
|
+
for (const child of Set.prototype.values.call(raw))
|
|
4661
|
+
pushProxied(child, node, undefined, pending);
|
|
4662
|
+
} else {
|
|
4663
|
+
const keys = Object.keys(raw);
|
|
4664
|
+
for (let i = 0;i < keys.length; i++)
|
|
4665
|
+
pushProxied(raw[keys[i]], node, keys[i], pending);
|
|
4666
|
+
}
|
|
2928
4667
|
}
|
|
2929
4668
|
}
|
|
4669
|
+
function pushProxied(value, container, key, pending) {
|
|
4670
|
+
if (value === null || typeof value !== "object")
|
|
4671
|
+
return;
|
|
4672
|
+
const raw = toRaw(value);
|
|
4673
|
+
if (globalSeen.get(raw) !== undefined)
|
|
4674
|
+
pending.push(container, key, raw);
|
|
4675
|
+
}
|
|
4676
|
+
function restoreEvicted(node) {
|
|
4677
|
+
const proxy = node.evicted?.deref();
|
|
4678
|
+
node.evicted = undefined;
|
|
4679
|
+
if (proxy === undefined)
|
|
4680
|
+
return;
|
|
4681
|
+
node.proxy = proxy;
|
|
4682
|
+
globalSeen.set(node.raw, proxy);
|
|
4683
|
+
wrapperCache.set(node.raw, proxy);
|
|
4684
|
+
proxyStats.staleEvicted--;
|
|
4685
|
+
return proxy;
|
|
4686
|
+
}
|
|
4687
|
+
|
|
2930
4688
|
// src/watch-effect.ts
|
|
2931
4689
|
var activeEffect = null;
|
|
2932
4690
|
var queuedEffects = new Map;
|
|
@@ -3038,70 +4796,583 @@ function trigger(target, key) {
|
|
|
3038
4796
|
queuedEffects.set(effect, triggerLevel);
|
|
3039
4797
|
}
|
|
3040
4798
|
}
|
|
3041
|
-
});
|
|
3042
|
-
}
|
|
3043
|
-
};
|
|
3044
|
-
addEffects(key);
|
|
3045
|
-
if (queuedEffects.size > 0) {
|
|
3046
|
-
flushEffects();
|
|
3047
|
-
}
|
|
3048
|
-
} finally {
|
|
3049
|
-
currentTriggerDepth--;
|
|
3050
|
-
}
|
|
3051
|
-
}
|
|
3052
|
-
function watchEffect(effectCallback, options = {}) {
|
|
3053
|
-
const run = () => {
|
|
3054
|
-
if (!effectFn.active) {
|
|
3055
|
-
throw new Error("Trying to run a stopped effect");
|
|
3056
|
-
}
|
|
3057
|
-
const previousEffect = activeEffect;
|
|
3058
|
-
try {
|
|
3059
|
-
runCleanupFunctions(effectFn);
|
|
3060
|
-
cleanupEffect(effectFn);
|
|
3061
|
-
setActiveEffect(effectFn);
|
|
3062
|
-
const onCleanup = (cleanupFn) => {
|
|
3063
|
-
if (!effectFn.cleanupFns) {
|
|
3064
|
-
effectFn.cleanupFns = [];
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4801
|
+
};
|
|
4802
|
+
addEffects(key);
|
|
4803
|
+
if (queuedEffects.size > 0) {
|
|
4804
|
+
flushEffects();
|
|
4805
|
+
}
|
|
4806
|
+
} finally {
|
|
4807
|
+
currentTriggerDepth--;
|
|
4808
|
+
}
|
|
4809
|
+
}
|
|
4810
|
+
function watchEffect(effectCallback, options = {}) {
|
|
4811
|
+
const run = () => {
|
|
4812
|
+
if (!effectFn.active) {
|
|
4813
|
+
throw new Error("Trying to run a stopped effect");
|
|
4814
|
+
}
|
|
4815
|
+
const previousEffect = activeEffect;
|
|
4816
|
+
try {
|
|
4817
|
+
runCleanupFunctions(effectFn);
|
|
4818
|
+
cleanupEffect(effectFn);
|
|
4819
|
+
setActiveEffect(effectFn);
|
|
4820
|
+
const onCleanup = (cleanupFn) => {
|
|
4821
|
+
if (!effectFn.cleanupFns) {
|
|
4822
|
+
effectFn.cleanupFns = [];
|
|
4823
|
+
}
|
|
4824
|
+
effectFn.cleanupFns.push(cleanupFn);
|
|
4825
|
+
};
|
|
4826
|
+
return effectCallback(onCleanup);
|
|
4827
|
+
} finally {
|
|
4828
|
+
setActiveEffect(previousEffect);
|
|
4829
|
+
}
|
|
4830
|
+
};
|
|
4831
|
+
const effectFn = {
|
|
4832
|
+
run,
|
|
4833
|
+
dependencies: new Set,
|
|
4834
|
+
options,
|
|
4835
|
+
active: true,
|
|
4836
|
+
_rawCallback: effectCallback,
|
|
4837
|
+
cleanupFns: []
|
|
4838
|
+
};
|
|
4839
|
+
if (!options.lazy) {
|
|
4840
|
+
effectFn.run();
|
|
4841
|
+
}
|
|
4842
|
+
const stopHandle = () => {
|
|
4843
|
+
if (effectFn.active) {
|
|
4844
|
+
runCleanupFunctions(effectFn);
|
|
4845
|
+
cleanupEffect(effectFn);
|
|
4846
|
+
effectFn.active = false;
|
|
4847
|
+
queuedEffects.delete(effectFn);
|
|
4848
|
+
}
|
|
4849
|
+
};
|
|
4850
|
+
stopHandle.effect = effectFn;
|
|
4851
|
+
return stopHandle;
|
|
4852
|
+
}
|
|
4853
|
+
|
|
4854
|
+
// src/wrap-array.ts
|
|
4855
|
+
function isObject3(v) {
|
|
4856
|
+
return v && typeof v === "object";
|
|
4857
|
+
}
|
|
4858
|
+
function arrayIndex(prop) {
|
|
4859
|
+
if (typeof prop !== "string" || prop.length === 0 || prop.length > 10)
|
|
4860
|
+
return -1;
|
|
4861
|
+
const first = prop.charCodeAt(0);
|
|
4862
|
+
if (first < 48 || first > 57 || first === 48 && prop.length > 1)
|
|
4863
|
+
return -1;
|
|
4864
|
+
for (let i = 1;i < prop.length; i++) {
|
|
4865
|
+
const code = prop.charCodeAt(i);
|
|
4866
|
+
if (code < 48 || code > 57)
|
|
4867
|
+
return -1;
|
|
4868
|
+
}
|
|
4869
|
+
const index = Number(prop);
|
|
4870
|
+
return index < 4294967295 ? index : -1;
|
|
4871
|
+
}
|
|
4872
|
+
function placeKey(prop) {
|
|
4873
|
+
const index = arrayIndex(prop);
|
|
4874
|
+
return index >= 0 ? index : prop;
|
|
4875
|
+
}
|
|
4876
|
+
function toIntegerOrInfinity(value) {
|
|
4877
|
+
const number = +value;
|
|
4878
|
+
if (number !== number || number === 0)
|
|
4879
|
+
return 0;
|
|
4880
|
+
return Math.trunc(number);
|
|
4881
|
+
}
|
|
4882
|
+
function clampIndex(relative, length) {
|
|
4883
|
+
return relative < 0 ? Math.max(length + relative, 0) : Math.min(relative, length);
|
|
4884
|
+
}
|
|
4885
|
+
function unwrapItems(items) {
|
|
4886
|
+
for (let i = 0;i < items.length; i++) {
|
|
4887
|
+
if (isObject3(items[i]))
|
|
4888
|
+
items[i] = unwrapForStore(items[i]);
|
|
4889
|
+
}
|
|
4890
|
+
}
|
|
4891
|
+
function planReorder(target, prop, method, args) {
|
|
4892
|
+
const length = target.length;
|
|
4893
|
+
if (prop === "fill" || prop === "copyWithin") {
|
|
4894
|
+
const fill2 = prop === "fill";
|
|
4895
|
+
const to = fill2 ? 0 : clampIndex(toIntegerOrInfinity(args[0]), length);
|
|
4896
|
+
const start = clampIndex(toIntegerOrInfinity(args[1]), length);
|
|
4897
|
+
const end = args[2] === undefined ? length : clampIndex(toIntegerOrInfinity(args[2]), length);
|
|
4898
|
+
const after2 = target.slice();
|
|
4899
|
+
method.call(after2, fill2 ? args[0] : to, start, end);
|
|
4900
|
+
const size = after2.length;
|
|
4901
|
+
if (fill2)
|
|
4902
|
+
return { after: after2, first: Math.min(start, size), last: Math.min(end, size), skip: -1 };
|
|
4903
|
+
const from = Math.min(to, size);
|
|
4904
|
+
const count = Math.min(Math.min(end, size) - Math.min(start, size), size - from);
|
|
4905
|
+
return { after: after2, first: from, last: from + Math.max(count, 0), skip: -1 };
|
|
4906
|
+
}
|
|
4907
|
+
const after = target.slice();
|
|
4908
|
+
method.apply(after, args);
|
|
4909
|
+
if (prop === "reverse") {
|
|
4910
|
+
return { after, first: 0, last: length, skip: length % 2 === 1 ? (length - 1) / 2 : -1 };
|
|
4911
|
+
}
|
|
4912
|
+
const sorted = length < 2 ? 0 : length;
|
|
4913
|
+
for (let i = length;i < target.length; i++) {
|
|
4914
|
+
if (i in target)
|
|
4915
|
+
after[i] = target[i];
|
|
4916
|
+
else
|
|
4917
|
+
after.length = i + 1;
|
|
4918
|
+
}
|
|
4919
|
+
return { after, first: 0, last: sorted, skip: -1 };
|
|
4920
|
+
}
|
|
4921
|
+
var strictWrites = function() {
|
|
4922
|
+
return this === undefined;
|
|
4923
|
+
}();
|
|
4924
|
+
function checkReorder(target, reorder) {
|
|
4925
|
+
const { after, first, last, skip } = reorder;
|
|
4926
|
+
let extensible;
|
|
4927
|
+
for (let i = first;i < last; i++) {
|
|
4928
|
+
if (i === skip)
|
|
4929
|
+
continue;
|
|
4930
|
+
if (i in after) {
|
|
4931
|
+
if (i in target) {
|
|
4932
|
+
if (strictWrites)
|
|
4933
|
+
target[i] = target[i];
|
|
4934
|
+
else if (!Reflect.set(target, i, target[i]))
|
|
4935
|
+
throw new TypeError(`Cannot assign to read only property '${i}' of array`);
|
|
4936
|
+
} else if (!(extensible ??= Object.isExtensible(target))) {
|
|
4937
|
+
throw new TypeError(`Cannot add property ${i}, array is not extensible`);
|
|
4938
|
+
}
|
|
4939
|
+
} else if (i in target && !Reflect.getOwnPropertyDescriptor(target, i).configurable) {
|
|
4940
|
+
throw new TypeError(`Cannot delete property '${i}' of array`);
|
|
4941
|
+
}
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4944
|
+
function reorderChanges(target, after) {
|
|
4945
|
+
if (after.length !== target.length)
|
|
4946
|
+
return true;
|
|
4947
|
+
for (let i = 0;i < after.length; i++) {
|
|
4948
|
+
const value = after[i];
|
|
4949
|
+
const current = target[i];
|
|
4950
|
+
if (value !== current) {
|
|
4951
|
+
if (value === value || current === current)
|
|
4952
|
+
return true;
|
|
4953
|
+
} else if (value === 0) {
|
|
4954
|
+
if (1 / value !== 1 / current)
|
|
4955
|
+
return true;
|
|
4956
|
+
} else if (value === undefined && i in after !== i in target) {
|
|
4957
|
+
return true;
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
return false;
|
|
4961
|
+
}
|
|
4962
|
+
function writeReorder(target, reorder) {
|
|
4963
|
+
const { after, first, last, skip } = reorder;
|
|
4964
|
+
for (let i = first;i < last; i++) {
|
|
4965
|
+
if (i === skip)
|
|
4966
|
+
continue;
|
|
4967
|
+
if (i in after)
|
|
4968
|
+
target[i] = after[i];
|
|
4969
|
+
else
|
|
4970
|
+
delete target[i];
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4973
|
+
function evictRemoved(removed) {
|
|
4974
|
+
for (let i = 0;i < removed.length; i++) {
|
|
4975
|
+
if (isObject3(removed[i]))
|
|
4976
|
+
evictDeep(removed[i]);
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
function wrapArray(arr, node) {
|
|
4980
|
+
const cachedProxy = wrapperCache.get(arr);
|
|
4981
|
+
if (cachedProxy)
|
|
4982
|
+
return cachedProxy;
|
|
4983
|
+
if (globalSeen.has(arr))
|
|
4984
|
+
return globalSeen.get(arr);
|
|
4985
|
+
const methodCache = {};
|
|
4986
|
+
const proxy = new Proxy(arr, {
|
|
4987
|
+
get(target, prop, receiver) {
|
|
4988
|
+
if (prop === "__v_raw" /* RAW */)
|
|
4989
|
+
return target;
|
|
4990
|
+
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
4991
|
+
return true;
|
|
4992
|
+
track(target, prop);
|
|
4993
|
+
if (methodCache[prop]) {
|
|
4994
|
+
return methodCache[prop];
|
|
4995
|
+
}
|
|
4996
|
+
switch (prop) {
|
|
4997
|
+
case "sort":
|
|
4998
|
+
case "reverse":
|
|
4999
|
+
case "fill":
|
|
5000
|
+
case "copyWithin": {
|
|
5001
|
+
track(target, "length");
|
|
5002
|
+
const method = Array.prototype[prop];
|
|
5003
|
+
methodCache[prop] = function(...args) {
|
|
5004
|
+
if (prop === "fill" && isObject3(args[0]))
|
|
5005
|
+
args[0] = unwrapForStore(args[0]);
|
|
5006
|
+
const reorder = planReorder(target, prop, method, args);
|
|
5007
|
+
const before = target.slice();
|
|
5008
|
+
checkReorder(target, reorder);
|
|
5009
|
+
const after = reorder.after;
|
|
5010
|
+
if (!reorderChanges(target, after))
|
|
5011
|
+
return proxy;
|
|
5012
|
+
const located = locate(node);
|
|
5013
|
+
const event = located && {
|
|
5014
|
+
action: "replace",
|
|
5015
|
+
path: located.paths[0],
|
|
5016
|
+
oldValue: before,
|
|
5017
|
+
newValue: target
|
|
5018
|
+
};
|
|
5019
|
+
if (event !== undefined)
|
|
5020
|
+
copyPayloadAfter(event, located, target, after);
|
|
5021
|
+
writeReorder(target, reorder);
|
|
5022
|
+
relinkReorder(node, target, before, prop === "fill" ? [args[0]] : undefined);
|
|
5023
|
+
if (event !== undefined)
|
|
5024
|
+
dispatch(located, event);
|
|
5025
|
+
trigger(target, Symbol.iterator);
|
|
5026
|
+
evictRemoved(before);
|
|
5027
|
+
return proxy;
|
|
5028
|
+
};
|
|
5029
|
+
return methodCache[prop];
|
|
5030
|
+
}
|
|
5031
|
+
case "push":
|
|
5032
|
+
track(target, "length");
|
|
5033
|
+
methodCache[prop] = function(...items) {
|
|
5034
|
+
unwrapItems(items);
|
|
5035
|
+
const oldLength = target.length;
|
|
5036
|
+
const located = items.length > 0 ? locate(node) : undefined;
|
|
5037
|
+
const event = located && {
|
|
5038
|
+
action: "array-push",
|
|
5039
|
+
path: located.paths[0],
|
|
5040
|
+
key: oldLength,
|
|
5041
|
+
items
|
|
5042
|
+
};
|
|
5043
|
+
const copied = copyPayload(event, located, target);
|
|
5044
|
+
if (copied === 0 /* Reaches */) {
|
|
5045
|
+
const after = target.slice();
|
|
5046
|
+
after.push(...items);
|
|
5047
|
+
copyPayloadReaching(event, located, target, after);
|
|
5048
|
+
}
|
|
5049
|
+
const result = target.push(...items);
|
|
5050
|
+
const newLength = target.length;
|
|
5051
|
+
if (items.length > 0) {
|
|
5052
|
+
relinkArray(node, target, oldLength, undefined, items, copied === 2 /* Fresh */);
|
|
5053
|
+
if (event !== undefined)
|
|
5054
|
+
dispatch(located, event);
|
|
5055
|
+
trigger(target, Symbol.iterator);
|
|
5056
|
+
if (oldLength !== newLength) {
|
|
5057
|
+
trigger(target, "length");
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
return result;
|
|
5061
|
+
};
|
|
5062
|
+
return methodCache[prop];
|
|
5063
|
+
case "pop":
|
|
5064
|
+
track(target, "length");
|
|
5065
|
+
methodCache[prop] = function() {
|
|
5066
|
+
if (target.length === 0)
|
|
5067
|
+
return;
|
|
5068
|
+
const oldLength = target.length;
|
|
5069
|
+
const poppedIndex = oldLength - 1;
|
|
5070
|
+
const oldValue = target[poppedIndex];
|
|
5071
|
+
const located = locate(node);
|
|
5072
|
+
const event = located && {
|
|
5073
|
+
action: "array-pop",
|
|
5074
|
+
path: located.paths[0],
|
|
5075
|
+
key: poppedIndex,
|
|
5076
|
+
oldValue
|
|
5077
|
+
};
|
|
5078
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5079
|
+
const after = target.slice();
|
|
5080
|
+
after.pop();
|
|
5081
|
+
copyPayloadReaching(event, located, target, after);
|
|
5082
|
+
}
|
|
5083
|
+
const result = target.pop();
|
|
5084
|
+
const newLength = target.length;
|
|
5085
|
+
if (isObject3(oldValue))
|
|
5086
|
+
detachPlace(oldValue, node, poppedIndex);
|
|
5087
|
+
if (event !== undefined)
|
|
5088
|
+
dispatch(located, event);
|
|
5089
|
+
if (isObject3(oldValue))
|
|
5090
|
+
evictDeep(oldValue);
|
|
5091
|
+
trigger(target, Symbol.iterator);
|
|
5092
|
+
if (oldLength !== newLength) {
|
|
5093
|
+
trigger(target, "length");
|
|
5094
|
+
}
|
|
5095
|
+
return result;
|
|
5096
|
+
};
|
|
5097
|
+
return methodCache[prop];
|
|
5098
|
+
case "shift":
|
|
5099
|
+
track(target, "length");
|
|
5100
|
+
methodCache[prop] = function() {
|
|
5101
|
+
if (target.length === 0)
|
|
5102
|
+
return;
|
|
5103
|
+
const oldLength = target.length;
|
|
5104
|
+
const oldValue = target[0];
|
|
5105
|
+
const located = locate(node);
|
|
5106
|
+
const event = located && {
|
|
5107
|
+
action: "array-shift",
|
|
5108
|
+
path: located.paths[0],
|
|
5109
|
+
key: 0,
|
|
5110
|
+
oldValue
|
|
5111
|
+
};
|
|
5112
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5113
|
+
const after = target.slice();
|
|
5114
|
+
after.shift();
|
|
5115
|
+
copyPayloadReaching(event, located, target, after);
|
|
5116
|
+
}
|
|
5117
|
+
const result = target.shift();
|
|
5118
|
+
const newLength = target.length;
|
|
5119
|
+
relinkArray(node, target, 0, [oldValue]);
|
|
5120
|
+
if (event !== undefined)
|
|
5121
|
+
dispatch(located, event);
|
|
5122
|
+
if (isObject3(oldValue))
|
|
5123
|
+
evictDeep(oldValue);
|
|
5124
|
+
trigger(target, Symbol.iterator);
|
|
5125
|
+
if (oldLength !== newLength) {
|
|
5126
|
+
trigger(target, "length");
|
|
5127
|
+
}
|
|
5128
|
+
return result;
|
|
5129
|
+
};
|
|
5130
|
+
return methodCache[prop];
|
|
5131
|
+
case "unshift":
|
|
5132
|
+
track(target, "length");
|
|
5133
|
+
methodCache[prop] = function(...items) {
|
|
5134
|
+
unwrapItems(items);
|
|
5135
|
+
const oldLength = target.length;
|
|
5136
|
+
const located = items.length > 0 ? locate(node) : undefined;
|
|
5137
|
+
const event = located && {
|
|
5138
|
+
action: "array-unshift",
|
|
5139
|
+
path: located.paths[0],
|
|
5140
|
+
key: 0,
|
|
5141
|
+
items
|
|
5142
|
+
};
|
|
5143
|
+
const copied = copyPayload(event, located, target);
|
|
5144
|
+
if (copied === 0 /* Reaches */) {
|
|
5145
|
+
const after = target.slice();
|
|
5146
|
+
after.unshift(...items);
|
|
5147
|
+
copyPayloadReaching(event, located, target, after);
|
|
5148
|
+
}
|
|
5149
|
+
const result = target.unshift(...items);
|
|
5150
|
+
const newLength = target.length;
|
|
5151
|
+
if (items.length > 0) {
|
|
5152
|
+
relinkArray(node, target, 0, undefined, items, copied === 2 /* Fresh */);
|
|
5153
|
+
if (event !== undefined)
|
|
5154
|
+
dispatch(located, event);
|
|
5155
|
+
trigger(target, Symbol.iterator);
|
|
5156
|
+
if (oldLength !== newLength) {
|
|
5157
|
+
trigger(target, "length");
|
|
5158
|
+
}
|
|
5159
|
+
}
|
|
5160
|
+
return result;
|
|
5161
|
+
};
|
|
5162
|
+
return methodCache[prop];
|
|
5163
|
+
case "splice":
|
|
5164
|
+
track(target, "length");
|
|
5165
|
+
methodCache[prop] = function(...args) {
|
|
5166
|
+
const oldLength = target.length;
|
|
5167
|
+
const actualStart = args.length === 0 ? 0 : clampIndex(toIntegerOrInfinity(args[0]), oldLength);
|
|
5168
|
+
const actualDeleteCount = args.length === 0 ? 0 : args.length === 1 ? oldLength - actualStart : Math.min(Math.max(toIntegerOrInfinity(args[1]), 0), oldLength - actualStart);
|
|
5169
|
+
const items = args.length > 2 ? args.slice(2) : [];
|
|
5170
|
+
unwrapItems(items);
|
|
5171
|
+
const changes = actualDeleteCount > 0 || items.length > 0;
|
|
5172
|
+
const located = changes ? locate(node) : undefined;
|
|
5173
|
+
const event = located && {
|
|
5174
|
+
action: "array-splice",
|
|
5175
|
+
path: located.paths[0],
|
|
5176
|
+
key: actualStart,
|
|
5177
|
+
deleteCount: actualDeleteCount,
|
|
5178
|
+
items: items.length > 0 ? items : undefined,
|
|
5179
|
+
oldValues: actualDeleteCount > 0 ? target.slice(actualStart, actualStart + actualDeleteCount) : undefined
|
|
5180
|
+
};
|
|
5181
|
+
const copied = copyPayload(event, located, target);
|
|
5182
|
+
if (copied === 0 /* Reaches */) {
|
|
5183
|
+
const after = target.slice();
|
|
5184
|
+
after.splice(actualStart, actualDeleteCount, ...items);
|
|
5185
|
+
copyPayloadReaching(event, located, target, after);
|
|
5186
|
+
}
|
|
5187
|
+
const deletedItems = target.splice(actualStart, actualDeleteCount, ...items);
|
|
5188
|
+
const newLength = target.length;
|
|
5189
|
+
if (changes) {
|
|
5190
|
+
relinkArray(node, target, actualStart, deletedItems, items, copied === 2 /* Fresh */);
|
|
5191
|
+
if (event !== undefined)
|
|
5192
|
+
dispatch(located, event);
|
|
5193
|
+
evictRemoved(deletedItems);
|
|
5194
|
+
trigger(target, Symbol.iterator);
|
|
5195
|
+
if (oldLength !== newLength) {
|
|
5196
|
+
trigger(target, "length");
|
|
5197
|
+
}
|
|
5198
|
+
}
|
|
5199
|
+
return deletedItems;
|
|
5200
|
+
};
|
|
5201
|
+
return methodCache[prop];
|
|
5202
|
+
case "find": {
|
|
5203
|
+
track(target, Symbol.iterator);
|
|
5204
|
+
if (!methodCache[prop]) {
|
|
5205
|
+
methodCache[prop] = function(predicate, thisArg) {
|
|
5206
|
+
const idx = Array.prototype.findIndex.call(target, predicate, thisArg);
|
|
5207
|
+
if (idx === -1)
|
|
5208
|
+
return;
|
|
5209
|
+
const value2 = target[idx];
|
|
5210
|
+
if (!isObject3(value2))
|
|
5211
|
+
return value2;
|
|
5212
|
+
return wrapChild(value2, node, idx);
|
|
5213
|
+
};
|
|
5214
|
+
}
|
|
5215
|
+
return methodCache[prop];
|
|
5216
|
+
}
|
|
5217
|
+
case "at": {
|
|
5218
|
+
track(target, Symbol.iterator);
|
|
5219
|
+
if (!methodCache[prop]) {
|
|
5220
|
+
methodCache[prop] = function(index2) {
|
|
5221
|
+
let idx = Number(index2);
|
|
5222
|
+
if (!Number.isInteger(idx))
|
|
5223
|
+
idx = Math.trunc(idx);
|
|
5224
|
+
if (idx < 0)
|
|
5225
|
+
idx = target.length + idx;
|
|
5226
|
+
if (idx < 0 || idx >= target.length)
|
|
5227
|
+
return;
|
|
5228
|
+
const value2 = target[idx];
|
|
5229
|
+
if (!isObject3(value2))
|
|
5230
|
+
return value2;
|
|
5231
|
+
return wrapChild(value2, node, idx);
|
|
5232
|
+
};
|
|
5233
|
+
}
|
|
5234
|
+
return methodCache[prop];
|
|
5235
|
+
}
|
|
5236
|
+
case Symbol.iterator:
|
|
5237
|
+
case "values":
|
|
5238
|
+
case "keys":
|
|
5239
|
+
case "entries":
|
|
5240
|
+
case "forEach":
|
|
5241
|
+
case "map":
|
|
5242
|
+
case "filter":
|
|
5243
|
+
case "reduce":
|
|
5244
|
+
case "reduceRight":
|
|
5245
|
+
case "findIndex":
|
|
5246
|
+
case "every":
|
|
5247
|
+
case "some":
|
|
5248
|
+
case "join":
|
|
5249
|
+
track(target, Symbol.iterator);
|
|
5250
|
+
break;
|
|
5251
|
+
case "length":
|
|
5252
|
+
track(target, "length");
|
|
5253
|
+
return Reflect.get(target, prop, receiver);
|
|
5254
|
+
}
|
|
5255
|
+
const value = Reflect.get(target, prop, receiver);
|
|
5256
|
+
const index = arrayIndex(prop);
|
|
5257
|
+
if (index >= 0) {
|
|
5258
|
+
track(target, prop);
|
|
5259
|
+
if (!isObject3(value))
|
|
5260
|
+
return value;
|
|
5261
|
+
return wrapChild(value, node, index);
|
|
5262
|
+
}
|
|
5263
|
+
const isNumericIndex = typeof prop === "string" && !isNaN(parseInt(prop, 10));
|
|
5264
|
+
if (isNumericIndex) {
|
|
5265
|
+
track(target, prop);
|
|
5266
|
+
if (!isObject3(value))
|
|
5267
|
+
return value;
|
|
5268
|
+
return wrapChild(value, node, placeKey(prop));
|
|
5269
|
+
}
|
|
5270
|
+
if (typeof value === "function") {
|
|
5271
|
+
return value.bind(target);
|
|
5272
|
+
}
|
|
5273
|
+
return value;
|
|
5274
|
+
},
|
|
5275
|
+
set(target, prop, value, receiver) {
|
|
5276
|
+
if (isObject3(value))
|
|
5277
|
+
value = unwrapForStore(value);
|
|
5278
|
+
const oldValue = target[prop];
|
|
5279
|
+
if (oldValue === value && Reflect.has(target, prop))
|
|
5280
|
+
return true;
|
|
5281
|
+
if (isObject3(oldValue) && isObject3(value) && deepEqual(oldValue, value))
|
|
5282
|
+
return true;
|
|
5283
|
+
const truncated = prop === "length" && Number(value) < target.length ? target.slice(Number(value)) : undefined;
|
|
5284
|
+
const isNumericIndex = typeof prop === "number" || arrayIndex(prop) >= 0 || typeof prop === "string" && !isNaN(parseInt(prop));
|
|
5285
|
+
const emits = isNumericIndex || prop === "length" || !writesThroughSetter(target, prop, node);
|
|
5286
|
+
const grows = prop === "length" && Number(value) > Number(oldValue);
|
|
5287
|
+
const located = emits ? grows ? locate(node) : locate(node, prop) : undefined;
|
|
5288
|
+
const event = located === undefined || grows ? undefined : { action: "set", path: located.paths[0], oldValue, newValue: value };
|
|
5289
|
+
const held = event !== undefined ? heldItems(value, oldValue) : undefined;
|
|
5290
|
+
const copied = copyPayload(event, located, target, held);
|
|
5291
|
+
if (copied === 0 /* Reaches */) {
|
|
5292
|
+
const after = target.slice();
|
|
5293
|
+
Reflect.set(after, prop, value);
|
|
5294
|
+
copyPayloadReaching(event, located, target, after);
|
|
5295
|
+
}
|
|
5296
|
+
const result = Reflect.set(target, prop, value, receiver);
|
|
5297
|
+
if (result && emits) {
|
|
5298
|
+
if (truncated !== undefined) {
|
|
5299
|
+
relinkArray(node, target, target.length, truncated);
|
|
5300
|
+
} else if (prop !== "length") {
|
|
5301
|
+
const key = placeKey(prop);
|
|
5302
|
+
if (isObject3(oldValue))
|
|
5303
|
+
detachPlace(oldValue, node, key);
|
|
5304
|
+
if (isObject3(value))
|
|
5305
|
+
attachValue(value, node, key, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5306
|
+
}
|
|
5307
|
+
if (grows) {
|
|
5308
|
+
if (located !== undefined) {
|
|
5309
|
+
const oldLength = Number(oldValue);
|
|
5310
|
+
const newLength = Number(value);
|
|
5311
|
+
const events = [];
|
|
5312
|
+
for (let i = oldLength;i < newLength; i++) {
|
|
5313
|
+
const index = String(i);
|
|
5314
|
+
for (let j = 0;j < located.paths.length; j++) {
|
|
5315
|
+
events.push({ action: "set", path: [...located.paths[j], index], newValue: undefined });
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
if (events.length > 0)
|
|
5319
|
+
deliver(located.root, events);
|
|
5320
|
+
}
|
|
5321
|
+
} else if (event !== undefined) {
|
|
5322
|
+
dispatch(located, event);
|
|
3065
5323
|
}
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
5324
|
+
if (isObject3(oldValue) && oldValue !== value) {
|
|
5325
|
+
evictDeep(oldValue);
|
|
5326
|
+
}
|
|
5327
|
+
if (truncated !== undefined)
|
|
5328
|
+
evictRemoved(truncated);
|
|
5329
|
+
trigger(target, prop);
|
|
5330
|
+
}
|
|
5331
|
+
return result;
|
|
5332
|
+
},
|
|
5333
|
+
deleteProperty(target, prop) {
|
|
5334
|
+
const oldValue = target[prop];
|
|
5335
|
+
const hadProperty = Object.prototype.hasOwnProperty.call(target, prop);
|
|
5336
|
+
const located = hadProperty ? locate(node, prop) : undefined;
|
|
5337
|
+
const event = located && { action: "delete", path: located.paths[0], oldValue };
|
|
5338
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5339
|
+
const after = target.slice();
|
|
5340
|
+
Reflect.deleteProperty(after, prop);
|
|
5341
|
+
copyPayloadReaching(event, located, target, after);
|
|
5342
|
+
}
|
|
5343
|
+
const result = Reflect.deleteProperty(target, prop);
|
|
5344
|
+
if (hadProperty && result) {
|
|
5345
|
+
if (isObject3(oldValue))
|
|
5346
|
+
detachPlace(oldValue, node, placeKey(prop));
|
|
5347
|
+
if (event !== undefined)
|
|
5348
|
+
dispatch(located, event);
|
|
5349
|
+
trigger(target, prop);
|
|
5350
|
+
if (isObject3(oldValue))
|
|
5351
|
+
evictDeep(oldValue);
|
|
5352
|
+
}
|
|
5353
|
+
return result;
|
|
3090
5354
|
}
|
|
3091
|
-
};
|
|
3092
|
-
|
|
3093
|
-
|
|
5355
|
+
});
|
|
5356
|
+
globalSeen.set(arr, proxy);
|
|
5357
|
+
wrapperCache.set(arr, proxy);
|
|
5358
|
+
proxyStats.created++;
|
|
5359
|
+
proxyStats.arrays++;
|
|
5360
|
+
return proxy;
|
|
3094
5361
|
}
|
|
3095
5362
|
|
|
3096
|
-
// src/wrap-
|
|
3097
|
-
function
|
|
3098
|
-
|
|
5363
|
+
// src/wrap-map.ts
|
|
5364
|
+
function isObject4(value) {
|
|
5365
|
+
return value !== null && typeof value === "object";
|
|
5366
|
+
}
|
|
5367
|
+
function wrapMap(map, node) {
|
|
5368
|
+
const cachedProxy = wrapperCache.get(map);
|
|
3099
5369
|
if (cachedProxy)
|
|
3100
5370
|
return cachedProxy;
|
|
3101
|
-
if (globalSeen.has(
|
|
3102
|
-
return globalSeen.get(
|
|
5371
|
+
if (globalSeen.has(map))
|
|
5372
|
+
return globalSeen.get(map);
|
|
3103
5373
|
const methodCache = {};
|
|
3104
|
-
const
|
|
5374
|
+
const watch = watchIndex(map);
|
|
5375
|
+
const proxy = new Proxy(map, {
|
|
3105
5376
|
get(target, prop, receiver) {
|
|
3106
5377
|
if (prop === "__v_raw" /* RAW */)
|
|
3107
5378
|
return target;
|
|
@@ -3114,54 +5385,95 @@ function wrapSet(set, emit, path = []) {
|
|
|
3114
5385
|
if (methodCache[prop]) {
|
|
3115
5386
|
return methodCache[prop];
|
|
3116
5387
|
}
|
|
3117
|
-
if (prop === "
|
|
3118
|
-
methodCache[prop] = function(value2) {
|
|
5388
|
+
if (prop === "set") {
|
|
5389
|
+
methodCache[prop] = function(key, value2) {
|
|
3119
5390
|
if (value2 != null && typeof value2 === "object")
|
|
3120
5391
|
value2 = unwrapForStore(value2);
|
|
3121
|
-
const existed = target.has(
|
|
5392
|
+
const existed = target.has(key);
|
|
5393
|
+
const oldValue = target.get(key);
|
|
3122
5394
|
const oldSize = target.size;
|
|
5395
|
+
if (oldValue === value2)
|
|
5396
|
+
return receiver;
|
|
5397
|
+
if (oldValue && typeof oldValue === "object" && value2 && typeof value2 === "object" && deepEqual(oldValue, value2))
|
|
5398
|
+
return receiver;
|
|
5399
|
+
const located = locate(node);
|
|
5400
|
+
const event = located && {
|
|
5401
|
+
action: "map-set",
|
|
5402
|
+
path: located.paths[0],
|
|
5403
|
+
key,
|
|
5404
|
+
oldValue,
|
|
5405
|
+
newValue: value2
|
|
5406
|
+
};
|
|
5407
|
+
const held = located && heldItems(value2, oldValue);
|
|
5408
|
+
if (event !== undefined && isObject4(key))
|
|
5409
|
+
nameKey(event, key, target, !existed);
|
|
5410
|
+
const copied = copyPayload(event, located, target, held);
|
|
5411
|
+
if (copied === 0 /* Reaches */) {
|
|
5412
|
+
copyPayloadReaching(event, located, target, shallowCopy(target).set(key, value2));
|
|
5413
|
+
}
|
|
5414
|
+
target.set(key, value2);
|
|
5415
|
+
const newSize = target.size;
|
|
5416
|
+
if (!existed && watch.indexed)
|
|
5417
|
+
indexAdded(target, key);
|
|
5418
|
+
if (isObject4(oldValue))
|
|
5419
|
+
detachPlace(oldValue, node, key);
|
|
5420
|
+
if (isObject4(value2))
|
|
5421
|
+
attachValue(value2, node, key, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5422
|
+
if (event !== undefined)
|
|
5423
|
+
dispatch(located, event);
|
|
3123
5424
|
if (!existed) {
|
|
3124
|
-
target.add(value2);
|
|
3125
|
-
const newSize = target.size;
|
|
3126
|
-
const event = {
|
|
3127
|
-
action: "set-add",
|
|
3128
|
-
path,
|
|
3129
|
-
value: value2
|
|
3130
|
-
};
|
|
3131
|
-
emit?.(event);
|
|
3132
5425
|
trigger(target, Symbol.iterator);
|
|
3133
5426
|
if (oldSize !== newSize) {
|
|
3134
5427
|
trigger(target, "size");
|
|
3135
5428
|
}
|
|
5429
|
+
} else {
|
|
5430
|
+
trigger(target, String(key));
|
|
3136
5431
|
}
|
|
5432
|
+
if (isObject4(oldValue))
|
|
5433
|
+
evictDeep(oldValue);
|
|
3137
5434
|
return receiver;
|
|
3138
5435
|
};
|
|
3139
5436
|
return methodCache[prop];
|
|
3140
5437
|
}
|
|
3141
5438
|
if (prop === "delete") {
|
|
3142
|
-
methodCache[prop] = function(
|
|
3143
|
-
const existed = target.has(
|
|
5439
|
+
methodCache[prop] = function(key) {
|
|
5440
|
+
const existed = target.has(key);
|
|
5441
|
+
if (!existed)
|
|
5442
|
+
return false;
|
|
5443
|
+
const oldValue = target.get(key);
|
|
3144
5444
|
const oldSize = target.size;
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
5445
|
+
const located = locate(node);
|
|
5446
|
+
const event = located && {
|
|
5447
|
+
action: "map-delete",
|
|
5448
|
+
path: located.paths[0],
|
|
5449
|
+
key,
|
|
5450
|
+
oldValue
|
|
5451
|
+
};
|
|
5452
|
+
if (event !== undefined && isObject4(key))
|
|
5453
|
+
nameKey(event, key, target, false);
|
|
5454
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5455
|
+
const after = shallowCopy(target);
|
|
5456
|
+
after.delete(key);
|
|
5457
|
+
copyPayloadReaching(event, located, target, after);
|
|
5458
|
+
}
|
|
5459
|
+
const result = target.delete(key);
|
|
5460
|
+
const newSize = target.size;
|
|
5461
|
+
if (result) {
|
|
5462
|
+
if (watch.indexed)
|
|
5463
|
+
indexRemoved(target, key);
|
|
5464
|
+
if (isObject4(oldValue))
|
|
5465
|
+
detachPlace(oldValue, node, key);
|
|
5466
|
+
if (event !== undefined)
|
|
5467
|
+
dispatch(located, event);
|
|
5468
|
+
trigger(target, Symbol.iterator);
|
|
5469
|
+
if (oldSize !== newSize) {
|
|
5470
|
+
trigger(target, "size");
|
|
3161
5471
|
}
|
|
3162
|
-
|
|
5472
|
+
trigger(target, String(key));
|
|
5473
|
+
if (isObject4(oldValue))
|
|
5474
|
+
evictDeep(oldValue);
|
|
3163
5475
|
}
|
|
3164
|
-
return
|
|
5476
|
+
return result;
|
|
3165
5477
|
};
|
|
3166
5478
|
return methodCache[prop];
|
|
3167
5479
|
}
|
|
@@ -3170,87 +5482,75 @@ function wrapSet(set, emit, path = []) {
|
|
|
3170
5482
|
const oldSize = target.size;
|
|
3171
5483
|
if (oldSize === 0)
|
|
3172
5484
|
return;
|
|
5485
|
+
const removed = [...target];
|
|
3173
5486
|
target.clear();
|
|
3174
5487
|
const newSize = target.size;
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
5488
|
+
if (watch.indexed)
|
|
5489
|
+
forgetReplicaIndex(target);
|
|
5490
|
+
for (const [key, value2] of removed) {
|
|
5491
|
+
if (isObject4(value2))
|
|
5492
|
+
detachPlace(value2, node, key);
|
|
5493
|
+
}
|
|
5494
|
+
const located = locate(node);
|
|
5495
|
+
if (located !== undefined) {
|
|
5496
|
+
dispatch(located, {
|
|
5497
|
+
action: "map-clear",
|
|
5498
|
+
path: located.paths[0],
|
|
5499
|
+
key: null
|
|
5500
|
+
});
|
|
5501
|
+
}
|
|
3181
5502
|
trigger(target, Symbol.iterator);
|
|
3182
5503
|
if (oldSize !== newSize) {
|
|
3183
5504
|
trigger(target, "size");
|
|
3184
5505
|
}
|
|
5506
|
+
for (const [, value2] of removed) {
|
|
5507
|
+
if (isObject4(value2))
|
|
5508
|
+
evictDeep(value2);
|
|
5509
|
+
}
|
|
5510
|
+
};
|
|
5511
|
+
return methodCache[prop];
|
|
5512
|
+
}
|
|
5513
|
+
if (prop === "get") {
|
|
5514
|
+
methodCache[prop] = function(key) {
|
|
5515
|
+
track(target, String(key));
|
|
5516
|
+
const value2 = target.get(key);
|
|
5517
|
+
if (!value2 || typeof value2 !== "object")
|
|
5518
|
+
return value2;
|
|
5519
|
+
return wrapChild(value2, node, key);
|
|
3185
5520
|
};
|
|
3186
5521
|
return methodCache[prop];
|
|
3187
5522
|
}
|
|
3188
5523
|
if (prop === "has") {
|
|
3189
5524
|
track(target, Symbol.iterator);
|
|
3190
|
-
methodCache[prop] = function(
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
}
|
|
3194
|
-
return target.has(value2);
|
|
5525
|
+
methodCache[prop] = function(key) {
|
|
5526
|
+
track(target, String(key));
|
|
5527
|
+
return target.has(key);
|
|
3195
5528
|
}.bind(target);
|
|
3196
5529
|
return methodCache[prop];
|
|
3197
5530
|
}
|
|
3198
|
-
if (prop ===
|
|
5531
|
+
if (prop === Symbol.iterator || prop === "entries" || prop === "values" || prop === "keys" || prop === "forEach") {
|
|
3199
5532
|
track(target, Symbol.iterator);
|
|
3200
|
-
const originalMethod = Reflect.get(target, prop, receiver);
|
|
3201
5533
|
if (prop === "forEach") {
|
|
3202
5534
|
methodCache[prop] = (callbackfn, thisArg) => {
|
|
3203
|
-
const
|
|
3204
|
-
for (const value2 of
|
|
3205
|
-
callbackfn.call(thisArg, value2,
|
|
5535
|
+
const entriesIterator = proxy.entries();
|
|
5536
|
+
for (const [key, value2] of entriesIterator) {
|
|
5537
|
+
callbackfn.call(thisArg, value2, key, proxy);
|
|
3206
5538
|
}
|
|
3207
5539
|
};
|
|
3208
5540
|
return methodCache[prop];
|
|
3209
5541
|
}
|
|
3210
|
-
methodCache[prop] = function* (
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
if (prop === "entries") {
|
|
3216
|
-
valueToWrap = entry[1];
|
|
3217
|
-
}
|
|
3218
|
-
track(target, String(index));
|
|
3219
|
-
let wrappedValue = valueToWrap;
|
|
3220
|
-
if (valueToWrap && typeof valueToWrap === "object") {
|
|
3221
|
-
if (globalSeen.has(valueToWrap)) {
|
|
3222
|
-
wrappedValue = globalSeen.get(valueToWrap);
|
|
3223
|
-
} else {
|
|
3224
|
-
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
3225
|
-
if (cachedValueProxy) {
|
|
3226
|
-
wrappedValue = cachedValueProxy;
|
|
3227
|
-
} else {
|
|
3228
|
-
const keyForPath = String(index);
|
|
3229
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyForPath}` : keyForPath;
|
|
3230
|
-
let newPath = getPathConcat(pathKey);
|
|
3231
|
-
if (newPath === undefined) {
|
|
3232
|
-
newPath = path.concat(keyForPath);
|
|
3233
|
-
setPathConcat(pathKey, newPath);
|
|
3234
|
-
}
|
|
3235
|
-
if (valueToWrap instanceof Map)
|
|
3236
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
3237
|
-
else if (valueToWrap instanceof Set)
|
|
3238
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
3239
|
-
else if (Array.isArray(valueToWrap))
|
|
3240
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
3241
|
-
else if (valueToWrap instanceof Date)
|
|
3242
|
-
wrappedValue = new Date(valueToWrap.getTime());
|
|
3243
|
-
else
|
|
3244
|
-
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
3245
|
-
}
|
|
3246
|
-
}
|
|
5542
|
+
methodCache[prop] = function* () {
|
|
5543
|
+
for (const [key, value2] of target.entries()) {
|
|
5544
|
+
if (prop === "keys") {
|
|
5545
|
+
yield key;
|
|
5546
|
+
continue;
|
|
3247
5547
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
} else {
|
|
5548
|
+
const wrappedValue = isObject4(value2) ? wrapChild(value2, node, key) : value2;
|
|
5549
|
+
if (prop === "values") {
|
|
3251
5550
|
yield wrappedValue;
|
|
5551
|
+
continue;
|
|
3252
5552
|
}
|
|
3253
|
-
|
|
5553
|
+
yield [isObject4(key) ? wrapUnplaced(key) : key, wrappedValue];
|
|
3254
5554
|
}
|
|
3255
5555
|
};
|
|
3256
5556
|
return methodCache[prop];
|
|
@@ -3260,7 +5560,7 @@ function wrapSet(set, emit, path = []) {
|
|
|
3260
5560
|
return target.size;
|
|
3261
5561
|
}
|
|
3262
5562
|
if (prop === "constructor") {
|
|
3263
|
-
return
|
|
5563
|
+
return Map;
|
|
3264
5564
|
}
|
|
3265
5565
|
const value = Reflect.get(target, prop, receiver);
|
|
3266
5566
|
if (typeof value === "function") {
|
|
@@ -3269,22 +5569,26 @@ function wrapSet(set, emit, path = []) {
|
|
|
3269
5569
|
return value;
|
|
3270
5570
|
}
|
|
3271
5571
|
});
|
|
3272
|
-
globalSeen.set(
|
|
3273
|
-
wrapperCache.set(
|
|
5572
|
+
globalSeen.set(map, proxy);
|
|
5573
|
+
wrapperCache.set(map, proxy);
|
|
3274
5574
|
proxyStats.created++;
|
|
3275
|
-
proxyStats.
|
|
5575
|
+
proxyStats.maps++;
|
|
3276
5576
|
return proxy;
|
|
3277
5577
|
}
|
|
3278
5578
|
|
|
3279
|
-
// src/wrap-
|
|
3280
|
-
function
|
|
3281
|
-
|
|
5579
|
+
// src/wrap-set.ts
|
|
5580
|
+
function isObject5(value) {
|
|
5581
|
+
return value !== null && typeof value === "object";
|
|
5582
|
+
}
|
|
5583
|
+
function wrapSet(set, node) {
|
|
5584
|
+
const cachedProxy = wrapperCache.get(set);
|
|
3282
5585
|
if (cachedProxy)
|
|
3283
5586
|
return cachedProxy;
|
|
3284
|
-
if (globalSeen.has(
|
|
3285
|
-
return globalSeen.get(
|
|
5587
|
+
if (globalSeen.has(set))
|
|
5588
|
+
return globalSeen.get(set);
|
|
3286
5589
|
const methodCache = {};
|
|
3287
|
-
const
|
|
5590
|
+
const watch = watchIndex(set);
|
|
5591
|
+
const proxy = new Proxy(set, {
|
|
3288
5592
|
get(target, prop, receiver) {
|
|
3289
5593
|
if (prop === "__v_raw" /* RAW */)
|
|
3290
5594
|
return target;
|
|
@@ -3297,75 +5601,77 @@ function wrapMap(map, emit, path = []) {
|
|
|
3297
5601
|
if (methodCache[prop]) {
|
|
3298
5602
|
return methodCache[prop];
|
|
3299
5603
|
}
|
|
3300
|
-
if (prop === "
|
|
3301
|
-
methodCache[prop] = function(
|
|
5604
|
+
if (prop === "add") {
|
|
5605
|
+
methodCache[prop] = function(value2) {
|
|
3302
5606
|
if (value2 != null && typeof value2 === "object")
|
|
3303
5607
|
value2 = unwrapForStore(value2);
|
|
3304
|
-
const existed = target.has(
|
|
3305
|
-
const oldValue = target.get(key);
|
|
5608
|
+
const existed = target.has(value2);
|
|
3306
5609
|
const oldSize = target.size;
|
|
3307
|
-
if (oldValue === value2)
|
|
3308
|
-
return receiver;
|
|
3309
|
-
if (oldValue && typeof oldValue === "object" && value2 && typeof value2 === "object" && deepEqual(oldValue, value2, new WeakMap))
|
|
3310
|
-
return receiver;
|
|
3311
|
-
target.set(key, value2);
|
|
3312
|
-
const newSize = target.size;
|
|
3313
|
-
const pathKey = path.join(".");
|
|
3314
|
-
let cachedPath = getPathConcat(pathKey);
|
|
3315
|
-
if (cachedPath === undefined) {
|
|
3316
|
-
cachedPath = path;
|
|
3317
|
-
setPathConcat(pathKey, cachedPath);
|
|
3318
|
-
}
|
|
3319
|
-
const event = {
|
|
3320
|
-
action: "map-set",
|
|
3321
|
-
path: cachedPath,
|
|
3322
|
-
key,
|
|
3323
|
-
oldValue,
|
|
3324
|
-
newValue: value2 !== null && typeof value2 === "object" ? deepClone(value2) : value2
|
|
3325
|
-
};
|
|
3326
|
-
emit?.(event);
|
|
3327
5610
|
if (!existed) {
|
|
5611
|
+
const located = locate(node);
|
|
5612
|
+
const event = located && {
|
|
5613
|
+
action: "set-add",
|
|
5614
|
+
path: located.paths[0],
|
|
5615
|
+
value: value2
|
|
5616
|
+
};
|
|
5617
|
+
const copied = copyPayload(event, located, target);
|
|
5618
|
+
if (copied === 0 /* Reaches */) {
|
|
5619
|
+
copyPayloadReaching(event, located, target, shallowCopy(target).add(value2));
|
|
5620
|
+
}
|
|
5621
|
+
target.add(value2);
|
|
5622
|
+
const newSize = target.size;
|
|
5623
|
+
if (watch.indexed)
|
|
5624
|
+
indexAdded(target, value2);
|
|
5625
|
+
if (isObject5(value2))
|
|
5626
|
+
attachValue(value2, node, undefined, copied === 2 /* Fresh */);
|
|
5627
|
+
if (event !== undefined)
|
|
5628
|
+
dispatch(located, event);
|
|
3328
5629
|
trigger(target, Symbol.iterator);
|
|
3329
5630
|
if (oldSize !== newSize) {
|
|
3330
5631
|
trigger(target, "size");
|
|
3331
5632
|
}
|
|
3332
|
-
} else {
|
|
3333
|
-
trigger(target, String(key));
|
|
3334
5633
|
}
|
|
3335
5634
|
return receiver;
|
|
3336
5635
|
};
|
|
3337
5636
|
return methodCache[prop];
|
|
3338
5637
|
}
|
|
3339
5638
|
if (prop === "delete") {
|
|
3340
|
-
methodCache[prop] = function(
|
|
3341
|
-
const existed = target.has(
|
|
3342
|
-
if (!existed)
|
|
3343
|
-
return false;
|
|
3344
|
-
const oldValue = target.get(key);
|
|
5639
|
+
methodCache[prop] = function(value2) {
|
|
5640
|
+
const existed = target.has(value2);
|
|
3345
5641
|
const oldSize = target.size;
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
const
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
setPathConcat(pathKey, cachedPath);
|
|
3354
|
-
}
|
|
3355
|
-
const event = {
|
|
3356
|
-
action: "map-delete",
|
|
3357
|
-
path: cachedPath,
|
|
3358
|
-
key,
|
|
5642
|
+
if (existed) {
|
|
5643
|
+
const oldValue = value2;
|
|
5644
|
+
const located = locate(node);
|
|
5645
|
+
const event = located && {
|
|
5646
|
+
action: "set-delete",
|
|
5647
|
+
path: located.paths[0],
|
|
5648
|
+
value: value2,
|
|
3359
5649
|
oldValue
|
|
3360
5650
|
};
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
5651
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5652
|
+
const after = shallowCopy(target);
|
|
5653
|
+
after.delete(value2);
|
|
5654
|
+
copyPayloadReaching(event, located, target, after);
|
|
3365
5655
|
}
|
|
3366
|
-
|
|
5656
|
+
const result = target.delete(value2);
|
|
5657
|
+
const newSize = target.size;
|
|
5658
|
+
if (result) {
|
|
5659
|
+
if (watch.indexed)
|
|
5660
|
+
indexRemoved(target, value2);
|
|
5661
|
+
if (isObject5(value2))
|
|
5662
|
+
detachPlace(value2, node, undefined);
|
|
5663
|
+
if (event !== undefined)
|
|
5664
|
+
dispatch(located, event);
|
|
5665
|
+
trigger(target, Symbol.iterator);
|
|
5666
|
+
if (oldSize !== newSize) {
|
|
5667
|
+
trigger(target, "size");
|
|
5668
|
+
}
|
|
5669
|
+
if (isObject5(value2))
|
|
5670
|
+
evictDeep(value2);
|
|
5671
|
+
}
|
|
5672
|
+
return result;
|
|
3367
5673
|
}
|
|
3368
|
-
return
|
|
5674
|
+
return false;
|
|
3369
5675
|
};
|
|
3370
5676
|
return methodCache[prop];
|
|
3371
5677
|
}
|
|
@@ -3374,132 +5680,72 @@ function wrapMap(map, emit, path = []) {
|
|
|
3374
5680
|
const oldSize = target.size;
|
|
3375
5681
|
if (oldSize === 0)
|
|
3376
5682
|
return;
|
|
5683
|
+
const removed = [...target];
|
|
3377
5684
|
target.clear();
|
|
3378
5685
|
const newSize = target.size;
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3384
|
-
|
|
5686
|
+
if (watch.indexed)
|
|
5687
|
+
forgetReplicaIndex(target);
|
|
5688
|
+
for (const member of removed) {
|
|
5689
|
+
if (isObject5(member))
|
|
5690
|
+
detachPlace(member, node, undefined);
|
|
5691
|
+
}
|
|
5692
|
+
const located = locate(node);
|
|
5693
|
+
if (located !== undefined) {
|
|
5694
|
+
dispatch(located, {
|
|
5695
|
+
action: "set-clear",
|
|
5696
|
+
path: located.paths[0],
|
|
5697
|
+
value: null
|
|
5698
|
+
});
|
|
5699
|
+
}
|
|
3385
5700
|
trigger(target, Symbol.iterator);
|
|
3386
5701
|
if (oldSize !== newSize) {
|
|
3387
5702
|
trigger(target, "size");
|
|
3388
5703
|
}
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
if (prop === "get") {
|
|
3393
|
-
methodCache[prop] = function(key) {
|
|
3394
|
-
track(target, String(key));
|
|
3395
|
-
const value2 = target.get(key);
|
|
3396
|
-
if (!value2 || typeof value2 !== "object")
|
|
3397
|
-
return value2;
|
|
3398
|
-
if (globalSeen.has(value2))
|
|
3399
|
-
return globalSeen.get(value2);
|
|
3400
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3401
|
-
if (cachedValueProxy)
|
|
3402
|
-
return cachedValueProxy;
|
|
3403
|
-
const keyString = String(key);
|
|
3404
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyString}` : keyString;
|
|
3405
|
-
let newPath = getPathConcat(pathKey);
|
|
3406
|
-
if (newPath === undefined) {
|
|
3407
|
-
newPath = path.concat(keyString);
|
|
3408
|
-
setPathConcat(pathKey, newPath);
|
|
5704
|
+
for (const member of removed) {
|
|
5705
|
+
if (isObject5(member))
|
|
5706
|
+
evictDeep(member);
|
|
3409
5707
|
}
|
|
3410
|
-
if (value2 instanceof Map)
|
|
3411
|
-
return wrapMap(value2, emit, newPath);
|
|
3412
|
-
if (value2 instanceof Set)
|
|
3413
|
-
return wrapSet(value2, emit, newPath);
|
|
3414
|
-
if (Array.isArray(value2))
|
|
3415
|
-
return wrapArray(value2, emit, newPath);
|
|
3416
|
-
if (value2 instanceof Date)
|
|
3417
|
-
return new Date(value2.getTime());
|
|
3418
|
-
return reactive(value2, emit, newPath);
|
|
3419
5708
|
};
|
|
3420
5709
|
return methodCache[prop];
|
|
3421
5710
|
}
|
|
3422
5711
|
if (prop === "has") {
|
|
3423
5712
|
track(target, Symbol.iterator);
|
|
3424
|
-
methodCache[prop] = function(
|
|
3425
|
-
|
|
3426
|
-
|
|
5713
|
+
methodCache[prop] = function(value2) {
|
|
5714
|
+
if (typeof value2 === "string" || typeof value2 === "number" || typeof value2 === "symbol") {
|
|
5715
|
+
track(target, String(value2));
|
|
5716
|
+
}
|
|
5717
|
+
return target.has(value2);
|
|
3427
5718
|
}.bind(target);
|
|
3428
5719
|
return methodCache[prop];
|
|
3429
5720
|
}
|
|
3430
|
-
if (prop ===
|
|
5721
|
+
if (prop === "values" || prop === Symbol.iterator || prop === "entries" || prop === "keys" || prop === "forEach") {
|
|
3431
5722
|
track(target, Symbol.iterator);
|
|
3432
5723
|
const originalMethod = Reflect.get(target, prop, receiver);
|
|
3433
5724
|
if (prop === "forEach") {
|
|
3434
5725
|
methodCache[prop] = (callbackfn, thisArg) => {
|
|
3435
|
-
const
|
|
3436
|
-
for (const
|
|
3437
|
-
callbackfn.call(thisArg, value2,
|
|
5726
|
+
const valuesIterator = proxy.values();
|
|
5727
|
+
for (const value2 of valuesIterator) {
|
|
5728
|
+
callbackfn.call(thisArg, value2, value2, proxy);
|
|
3438
5729
|
}
|
|
3439
5730
|
};
|
|
3440
5731
|
return methodCache[prop];
|
|
3441
5732
|
}
|
|
3442
5733
|
methodCache[prop] = function* (...args) {
|
|
5734
|
+
let index = 0;
|
|
3443
5735
|
const iterator = originalMethod.apply(target, args);
|
|
3444
5736
|
for (const entry of iterator) {
|
|
3445
|
-
let keyToWrap = entry;
|
|
3446
5737
|
let valueToWrap = entry;
|
|
3447
|
-
|
|
3448
|
-
if (prop === "entries" || prop === Symbol.iterator) {
|
|
3449
|
-
keyToWrap = entry[0];
|
|
5738
|
+
if (prop === "entries") {
|
|
3450
5739
|
valueToWrap = entry[1];
|
|
3451
|
-
isEntry = true;
|
|
3452
|
-
}
|
|
3453
|
-
let wrappedKey = keyToWrap;
|
|
3454
|
-
if (isEntry && keyToWrap && typeof keyToWrap === "object") {
|
|
3455
|
-
if (globalSeen.has(keyToWrap)) {
|
|
3456
|
-
wrappedKey = globalSeen.get(keyToWrap);
|
|
3457
|
-
} else {
|
|
3458
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${String(keyToWrap)}` : String(keyToWrap);
|
|
3459
|
-
let keyPath = getPathConcat(pathKey);
|
|
3460
|
-
if (keyPath === undefined) {
|
|
3461
|
-
keyPath = path.concat(String(keyToWrap));
|
|
3462
|
-
setPathConcat(pathKey, keyPath);
|
|
3463
|
-
}
|
|
3464
|
-
wrappedKey = reactive(keyToWrap, emit, keyPath);
|
|
3465
|
-
}
|
|
3466
|
-
}
|
|
3467
|
-
let wrappedValue = valueToWrap;
|
|
3468
|
-
if (valueToWrap && typeof valueToWrap === "object") {
|
|
3469
|
-
if (globalSeen.has(valueToWrap)) {
|
|
3470
|
-
wrappedValue = globalSeen.get(valueToWrap);
|
|
3471
|
-
} else {
|
|
3472
|
-
const cachedValueProxy = wrapperCache.get(valueToWrap);
|
|
3473
|
-
if (cachedValueProxy) {
|
|
3474
|
-
wrappedValue = cachedValueProxy;
|
|
3475
|
-
} else {
|
|
3476
|
-
const keyString = String(keyToWrap);
|
|
3477
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${keyString}` : keyString;
|
|
3478
|
-
let newPath = getPathConcat(pathKey);
|
|
3479
|
-
if (newPath === undefined) {
|
|
3480
|
-
newPath = path.concat(keyString);
|
|
3481
|
-
setPathConcat(pathKey, newPath);
|
|
3482
|
-
}
|
|
3483
|
-
if (valueToWrap instanceof Map)
|
|
3484
|
-
wrappedValue = wrapMap(valueToWrap, emit, newPath);
|
|
3485
|
-
else if (valueToWrap instanceof Set)
|
|
3486
|
-
wrappedValue = wrapSet(valueToWrap, emit, newPath);
|
|
3487
|
-
else if (Array.isArray(valueToWrap))
|
|
3488
|
-
wrappedValue = wrapArray(valueToWrap, emit, newPath);
|
|
3489
|
-
else if (valueToWrap instanceof Date)
|
|
3490
|
-
wrappedValue = new Date(valueToWrap.getTime());
|
|
3491
|
-
else
|
|
3492
|
-
wrappedValue = reactive(valueToWrap, emit, newPath);
|
|
3493
|
-
}
|
|
3494
|
-
}
|
|
3495
5740
|
}
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
yield wrappedValue;
|
|
5741
|
+
track(target, String(index));
|
|
5742
|
+
const wrappedValue = isObject5(valueToWrap) ? wrapChild(valueToWrap, node, undefined) : valueToWrap;
|
|
5743
|
+
if (prop === "entries") {
|
|
5744
|
+
yield [wrappedValue, wrappedValue];
|
|
3500
5745
|
} else {
|
|
3501
|
-
yield
|
|
5746
|
+
yield wrappedValue;
|
|
3502
5747
|
}
|
|
5748
|
+
index++;
|
|
3503
5749
|
}
|
|
3504
5750
|
};
|
|
3505
5751
|
return methodCache[prop];
|
|
@@ -3509,350 +5755,24 @@ function wrapMap(map, emit, path = []) {
|
|
|
3509
5755
|
return target.size;
|
|
3510
5756
|
}
|
|
3511
5757
|
if (prop === "constructor") {
|
|
3512
|
-
return
|
|
3513
|
-
}
|
|
3514
|
-
const value = Reflect.get(target, prop, receiver);
|
|
3515
|
-
if (typeof value === "function") {
|
|
3516
|
-
return value.bind(target);
|
|
3517
|
-
}
|
|
3518
|
-
return value;
|
|
3519
|
-
}
|
|
3520
|
-
});
|
|
3521
|
-
globalSeen.set(map, proxy);
|
|
3522
|
-
wrapperCache.set(map, proxy);
|
|
3523
|
-
proxyStats.created++;
|
|
3524
|
-
proxyStats.maps++;
|
|
3525
|
-
return proxy;
|
|
3526
|
-
}
|
|
3527
|
-
|
|
3528
|
-
// src/wrap-array.ts
|
|
3529
|
-
function isObject2(v) {
|
|
3530
|
-
return v && typeof v === "object";
|
|
3531
|
-
}
|
|
3532
|
-
function wrapArray(arr, emit, path = []) {
|
|
3533
|
-
const cachedProxy = wrapperCache.get(arr);
|
|
3534
|
-
if (cachedProxy)
|
|
3535
|
-
return cachedProxy;
|
|
3536
|
-
if (globalSeen.has(arr))
|
|
3537
|
-
return globalSeen.get(arr);
|
|
3538
|
-
const methodCache = {};
|
|
3539
|
-
const proxy = new Proxy(arr, {
|
|
3540
|
-
get(target, prop, receiver) {
|
|
3541
|
-
if (prop === "__v_raw" /* RAW */)
|
|
3542
|
-
return target;
|
|
3543
|
-
if (prop === "__v_isReactive" /* IS_REACTIVE */)
|
|
3544
|
-
return true;
|
|
3545
|
-
track(target, prop);
|
|
3546
|
-
if (methodCache[prop]) {
|
|
3547
|
-
return methodCache[prop];
|
|
3548
|
-
}
|
|
3549
|
-
switch (prop) {
|
|
3550
|
-
case "push":
|
|
3551
|
-
track(target, "length");
|
|
3552
|
-
methodCache[prop] = function(...items) {
|
|
3553
|
-
const oldLength = target.length;
|
|
3554
|
-
const result = target.push(...items);
|
|
3555
|
-
const newLength = target.length;
|
|
3556
|
-
if (items.length > 0) {
|
|
3557
|
-
const event = {
|
|
3558
|
-
action: "array-push",
|
|
3559
|
-
path,
|
|
3560
|
-
key: oldLength,
|
|
3561
|
-
items
|
|
3562
|
-
};
|
|
3563
|
-
emit?.(event);
|
|
3564
|
-
trigger(target, Symbol.iterator);
|
|
3565
|
-
if (oldLength !== newLength) {
|
|
3566
|
-
trigger(target, "length");
|
|
3567
|
-
}
|
|
3568
|
-
}
|
|
3569
|
-
return result;
|
|
3570
|
-
};
|
|
3571
|
-
return methodCache[prop];
|
|
3572
|
-
case "pop":
|
|
3573
|
-
track(target, "length");
|
|
3574
|
-
methodCache[prop] = function() {
|
|
3575
|
-
if (target.length === 0)
|
|
3576
|
-
return;
|
|
3577
|
-
const oldLength = target.length;
|
|
3578
|
-
const poppedIndex = oldLength - 1;
|
|
3579
|
-
const oldValue = target[poppedIndex];
|
|
3580
|
-
const result = target.pop();
|
|
3581
|
-
const newLength = target.length;
|
|
3582
|
-
const event = {
|
|
3583
|
-
action: "array-pop",
|
|
3584
|
-
path,
|
|
3585
|
-
key: poppedIndex,
|
|
3586
|
-
oldValue
|
|
3587
|
-
};
|
|
3588
|
-
emit?.(event);
|
|
3589
|
-
if (isObject2(oldValue))
|
|
3590
|
-
evictDeep(oldValue);
|
|
3591
|
-
trigger(target, Symbol.iterator);
|
|
3592
|
-
if (oldLength !== newLength) {
|
|
3593
|
-
trigger(target, "length");
|
|
3594
|
-
}
|
|
3595
|
-
return result;
|
|
3596
|
-
};
|
|
3597
|
-
return methodCache[prop];
|
|
3598
|
-
case "shift":
|
|
3599
|
-
track(target, "length");
|
|
3600
|
-
methodCache[prop] = function() {
|
|
3601
|
-
if (target.length === 0)
|
|
3602
|
-
return;
|
|
3603
|
-
const oldLength = target.length;
|
|
3604
|
-
const oldValue = target[0];
|
|
3605
|
-
const result = target.shift();
|
|
3606
|
-
const newLength = target.length;
|
|
3607
|
-
const event = {
|
|
3608
|
-
action: "array-shift",
|
|
3609
|
-
path,
|
|
3610
|
-
key: 0,
|
|
3611
|
-
oldValue
|
|
3612
|
-
};
|
|
3613
|
-
emit?.(event);
|
|
3614
|
-
if (isObject2(oldValue))
|
|
3615
|
-
evictDeep(oldValue);
|
|
3616
|
-
trigger(target, Symbol.iterator);
|
|
3617
|
-
if (oldLength !== newLength) {
|
|
3618
|
-
trigger(target, "length");
|
|
3619
|
-
}
|
|
3620
|
-
return result;
|
|
3621
|
-
};
|
|
3622
|
-
return methodCache[prop];
|
|
3623
|
-
case "unshift":
|
|
3624
|
-
track(target, "length");
|
|
3625
|
-
methodCache[prop] = function(...items) {
|
|
3626
|
-
const oldLength = target.length;
|
|
3627
|
-
const result = target.unshift(...items);
|
|
3628
|
-
const newLength = target.length;
|
|
3629
|
-
if (items.length > 0) {
|
|
3630
|
-
const event = {
|
|
3631
|
-
action: "array-unshift",
|
|
3632
|
-
path,
|
|
3633
|
-
key: 0,
|
|
3634
|
-
items
|
|
3635
|
-
};
|
|
3636
|
-
emit?.(event);
|
|
3637
|
-
trigger(target, Symbol.iterator);
|
|
3638
|
-
if (oldLength !== newLength) {
|
|
3639
|
-
trigger(target, "length");
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
return result;
|
|
3643
|
-
};
|
|
3644
|
-
return methodCache[prop];
|
|
3645
|
-
case "splice":
|
|
3646
|
-
track(target, "length");
|
|
3647
|
-
methodCache[prop] = function(start, deleteCount, ...items) {
|
|
3648
|
-
const oldLength = target.length;
|
|
3649
|
-
const actualStart = start < 0 ? Math.max(target.length + start, 0) : Math.min(start, target.length);
|
|
3650
|
-
const deleteCountNum = deleteCount === undefined ? target.length - actualStart : Number(deleteCount);
|
|
3651
|
-
const actualDeleteCount = Math.min(deleteCountNum, target.length - actualStart);
|
|
3652
|
-
const deletedItems = target.slice(actualStart, actualStart + actualDeleteCount);
|
|
3653
|
-
const result = target.splice(start, deleteCountNum, ...items);
|
|
3654
|
-
const newLength = target.length;
|
|
3655
|
-
if (actualDeleteCount > 0 || items.length > 0) {
|
|
3656
|
-
const event = {
|
|
3657
|
-
action: "array-splice",
|
|
3658
|
-
path,
|
|
3659
|
-
key: actualStart,
|
|
3660
|
-
deleteCount: actualDeleteCount,
|
|
3661
|
-
items: items.length > 0 ? items : undefined,
|
|
3662
|
-
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3663
|
-
};
|
|
3664
|
-
emit?.(event);
|
|
3665
|
-
for (let i = 0;i < deletedItems.length; i++) {
|
|
3666
|
-
if (isObject2(deletedItems[i]))
|
|
3667
|
-
evictDeep(deletedItems[i]);
|
|
3668
|
-
}
|
|
3669
|
-
trigger(target, Symbol.iterator);
|
|
3670
|
-
if (oldLength !== newLength) {
|
|
3671
|
-
trigger(target, "length");
|
|
3672
|
-
}
|
|
3673
|
-
}
|
|
3674
|
-
return result;
|
|
3675
|
-
};
|
|
3676
|
-
return methodCache[prop];
|
|
3677
|
-
case "find": {
|
|
3678
|
-
track(target, Symbol.iterator);
|
|
3679
|
-
if (!methodCache[prop]) {
|
|
3680
|
-
methodCache[prop] = function(predicate, thisArg) {
|
|
3681
|
-
const idx = Array.prototype.findIndex.call(target, predicate, thisArg);
|
|
3682
|
-
if (idx === -1)
|
|
3683
|
-
return;
|
|
3684
|
-
const value2 = target[idx];
|
|
3685
|
-
if (!isObject2(value2))
|
|
3686
|
-
return value2;
|
|
3687
|
-
const propKey = String(idx);
|
|
3688
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3689
|
-
let newPath = getPathConcat(pathKey);
|
|
3690
|
-
if (newPath === undefined) {
|
|
3691
|
-
newPath = path.concat(propKey);
|
|
3692
|
-
setPathConcat(pathKey, newPath);
|
|
3693
|
-
}
|
|
3694
|
-
if (globalSeen.has(value2))
|
|
3695
|
-
return globalSeen.get(value2);
|
|
3696
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3697
|
-
if (cachedValueProxy)
|
|
3698
|
-
return cachedValueProxy;
|
|
3699
|
-
if (Array.isArray(value2))
|
|
3700
|
-
return wrapArray(value2, emit, newPath);
|
|
3701
|
-
if (value2 instanceof Map)
|
|
3702
|
-
return wrapMap(value2, emit, newPath);
|
|
3703
|
-
if (value2 instanceof Set)
|
|
3704
|
-
return wrapSet(value2, emit, newPath);
|
|
3705
|
-
if (value2 instanceof Date)
|
|
3706
|
-
return new Date(value2.getTime());
|
|
3707
|
-
return reactive(value2, emit, newPath);
|
|
3708
|
-
};
|
|
3709
|
-
}
|
|
3710
|
-
return methodCache[prop];
|
|
3711
|
-
}
|
|
3712
|
-
case "at": {
|
|
3713
|
-
track(target, Symbol.iterator);
|
|
3714
|
-
if (!methodCache[prop]) {
|
|
3715
|
-
methodCache[prop] = function(index) {
|
|
3716
|
-
let idx = Number(index);
|
|
3717
|
-
if (!Number.isInteger(idx))
|
|
3718
|
-
idx = Math.trunc(idx);
|
|
3719
|
-
if (idx < 0)
|
|
3720
|
-
idx = target.length + idx;
|
|
3721
|
-
if (idx < 0 || idx >= target.length)
|
|
3722
|
-
return;
|
|
3723
|
-
const value2 = target[idx];
|
|
3724
|
-
if (!isObject2(value2))
|
|
3725
|
-
return value2;
|
|
3726
|
-
const propKey = String(idx);
|
|
3727
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3728
|
-
let newPath = getPathConcat(pathKey);
|
|
3729
|
-
if (newPath === undefined) {
|
|
3730
|
-
newPath = path.concat(propKey);
|
|
3731
|
-
setPathConcat(pathKey, newPath);
|
|
3732
|
-
}
|
|
3733
|
-
if (globalSeen.has(value2))
|
|
3734
|
-
return globalSeen.get(value2);
|
|
3735
|
-
const cachedValueProxy = wrapperCache.get(value2);
|
|
3736
|
-
if (cachedValueProxy)
|
|
3737
|
-
return cachedValueProxy;
|
|
3738
|
-
if (Array.isArray(value2))
|
|
3739
|
-
return wrapArray(value2, emit, newPath);
|
|
3740
|
-
if (value2 instanceof Map)
|
|
3741
|
-
return wrapMap(value2, emit, newPath);
|
|
3742
|
-
if (value2 instanceof Set)
|
|
3743
|
-
return wrapSet(value2, emit, newPath);
|
|
3744
|
-
if (value2 instanceof Date)
|
|
3745
|
-
return new Date(value2.getTime());
|
|
3746
|
-
return reactive(value2, emit, newPath);
|
|
3747
|
-
};
|
|
3748
|
-
}
|
|
3749
|
-
return methodCache[prop];
|
|
3750
|
-
}
|
|
3751
|
-
case Symbol.iterator:
|
|
3752
|
-
case "values":
|
|
3753
|
-
case "keys":
|
|
3754
|
-
case "entries":
|
|
3755
|
-
case "forEach":
|
|
3756
|
-
case "map":
|
|
3757
|
-
case "filter":
|
|
3758
|
-
case "reduce":
|
|
3759
|
-
case "reduceRight":
|
|
3760
|
-
case "findIndex":
|
|
3761
|
-
case "every":
|
|
3762
|
-
case "some":
|
|
3763
|
-
case "join":
|
|
3764
|
-
track(target, Symbol.iterator);
|
|
3765
|
-
break;
|
|
3766
|
-
case "length":
|
|
3767
|
-
track(target, "length");
|
|
3768
|
-
return Reflect.get(target, prop, receiver);
|
|
5758
|
+
return Set;
|
|
3769
5759
|
}
|
|
3770
5760
|
const value = Reflect.get(target, prop, receiver);
|
|
3771
|
-
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(prop, 10));
|
|
3772
|
-
if (isNumericIndex) {
|
|
3773
|
-
track(target, String(prop));
|
|
3774
|
-
if (!isObject2(value))
|
|
3775
|
-
return value;
|
|
3776
|
-
if (globalSeen.has(value))
|
|
3777
|
-
return globalSeen.get(value);
|
|
3778
|
-
const cachedValueProxy = wrapperCache.get(value);
|
|
3779
|
-
if (cachedValueProxy)
|
|
3780
|
-
return cachedValueProxy;
|
|
3781
|
-
const propKey = String(prop);
|
|
3782
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3783
|
-
let newPath = getPathConcat(pathKey);
|
|
3784
|
-
if (newPath === undefined) {
|
|
3785
|
-
newPath = path.concat(propKey);
|
|
3786
|
-
setPathConcat(pathKey, newPath);
|
|
3787
|
-
}
|
|
3788
|
-
if (Array.isArray(value))
|
|
3789
|
-
return wrapArray(value, emit, newPath);
|
|
3790
|
-
if (value instanceof Map)
|
|
3791
|
-
return wrapMap(value, emit, newPath);
|
|
3792
|
-
if (value instanceof Set)
|
|
3793
|
-
return wrapSet(value, emit, newPath);
|
|
3794
|
-
if (value instanceof Date)
|
|
3795
|
-
return new Date(value.getTime());
|
|
3796
|
-
return reactive(value, emit, newPath);
|
|
3797
|
-
}
|
|
3798
5761
|
if (typeof value === "function") {
|
|
3799
5762
|
return value.bind(target);
|
|
3800
5763
|
}
|
|
3801
5764
|
return value;
|
|
3802
|
-
},
|
|
3803
|
-
set(target, prop, value, receiver) {
|
|
3804
|
-
if (isObject2(value))
|
|
3805
|
-
value = unwrapForStore(value);
|
|
3806
|
-
const oldValue = target[prop];
|
|
3807
|
-
if (oldValue === value && Reflect.has(target, prop))
|
|
3808
|
-
return true;
|
|
3809
|
-
if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
|
|
3810
|
-
return true;
|
|
3811
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
3812
|
-
const result = Reflect.set(target, prop, value, receiver);
|
|
3813
|
-
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
|
|
3814
|
-
if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
|
|
3815
|
-
const resolvePath = (key) => {
|
|
3816
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${key}` : key;
|
|
3817
|
-
let newPath = getPathConcat(pathKey);
|
|
3818
|
-
if (newPath === undefined) {
|
|
3819
|
-
newPath = path.concat(key);
|
|
3820
|
-
setPathConcat(pathKey, newPath);
|
|
3821
|
-
}
|
|
3822
|
-
return newPath;
|
|
3823
|
-
};
|
|
3824
|
-
if (Array.isArray(target) && prop === "length" && Number(value) > Number(oldValue)) {
|
|
3825
|
-
const oldLength = Number(oldValue);
|
|
3826
|
-
const newLength = Number(value);
|
|
3827
|
-
for (let i = oldLength;i < newLength; i++) {
|
|
3828
|
-
emit?.({ action: "set", path: resolvePath(String(i)), newValue: undefined });
|
|
3829
|
-
}
|
|
3830
|
-
} else {
|
|
3831
|
-
const event = {
|
|
3832
|
-
action: "set",
|
|
3833
|
-
path: resolvePath(String(prop)),
|
|
3834
|
-
oldValue,
|
|
3835
|
-
newValue: isObject2(value) ? deepClone(value) : value
|
|
3836
|
-
};
|
|
3837
|
-
emit?.(event);
|
|
3838
|
-
}
|
|
3839
|
-
if (isObject2(oldValue) && oldValue !== value) {
|
|
3840
|
-
evictDeep(oldValue);
|
|
3841
|
-
}
|
|
3842
|
-
trigger(target, prop);
|
|
3843
|
-
}
|
|
3844
|
-
return result;
|
|
3845
5765
|
}
|
|
3846
5766
|
});
|
|
3847
|
-
globalSeen.set(
|
|
3848
|
-
wrapperCache.set(
|
|
5767
|
+
globalSeen.set(set, proxy);
|
|
5768
|
+
wrapperCache.set(set, proxy);
|
|
3849
5769
|
proxyStats.created++;
|
|
3850
|
-
proxyStats.
|
|
5770
|
+
proxyStats.sets++;
|
|
3851
5771
|
return proxy;
|
|
3852
5772
|
}
|
|
3853
5773
|
|
|
3854
5774
|
// src/reactive.ts
|
|
3855
|
-
function
|
|
5775
|
+
function isObject6(v) {
|
|
3856
5776
|
return v && typeof v === "object";
|
|
3857
5777
|
}
|
|
3858
5778
|
function isReactive(value) {
|
|
@@ -3866,60 +5786,98 @@ function createAsyncEmit(emit) {
|
|
|
3866
5786
|
if (!flushScheduled) {
|
|
3867
5787
|
flushScheduled = true;
|
|
3868
5788
|
queueMicrotask(() => {
|
|
3869
|
-
|
|
3870
|
-
|
|
3871
|
-
|
|
3872
|
-
|
|
5789
|
+
let failed = false;
|
|
5790
|
+
let failure;
|
|
5791
|
+
let next = 0;
|
|
5792
|
+
while (next < queue.length) {
|
|
5793
|
+
try {
|
|
5794
|
+
emit(queue[next++]);
|
|
5795
|
+
} catch (error) {
|
|
5796
|
+
if (!failed) {
|
|
5797
|
+
failed = true;
|
|
5798
|
+
failure = error;
|
|
5799
|
+
}
|
|
5800
|
+
}
|
|
5801
|
+
if (next === FLUSH_CHUNK) {
|
|
5802
|
+
queue.splice(0, next);
|
|
5803
|
+
next = 0;
|
|
5804
|
+
}
|
|
3873
5805
|
}
|
|
5806
|
+
queue.length = 0;
|
|
5807
|
+
flushScheduled = false;
|
|
5808
|
+
if (failed)
|
|
5809
|
+
throw failure;
|
|
3874
5810
|
});
|
|
3875
5811
|
}
|
|
3876
5812
|
};
|
|
3877
5813
|
}
|
|
5814
|
+
var FLUSH_CHUNK = 1024;
|
|
3878
5815
|
function reactive(obj, emit, path = [], options) {
|
|
3879
5816
|
if (obj["__v_skip" /* SKIP */]) {
|
|
3880
5817
|
return obj;
|
|
3881
5818
|
}
|
|
3882
|
-
|
|
3883
|
-
|
|
5819
|
+
const existing = globalSeen.get(obj);
|
|
5820
|
+
if (existing !== undefined)
|
|
5821
|
+
return existing;
|
|
5822
|
+
if (obj["__v_isReactive" /* IS_REACTIVE */])
|
|
5823
|
+
return obj;
|
|
3884
5824
|
if (emit && path.length === 0 && options?.async) {
|
|
3885
5825
|
emit = createAsyncEmit(emit);
|
|
3886
5826
|
}
|
|
5827
|
+
let fresh = false;
|
|
3887
5828
|
if (emit && path.length === 0) {
|
|
3888
5829
|
try {
|
|
3889
|
-
const
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
newValue: obj
|
|
3893
|
-
};
|
|
3894
|
-
emit(initialEvent);
|
|
5830
|
+
const newValue = cloneStored(obj, undefined, 2 /* All */);
|
|
5831
|
+
fresh = copiedFresh;
|
|
5832
|
+
emit({ action: "replace", path: [], newValue });
|
|
3895
5833
|
} catch (error) {
|
|
5834
|
+
if (error instanceof SnapshotLimitError)
|
|
5835
|
+
throw error;
|
|
3896
5836
|
console.error("Failed to emit initial reactive state:", error);
|
|
3897
5837
|
}
|
|
3898
5838
|
}
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
if (
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
5839
|
+
const node = ensureLocationNode(obj);
|
|
5840
|
+
node.root = { emit, path, async: emit !== undefined && options?.async === true, undelivered: undefined };
|
|
5841
|
+
node.scope = node.root;
|
|
5842
|
+
if (emit && !fresh)
|
|
5843
|
+
adoptRoot(node);
|
|
5844
|
+
return createProxy(obj, node, options);
|
|
5845
|
+
}
|
|
5846
|
+
function wrapChild(raw, parent, key, options) {
|
|
5847
|
+
let node = getLocationNode(raw);
|
|
5848
|
+
if (node !== undefined && node.proxy !== undefined) {
|
|
5849
|
+
notePlace(node, parent, key);
|
|
5850
|
+
node.scope ??= parent.scope;
|
|
5851
|
+
return node.proxy;
|
|
5852
|
+
}
|
|
5853
|
+
if (raw["__v_skip" /* SKIP */])
|
|
5854
|
+
return raw;
|
|
5855
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */])
|
|
5856
|
+
return wrapChild(toRaw(raw), parent, key, options);
|
|
5857
|
+
if (raw instanceof Date)
|
|
5858
|
+
return new Date(raw.getTime());
|
|
5859
|
+
node ??= ensureLocationNode(raw);
|
|
5860
|
+
notePlace(node, parent, key);
|
|
5861
|
+
node.scope ??= parent.scope;
|
|
5862
|
+
return restoreEvicted(node) ?? createProxy(raw, node, options);
|
|
5863
|
+
}
|
|
5864
|
+
function wrapUnplaced(raw) {
|
|
5865
|
+
if (raw["__v_skip" /* SKIP */])
|
|
5866
|
+
return raw;
|
|
5867
|
+
const existing = globalSeen.get(raw);
|
|
5868
|
+
if (existing !== undefined)
|
|
5869
|
+
return existing;
|
|
5870
|
+
if (raw["__v_isReactive" /* IS_REACTIVE */])
|
|
5871
|
+
return wrapUnplaced(toRaw(raw));
|
|
5872
|
+
const node = ensureLocationNode(raw);
|
|
5873
|
+
return restoreEvicted(node) ?? createProxy(raw, node);
|
|
5874
|
+
}
|
|
5875
|
+
function createProxy(raw, node, options) {
|
|
5876
|
+
const proxy = Array.isArray(raw) ? wrapArray(raw, node) : raw instanceof Map ? wrapMap(raw, node) : raw instanceof Set ? wrapSet(raw, node) : wrapObject(raw, node, options);
|
|
5877
|
+
node.proxy = proxy;
|
|
5878
|
+
return proxy;
|
|
5879
|
+
}
|
|
5880
|
+
function wrapObject(obj, node, options) {
|
|
3923
5881
|
const proxy = new Proxy(obj, {
|
|
3924
5882
|
get(target, prop, receiver) {
|
|
3925
5883
|
if (prop === "__v_raw" /* RAW */) {
|
|
@@ -3930,44 +5888,45 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3930
5888
|
}
|
|
3931
5889
|
const value = Reflect.get(target, prop, receiver);
|
|
3932
5890
|
track(target, prop);
|
|
3933
|
-
if (!
|
|
5891
|
+
if (!isObject6(value))
|
|
3934
5892
|
return value;
|
|
3935
|
-
|
|
3936
|
-
const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
|
|
3937
|
-
let newPath = getPathConcat(pathKey);
|
|
3938
|
-
if (newPath === undefined) {
|
|
3939
|
-
newPath = path.concat(propKey);
|
|
3940
|
-
setPathConcat(pathKey, newPath);
|
|
3941
|
-
}
|
|
3942
|
-
return wrapValue(value, newPath);
|
|
5893
|
+
return wrapChild(value, node, prop, options);
|
|
3943
5894
|
},
|
|
3944
5895
|
set(target, prop, value, receiver) {
|
|
3945
|
-
if (
|
|
5896
|
+
if (isObject6(value))
|
|
3946
5897
|
value = unwrapForStore(value);
|
|
3947
5898
|
const oldValue = target[prop];
|
|
3948
5899
|
if (oldValue === value)
|
|
3949
5900
|
return true;
|
|
3950
|
-
if (!options?.async &&
|
|
5901
|
+
if (!options?.async && isObject6(oldValue) && isObject6(value) && deepEqual(oldValue, value))
|
|
3951
5902
|
return true;
|
|
3952
|
-
const
|
|
5903
|
+
const emits = !writesThroughSetter(target, prop, node);
|
|
5904
|
+
const located = emits ? locate(node, prop) : undefined;
|
|
5905
|
+
const event = located && {
|
|
5906
|
+
action: "set",
|
|
5907
|
+
path: located.paths[0],
|
|
5908
|
+
oldValue,
|
|
5909
|
+
newValue: value
|
|
5910
|
+
};
|
|
5911
|
+
const held = located && heldItems(value, oldValue);
|
|
5912
|
+
const copied = copyPayload(event, located, target, held);
|
|
5913
|
+
if (copied === 0 /* Reaches */) {
|
|
5914
|
+
const after = shallowCopy(target);
|
|
5915
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
5916
|
+
if (descriptor === undefined || descriptor.enumerable)
|
|
5917
|
+
setData(after, prop, value);
|
|
5918
|
+
copyPayloadReaching(event, located, target, after);
|
|
5919
|
+
}
|
|
3953
5920
|
const result = Reflect.set(target, prop, value, receiver);
|
|
3954
|
-
if (result &&
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
}
|
|
3962
|
-
const event = {
|
|
3963
|
-
action: "set",
|
|
3964
|
-
path: newPath,
|
|
3965
|
-
oldValue,
|
|
3966
|
-
newValue: isObject3(value) ? deepClone(value) : value
|
|
3967
|
-
};
|
|
3968
|
-
emit?.(event);
|
|
5921
|
+
if (result && emits) {
|
|
5922
|
+
if (isObject6(oldValue))
|
|
5923
|
+
detachPlace(oldValue, node, prop);
|
|
5924
|
+
if (isObject6(value))
|
|
5925
|
+
attachValue(value, node, prop, copied === 2 /* Fresh */, located && oldValue, held);
|
|
5926
|
+
if (event !== undefined)
|
|
5927
|
+
dispatch(located, event);
|
|
3969
5928
|
trigger(target, prop);
|
|
3970
|
-
if (
|
|
5929
|
+
if (isObject6(oldValue)) {
|
|
3971
5930
|
evictDeep(oldValue);
|
|
3972
5931
|
}
|
|
3973
5932
|
}
|
|
@@ -3976,23 +5935,25 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3976
5935
|
deleteProperty(target, prop) {
|
|
3977
5936
|
const oldValue = target[prop];
|
|
3978
5937
|
const hadProperty = Object.prototype.hasOwnProperty.call(target, prop);
|
|
5938
|
+
const located = hadProperty ? locate(node, prop) : undefined;
|
|
5939
|
+
const event = located && {
|
|
5940
|
+
action: "delete",
|
|
5941
|
+
path: located.paths[0],
|
|
5942
|
+
oldValue
|
|
5943
|
+
};
|
|
5944
|
+
if (copyPayload(event, located, target) === 0 /* Reaches */) {
|
|
5945
|
+
const after = shallowCopy(target);
|
|
5946
|
+
delete after[prop];
|
|
5947
|
+
copyPayloadReaching(event, located, target, after);
|
|
5948
|
+
}
|
|
3979
5949
|
const result = Reflect.deleteProperty(target, prop);
|
|
3980
5950
|
if (hadProperty && result) {
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
newPath = path.concat(propKey);
|
|
3986
|
-
setPathConcat(pathKey, newPath);
|
|
3987
|
-
}
|
|
3988
|
-
const event = {
|
|
3989
|
-
action: "delete",
|
|
3990
|
-
path: newPath,
|
|
3991
|
-
oldValue
|
|
3992
|
-
};
|
|
3993
|
-
emit?.(event);
|
|
5951
|
+
if (isObject6(oldValue))
|
|
5952
|
+
detachPlace(oldValue, node, prop);
|
|
5953
|
+
if (event !== undefined)
|
|
5954
|
+
dispatch(located, event);
|
|
3994
5955
|
trigger(target, prop);
|
|
3995
|
-
if (
|
|
5956
|
+
if (isObject6(oldValue)) {
|
|
3996
5957
|
evictDeep(oldValue);
|
|
3997
5958
|
}
|
|
3998
5959
|
}
|
|
@@ -4004,6 +5965,260 @@ function reactive(obj, emit, path = [], options) {
|
|
|
4004
5965
|
proxyStats.objects++;
|
|
4005
5966
|
return proxy;
|
|
4006
5967
|
}
|
|
5968
|
+
|
|
5969
|
+
// src/state.ts
|
|
5970
|
+
function getValue(obj, key) {
|
|
5971
|
+
if (obj instanceof Map)
|
|
5972
|
+
return obj.get(key);
|
|
5973
|
+
return obj[key];
|
|
5974
|
+
}
|
|
5975
|
+
function setValue(obj, key, value) {
|
|
5976
|
+
if (obj instanceof Map)
|
|
5977
|
+
obj.set(key, value);
|
|
5978
|
+
else
|
|
5979
|
+
obj[key] = value;
|
|
5980
|
+
}
|
|
5981
|
+
function deleteValue(obj, key) {
|
|
5982
|
+
if (obj instanceof Map)
|
|
5983
|
+
obj.delete(key);
|
|
5984
|
+
else
|
|
5985
|
+
delete obj[key];
|
|
5986
|
+
}
|
|
5987
|
+
function validateCachedPath(root, fullPath, pathKey, cached) {
|
|
5988
|
+
if (fullPath.length === 0)
|
|
5989
|
+
return cached;
|
|
5990
|
+
const lastKey = fullPath[fullPath.length - 1];
|
|
5991
|
+
let grandparent = root;
|
|
5992
|
+
for (let i = 0;i < fullPath.length - 1; i++) {
|
|
5993
|
+
grandparent = grandparent ? getValue(grandparent, fullPath[i]) : undefined;
|
|
5994
|
+
if (grandparent === undefined)
|
|
5995
|
+
break;
|
|
5996
|
+
}
|
|
5997
|
+
if (grandparent === undefined) {
|
|
5998
|
+
evictDescendantsFromPathCache(root, pathKey);
|
|
5999
|
+
return;
|
|
6000
|
+
}
|
|
6001
|
+
const actual = getValue(grandparent, lastKey);
|
|
6002
|
+
if (actual === cached)
|
|
6003
|
+
return cached;
|
|
6004
|
+
evictDescendantsFromPathCache(root, pathKey);
|
|
6005
|
+
return;
|
|
6006
|
+
}
|
|
6007
|
+
var actionHandlers = {
|
|
6008
|
+
set: function(parent, key, event) {
|
|
6009
|
+
if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
|
|
6010
|
+
console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
|
|
6011
|
+
return;
|
|
6012
|
+
}
|
|
6013
|
+
setValue(parent, key, event.newValue);
|
|
6014
|
+
},
|
|
6015
|
+
delete: function(parent, key) {
|
|
6016
|
+
deleteValue(parent, key);
|
|
6017
|
+
},
|
|
6018
|
+
"array-push": function(targetArray, _keyIgnored, event) {
|
|
6019
|
+
if (!Array.isArray(targetArray)) {
|
|
6020
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6021
|
+
return;
|
|
6022
|
+
}
|
|
6023
|
+
if (!event.items) {
|
|
6024
|
+
console.warn("array-push event missing items");
|
|
6025
|
+
return;
|
|
6026
|
+
}
|
|
6027
|
+
targetArray.push(...event.items);
|
|
6028
|
+
},
|
|
6029
|
+
"array-pop": function(targetArray, _keyIgnored, event) {
|
|
6030
|
+
if (!Array.isArray(targetArray)) {
|
|
6031
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6032
|
+
return;
|
|
6033
|
+
}
|
|
6034
|
+
if (targetArray.length > 0) {
|
|
6035
|
+
targetArray.pop();
|
|
6036
|
+
}
|
|
6037
|
+
},
|
|
6038
|
+
"array-splice": function(targetArray, _keyIgnored, event) {
|
|
6039
|
+
if (!Array.isArray(targetArray)) {
|
|
6040
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6041
|
+
return;
|
|
6042
|
+
}
|
|
6043
|
+
if (event.key === undefined || event.deleteCount === undefined) {
|
|
6044
|
+
console.warn("array-splice event missing key or deletecount");
|
|
6045
|
+
return;
|
|
6046
|
+
}
|
|
6047
|
+
if (event.items && event.items.length > 0) {
|
|
6048
|
+
targetArray.splice(event.key, event.deleteCount, ...event.items);
|
|
6049
|
+
} else {
|
|
6050
|
+
targetArray.splice(event.key, event.deleteCount);
|
|
6051
|
+
}
|
|
6052
|
+
},
|
|
6053
|
+
"array-shift": function(targetArray, _keyIgnored, event) {
|
|
6054
|
+
if (!Array.isArray(targetArray)) {
|
|
6055
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6056
|
+
return;
|
|
6057
|
+
}
|
|
6058
|
+
if (targetArray.length > 0) {
|
|
6059
|
+
targetArray.shift();
|
|
6060
|
+
}
|
|
6061
|
+
},
|
|
6062
|
+
"array-unshift": function(targetArray, _keyIgnored, event) {
|
|
6063
|
+
if (!Array.isArray(targetArray)) {
|
|
6064
|
+
console.warn(`expected array at path ${event.path.join(".")}`);
|
|
6065
|
+
return;
|
|
6066
|
+
}
|
|
6067
|
+
if (!event.items) {
|
|
6068
|
+
console.warn("array-unshift event missing items");
|
|
6069
|
+
return;
|
|
6070
|
+
}
|
|
6071
|
+
targetArray.unshift(...event.items);
|
|
6072
|
+
},
|
|
6073
|
+
"map-set": function(targetMap2, _parentKeyIgnored, event) {
|
|
6074
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6075
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6076
|
+
return;
|
|
6077
|
+
}
|
|
6078
|
+
replicaMapSet(targetMap2, event.key, event.newValue);
|
|
6079
|
+
},
|
|
6080
|
+
"map-delete": function(targetMap2, _parentKeyIgnored, event) {
|
|
6081
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6082
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6083
|
+
return;
|
|
6084
|
+
}
|
|
6085
|
+
replicaMapDelete(targetMap2, event.key);
|
|
6086
|
+
},
|
|
6087
|
+
"map-clear": function(targetMap2, _parentKeyIgnored, event) {
|
|
6088
|
+
if (!(targetMap2 instanceof Map)) {
|
|
6089
|
+
console.warn(`expected map at path ${event.path.join(".")}`);
|
|
6090
|
+
return;
|
|
6091
|
+
}
|
|
6092
|
+
targetMap2.clear();
|
|
6093
|
+
forgetReplicaIndex(targetMap2);
|
|
6094
|
+
},
|
|
6095
|
+
"set-add": function(targetSet, _keyIgnored, event) {
|
|
6096
|
+
if (!(targetSet instanceof Set)) {
|
|
6097
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6098
|
+
return;
|
|
6099
|
+
}
|
|
6100
|
+
replicaAdd(targetSet, event.value);
|
|
6101
|
+
},
|
|
6102
|
+
"set-delete": function(targetSet, _keyIgnored, event) {
|
|
6103
|
+
if (!(targetSet instanceof Set)) {
|
|
6104
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6105
|
+
return;
|
|
6106
|
+
}
|
|
6107
|
+
replicaDelete(targetSet, event.value);
|
|
6108
|
+
},
|
|
6109
|
+
"set-clear": function(targetSet, _keyIgnored, event) {
|
|
6110
|
+
if (!(targetSet instanceof Set)) {
|
|
6111
|
+
console.warn(`expected set at path ${event.path.join(".")}`);
|
|
6112
|
+
return;
|
|
6113
|
+
}
|
|
6114
|
+
targetSet.clear();
|
|
6115
|
+
forgetReplicaIndex(targetSet);
|
|
6116
|
+
},
|
|
6117
|
+
replace: function(target, _keyIgnored, event) {
|
|
6118
|
+
const newValue = event.newValue;
|
|
6119
|
+
if (newValue === undefined || newValue === null) {
|
|
6120
|
+
console.warn("replace action requires newValue");
|
|
6121
|
+
return;
|
|
6122
|
+
}
|
|
6123
|
+
if (Array.isArray(target) && Array.isArray(newValue)) {
|
|
6124
|
+
target.splice(0, target.length, ...newValue);
|
|
6125
|
+
} else if (target instanceof Map && newValue instanceof Map) {
|
|
6126
|
+
const newValueEntries = [...newValue.entries()];
|
|
6127
|
+
target.clear();
|
|
6128
|
+
forgetReplicaIndex(target);
|
|
6129
|
+
const reactiveTarget = isReactive(target);
|
|
6130
|
+
for (const [key, value] of newValueEntries) {
|
|
6131
|
+
if (reactiveTarget)
|
|
6132
|
+
replicaMapSet(target, key, value);
|
|
6133
|
+
else
|
|
6134
|
+
target.set(key, value);
|
|
6135
|
+
}
|
|
6136
|
+
} else if (target instanceof Set && newValue instanceof Set) {
|
|
6137
|
+
const newValueEntries = [...newValue.values()];
|
|
6138
|
+
target.clear();
|
|
6139
|
+
forgetReplicaIndex(target);
|
|
6140
|
+
const reactiveTarget = isReactive(target);
|
|
6141
|
+
for (const value of newValueEntries) {
|
|
6142
|
+
if (reactiveTarget)
|
|
6143
|
+
replicaAdd(target, value);
|
|
6144
|
+
else
|
|
6145
|
+
target.add(value);
|
|
6146
|
+
}
|
|
6147
|
+
} else if (typeof target === "object" && target !== null && typeof newValue === "object" && newValue !== null) {
|
|
6148
|
+
Object.keys(target).forEach((key) => delete target[key]);
|
|
6149
|
+
Object.assign(target, newValue);
|
|
6150
|
+
} else {
|
|
6151
|
+
console.warn(`Type mismatch or unsupported type for 'replace' action at path ${event.path.join(".")}. Target type: ${typeof target} ${target.constructor.name}, New value type: ${typeof newValue} ${newValue.constructor.name}`);
|
|
6152
|
+
}
|
|
6153
|
+
}
|
|
6154
|
+
};
|
|
6155
|
+
function updateState(root, event) {
|
|
6156
|
+
const { action, path } = event;
|
|
6157
|
+
if (!path || path.length === 0 && action !== "replace") {
|
|
6158
|
+
console.warn("event path is invalid for action", event);
|
|
6159
|
+
return;
|
|
6160
|
+
}
|
|
6161
|
+
const handler = actionHandlers[action];
|
|
6162
|
+
if (!handler) {
|
|
6163
|
+
console.error(`unhandled action type: ${action}`, event);
|
|
6164
|
+
return;
|
|
6165
|
+
}
|
|
6166
|
+
let targetForHandler;
|
|
6167
|
+
let keyForHandler = null;
|
|
6168
|
+
if (action === "set" || action === "delete") {
|
|
6169
|
+
if (path.length === 1) {
|
|
6170
|
+
targetForHandler = root;
|
|
6171
|
+
keyForHandler = path[0];
|
|
6172
|
+
} else {
|
|
6173
|
+
const parentPath = path.slice(0, -1);
|
|
6174
|
+
const parentPathKey = parentPath.join(".");
|
|
6175
|
+
let parent = pathCache.get(root)?.get(parentPathKey);
|
|
6176
|
+
if (parent !== undefined) {
|
|
6177
|
+
parent = validateCachedPath(root, parentPath, parentPathKey, parent);
|
|
6178
|
+
}
|
|
6179
|
+
if (parent === undefined) {
|
|
6180
|
+
parent = parentPath.reduce((acc, key) => acc ? getValue(acc, key) : undefined, root);
|
|
6181
|
+
if (parent !== undefined)
|
|
6182
|
+
setInPathCache(root, parentPathKey, parent);
|
|
6183
|
+
}
|
|
6184
|
+
if (parent === undefined) {
|
|
6185
|
+
console.warn(`parent path ${parentPathKey} not found for action ${action}`);
|
|
6186
|
+
return;
|
|
6187
|
+
}
|
|
6188
|
+
targetForHandler = parent;
|
|
6189
|
+
keyForHandler = path[path.length - 1];
|
|
6190
|
+
}
|
|
6191
|
+
} else if (action.startsWith("array-") || action.startsWith("map-") || action.startsWith("set-") || action === "replace") {
|
|
6192
|
+
if (path.length === 0 && action === "replace") {
|
|
6193
|
+
targetForHandler = root;
|
|
6194
|
+
} else {
|
|
6195
|
+
const targetPath = path;
|
|
6196
|
+
const targetPathKey = targetPath.join(".");
|
|
6197
|
+
let targetCollection = pathCache.get(root)?.get(targetPathKey);
|
|
6198
|
+
if (targetCollection !== undefined) {
|
|
6199
|
+
targetCollection = validateCachedPath(root, targetPath, targetPathKey, targetCollection);
|
|
6200
|
+
}
|
|
6201
|
+
if (targetCollection === undefined) {
|
|
6202
|
+
targetCollection = targetPath.reduce((acc, key) => acc ? getValue(acc, key) : undefined, root);
|
|
6203
|
+
if (targetCollection !== undefined)
|
|
6204
|
+
setInPathCache(root, targetPathKey, targetCollection);
|
|
6205
|
+
}
|
|
6206
|
+
if (targetCollection === undefined) {
|
|
6207
|
+
console.warn(`target at path ${targetPathKey} not found for action ${action}`);
|
|
6208
|
+
return;
|
|
6209
|
+
}
|
|
6210
|
+
targetForHandler = targetCollection;
|
|
6211
|
+
}
|
|
6212
|
+
} else {
|
|
6213
|
+
console.error(`unexpected action type passed checks: ${action}`);
|
|
6214
|
+
return;
|
|
6215
|
+
}
|
|
6216
|
+
handler(targetForHandler, keyForHandler, event);
|
|
6217
|
+
if (action === "set" && event.newValue != null && typeof event.newValue === "object") {
|
|
6218
|
+
const fullPathKey = path.join(".");
|
|
6219
|
+
evictDescendantsFromPathCache(root, fullPathKey);
|
|
6220
|
+
}
|
|
6221
|
+
}
|
|
4007
6222
|
// src/ref.ts
|
|
4008
6223
|
var isRefSymbol = Symbol("isRef");
|
|
4009
6224
|
function ref(value) {
|