@yiin/reactive-proxy-state 1.0.38 → 1.0.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -6
- package/dist/index.js +47 -6
- package/dist/utils.d.ts +6 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2389,6 +2389,40 @@ function resetProxyStats() {
|
|
|
2389
2389
|
proxyStats.objects = 0;
|
|
2390
2390
|
proxyStats.staleEvicted = 0;
|
|
2391
2391
|
}
|
|
2392
|
+
function evictDeep(value) {
|
|
2393
|
+
if (value == null || typeof value !== "object")
|
|
2394
|
+
return;
|
|
2395
|
+
if (!globalSeen.has(value))
|
|
2396
|
+
return;
|
|
2397
|
+
globalSeen.delete(value);
|
|
2398
|
+
wrapperCache.delete(value);
|
|
2399
|
+
proxyStats.staleEvicted++;
|
|
2400
|
+
if (Array.isArray(value)) {
|
|
2401
|
+
for (let i = 0;i < value.length; i++) {
|
|
2402
|
+
if (value[i] != null && typeof value[i] === "object") {
|
|
2403
|
+
evictDeep(value[i]);
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
} else if (value instanceof Map) {
|
|
2407
|
+
for (const v of value.values()) {
|
|
2408
|
+
if (v != null && typeof v === "object")
|
|
2409
|
+
evictDeep(v);
|
|
2410
|
+
}
|
|
2411
|
+
} else if (value instanceof Set) {
|
|
2412
|
+
for (const v of value) {
|
|
2413
|
+
if (v != null && typeof v === "object")
|
|
2414
|
+
evictDeep(v);
|
|
2415
|
+
}
|
|
2416
|
+
} else {
|
|
2417
|
+
const keys = Object.keys(value);
|
|
2418
|
+
for (let i = 0;i < keys.length; i++) {
|
|
2419
|
+
const child = value[keys[i]];
|
|
2420
|
+
if (child != null && typeof child === "object") {
|
|
2421
|
+
evictDeep(child);
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2392
2426
|
function cleanupPathCache(root) {
|
|
2393
2427
|
const cache = pathCache.get(root);
|
|
2394
2428
|
if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
|
|
@@ -3480,6 +3514,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3480
3514
|
oldValue
|
|
3481
3515
|
};
|
|
3482
3516
|
emit?.(event);
|
|
3517
|
+
if (isObject2(oldValue))
|
|
3518
|
+
evictDeep(oldValue);
|
|
3483
3519
|
trigger(target, Symbol.iterator);
|
|
3484
3520
|
if (oldLength !== newLength) {
|
|
3485
3521
|
trigger(target, "length");
|
|
@@ -3503,6 +3539,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3503
3539
|
oldValue
|
|
3504
3540
|
};
|
|
3505
3541
|
emit?.(event);
|
|
3542
|
+
if (isObject2(oldValue))
|
|
3543
|
+
evictDeep(oldValue);
|
|
3506
3544
|
trigger(target, Symbol.iterator);
|
|
3507
3545
|
if (oldLength !== newLength) {
|
|
3508
3546
|
trigger(target, "length");
|
|
@@ -3552,6 +3590,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3552
3590
|
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3553
3591
|
};
|
|
3554
3592
|
emit?.(event);
|
|
3593
|
+
for (let i = 0;i < deletedItems.length; i++) {
|
|
3594
|
+
if (isObject2(deletedItems[i]))
|
|
3595
|
+
evictDeep(deletedItems[i]);
|
|
3596
|
+
}
|
|
3555
3597
|
trigger(target, Symbol.iterator);
|
|
3556
3598
|
if (oldLength !== newLength) {
|
|
3557
3599
|
trigger(target, "length");
|
|
@@ -3710,6 +3752,9 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3710
3752
|
newValue: value
|
|
3711
3753
|
};
|
|
3712
3754
|
emit?.(event);
|
|
3755
|
+
if (isObject2(oldValue) && oldValue !== value) {
|
|
3756
|
+
evictDeep(oldValue);
|
|
3757
|
+
}
|
|
3713
3758
|
trigger(target, prop);
|
|
3714
3759
|
}
|
|
3715
3760
|
return result;
|
|
@@ -3841,9 +3886,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3841
3886
|
emit?.(event);
|
|
3842
3887
|
trigger(target, prop);
|
|
3843
3888
|
if (isObject3(oldValue) && oldValue !== value) {
|
|
3844
|
-
|
|
3845
|
-
wrapperCache.delete(oldValue);
|
|
3846
|
-
proxyStats.staleEvicted++;
|
|
3889
|
+
evictDeep(oldValue);
|
|
3847
3890
|
}
|
|
3848
3891
|
}
|
|
3849
3892
|
return result;
|
|
@@ -3868,9 +3911,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3868
3911
|
emit?.(event);
|
|
3869
3912
|
trigger(target, prop);
|
|
3870
3913
|
if (isObject3(oldValue)) {
|
|
3871
|
-
|
|
3872
|
-
wrapperCache.delete(oldValue);
|
|
3873
|
-
proxyStats.staleEvicted++;
|
|
3914
|
+
evictDeep(oldValue);
|
|
3874
3915
|
}
|
|
3875
3916
|
}
|
|
3876
3917
|
return result;
|
package/dist/index.js
CHANGED
|
@@ -2327,6 +2327,40 @@ function resetProxyStats() {
|
|
|
2327
2327
|
proxyStats.objects = 0;
|
|
2328
2328
|
proxyStats.staleEvicted = 0;
|
|
2329
2329
|
}
|
|
2330
|
+
function evictDeep(value) {
|
|
2331
|
+
if (value == null || typeof value !== "object")
|
|
2332
|
+
return;
|
|
2333
|
+
if (!globalSeen.has(value))
|
|
2334
|
+
return;
|
|
2335
|
+
globalSeen.delete(value);
|
|
2336
|
+
wrapperCache.delete(value);
|
|
2337
|
+
proxyStats.staleEvicted++;
|
|
2338
|
+
if (Array.isArray(value)) {
|
|
2339
|
+
for (let i = 0;i < value.length; i++) {
|
|
2340
|
+
if (value[i] != null && typeof value[i] === "object") {
|
|
2341
|
+
evictDeep(value[i]);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
} else if (value instanceof Map) {
|
|
2345
|
+
for (const v of value.values()) {
|
|
2346
|
+
if (v != null && typeof v === "object")
|
|
2347
|
+
evictDeep(v);
|
|
2348
|
+
}
|
|
2349
|
+
} else if (value instanceof Set) {
|
|
2350
|
+
for (const v of value) {
|
|
2351
|
+
if (v != null && typeof v === "object")
|
|
2352
|
+
evictDeep(v);
|
|
2353
|
+
}
|
|
2354
|
+
} else {
|
|
2355
|
+
const keys = Object.keys(value);
|
|
2356
|
+
for (let i = 0;i < keys.length; i++) {
|
|
2357
|
+
const child = value[keys[i]];
|
|
2358
|
+
if (child != null && typeof child === "object") {
|
|
2359
|
+
evictDeep(child);
|
|
2360
|
+
}
|
|
2361
|
+
}
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2330
2364
|
function cleanupPathCache(root) {
|
|
2331
2365
|
const cache = pathCache.get(root);
|
|
2332
2366
|
if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
|
|
@@ -3418,6 +3452,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3418
3452
|
oldValue
|
|
3419
3453
|
};
|
|
3420
3454
|
emit?.(event);
|
|
3455
|
+
if (isObject2(oldValue))
|
|
3456
|
+
evictDeep(oldValue);
|
|
3421
3457
|
trigger(target, Symbol.iterator);
|
|
3422
3458
|
if (oldLength !== newLength) {
|
|
3423
3459
|
trigger(target, "length");
|
|
@@ -3441,6 +3477,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3441
3477
|
oldValue
|
|
3442
3478
|
};
|
|
3443
3479
|
emit?.(event);
|
|
3480
|
+
if (isObject2(oldValue))
|
|
3481
|
+
evictDeep(oldValue);
|
|
3444
3482
|
trigger(target, Symbol.iterator);
|
|
3445
3483
|
if (oldLength !== newLength) {
|
|
3446
3484
|
trigger(target, "length");
|
|
@@ -3490,6 +3528,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3490
3528
|
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3491
3529
|
};
|
|
3492
3530
|
emit?.(event);
|
|
3531
|
+
for (let i = 0;i < deletedItems.length; i++) {
|
|
3532
|
+
if (isObject2(deletedItems[i]))
|
|
3533
|
+
evictDeep(deletedItems[i]);
|
|
3534
|
+
}
|
|
3493
3535
|
trigger(target, Symbol.iterator);
|
|
3494
3536
|
if (oldLength !== newLength) {
|
|
3495
3537
|
trigger(target, "length");
|
|
@@ -3648,6 +3690,9 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3648
3690
|
newValue: value
|
|
3649
3691
|
};
|
|
3650
3692
|
emit?.(event);
|
|
3693
|
+
if (isObject2(oldValue) && oldValue !== value) {
|
|
3694
|
+
evictDeep(oldValue);
|
|
3695
|
+
}
|
|
3651
3696
|
trigger(target, prop);
|
|
3652
3697
|
}
|
|
3653
3698
|
return result;
|
|
@@ -3779,9 +3824,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3779
3824
|
emit?.(event);
|
|
3780
3825
|
trigger(target, prop);
|
|
3781
3826
|
if (isObject3(oldValue) && oldValue !== value) {
|
|
3782
|
-
|
|
3783
|
-
wrapperCache.delete(oldValue);
|
|
3784
|
-
proxyStats.staleEvicted++;
|
|
3827
|
+
evictDeep(oldValue);
|
|
3785
3828
|
}
|
|
3786
3829
|
}
|
|
3787
3830
|
return result;
|
|
@@ -3806,9 +3849,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3806
3849
|
emit?.(event);
|
|
3807
3850
|
trigger(target, prop);
|
|
3808
3851
|
if (isObject3(oldValue)) {
|
|
3809
|
-
|
|
3810
|
-
wrapperCache.delete(oldValue);
|
|
3811
|
-
proxyStats.staleEvicted++;
|
|
3852
|
+
evictDeep(oldValue);
|
|
3812
3853
|
}
|
|
3813
3854
|
}
|
|
3814
3855
|
return result;
|
package/dist/utils.d.ts
CHANGED
|
@@ -22,6 +22,12 @@ export declare function getProxyStats(): {
|
|
|
22
22
|
staleEvicted: number;
|
|
23
23
|
};
|
|
24
24
|
export declare function resetProxyStats(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Recursively evict an object and all its nested children from proxy caches.
|
|
27
|
+
* This allows GC to collect the entire old object tree when a property is
|
|
28
|
+
* replaced, not just the top-level value.
|
|
29
|
+
*/
|
|
30
|
+
export declare function evictDeep(value: any): void;
|
|
25
31
|
export declare function deepEqual(a: any, b: any, seen?: WeakMap<any, any>): boolean;
|
|
26
32
|
export declare function getFromPathCache(root: object, pathKey: string): any | undefined;
|
|
27
33
|
export declare function setInPathCache(root: object, pathKey: string, value: any): void;
|