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