@yiin/reactive-proxy-state 1.0.37 → 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 +80 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +80 -0
- package/dist/utils.d.ts +26 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2340,6 +2340,7 @@ __export(exports_src, {
|
|
|
2340
2340
|
toRaw: () => toRaw,
|
|
2341
2341
|
setActiveEffect: () => setActiveEffect,
|
|
2342
2342
|
runCleanupFunctions: () => runCleanupFunctions,
|
|
2343
|
+
resetProxyStats: () => resetProxyStats,
|
|
2343
2344
|
ref: () => ref,
|
|
2344
2345
|
reactive: () => reactive,
|
|
2345
2346
|
markRaw: () => markRaw,
|
|
@@ -2347,6 +2348,7 @@ __export(exports_src, {
|
|
|
2347
2348
|
isRef: () => isRef,
|
|
2348
2349
|
isReactive: () => isReactive,
|
|
2349
2350
|
isComputed: () => isComputed,
|
|
2351
|
+
getProxyStats: () => getProxyStats,
|
|
2350
2352
|
deepToRaw: () => deepToRaw,
|
|
2351
2353
|
deepEqual: () => deepEqual,
|
|
2352
2354
|
deepClone: () => deepClone,
|
|
@@ -2368,6 +2370,59 @@ var pathConcatCache = new Map;
|
|
|
2368
2370
|
var MAX_PATH_CACHE_SIZE = 1000;
|
|
2369
2371
|
var globalSeen = new WeakMap;
|
|
2370
2372
|
var wrapperCache = new WeakMap;
|
|
2373
|
+
var proxyStats = {
|
|
2374
|
+
created: 0,
|
|
2375
|
+
arrays: 0,
|
|
2376
|
+
maps: 0,
|
|
2377
|
+
sets: 0,
|
|
2378
|
+
objects: 0,
|
|
2379
|
+
staleEvicted: 0
|
|
2380
|
+
};
|
|
2381
|
+
function getProxyStats() {
|
|
2382
|
+
return { ...proxyStats, pathConcatCacheSize: pathConcatCache.size };
|
|
2383
|
+
}
|
|
2384
|
+
function resetProxyStats() {
|
|
2385
|
+
proxyStats.created = 0;
|
|
2386
|
+
proxyStats.arrays = 0;
|
|
2387
|
+
proxyStats.maps = 0;
|
|
2388
|
+
proxyStats.sets = 0;
|
|
2389
|
+
proxyStats.objects = 0;
|
|
2390
|
+
proxyStats.staleEvicted = 0;
|
|
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
|
+
}
|
|
2371
2426
|
function cleanupPathCache(root) {
|
|
2372
2427
|
const cache = pathCache.get(root);
|
|
2373
2428
|
if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
|
|
@@ -3154,6 +3209,8 @@ function wrapSet(set, emit, path = []) {
|
|
|
3154
3209
|
});
|
|
3155
3210
|
globalSeen.set(set, proxy);
|
|
3156
3211
|
wrapperCache.set(set, proxy);
|
|
3212
|
+
proxyStats.created++;
|
|
3213
|
+
proxyStats.sets++;
|
|
3157
3214
|
return proxy;
|
|
3158
3215
|
}
|
|
3159
3216
|
|
|
@@ -3395,6 +3452,8 @@ function wrapMap(map, emit, path = []) {
|
|
|
3395
3452
|
});
|
|
3396
3453
|
globalSeen.set(map, proxy);
|
|
3397
3454
|
wrapperCache.set(map, proxy);
|
|
3455
|
+
proxyStats.created++;
|
|
3456
|
+
proxyStats.maps++;
|
|
3398
3457
|
return proxy;
|
|
3399
3458
|
}
|
|
3400
3459
|
|
|
@@ -3455,6 +3514,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3455
3514
|
oldValue
|
|
3456
3515
|
};
|
|
3457
3516
|
emit?.(event);
|
|
3517
|
+
if (isObject2(oldValue))
|
|
3518
|
+
evictDeep(oldValue);
|
|
3458
3519
|
trigger(target, Symbol.iterator);
|
|
3459
3520
|
if (oldLength !== newLength) {
|
|
3460
3521
|
trigger(target, "length");
|
|
@@ -3478,6 +3539,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3478
3539
|
oldValue
|
|
3479
3540
|
};
|
|
3480
3541
|
emit?.(event);
|
|
3542
|
+
if (isObject2(oldValue))
|
|
3543
|
+
evictDeep(oldValue);
|
|
3481
3544
|
trigger(target, Symbol.iterator);
|
|
3482
3545
|
if (oldLength !== newLength) {
|
|
3483
3546
|
trigger(target, "length");
|
|
@@ -3527,6 +3590,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3527
3590
|
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3528
3591
|
};
|
|
3529
3592
|
emit?.(event);
|
|
3593
|
+
for (let i = 0;i < deletedItems.length; i++) {
|
|
3594
|
+
if (isObject2(deletedItems[i]))
|
|
3595
|
+
evictDeep(deletedItems[i]);
|
|
3596
|
+
}
|
|
3530
3597
|
trigger(target, Symbol.iterator);
|
|
3531
3598
|
if (oldLength !== newLength) {
|
|
3532
3599
|
trigger(target, "length");
|
|
@@ -3685,6 +3752,9 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3685
3752
|
newValue: value
|
|
3686
3753
|
};
|
|
3687
3754
|
emit?.(event);
|
|
3755
|
+
if (isObject2(oldValue) && oldValue !== value) {
|
|
3756
|
+
evictDeep(oldValue);
|
|
3757
|
+
}
|
|
3688
3758
|
trigger(target, prop);
|
|
3689
3759
|
}
|
|
3690
3760
|
return result;
|
|
@@ -3692,6 +3762,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3692
3762
|
});
|
|
3693
3763
|
globalSeen.set(arr, proxy);
|
|
3694
3764
|
wrapperCache.set(arr, proxy);
|
|
3765
|
+
proxyStats.created++;
|
|
3766
|
+
proxyStats.arrays++;
|
|
3695
3767
|
return proxy;
|
|
3696
3768
|
}
|
|
3697
3769
|
|
|
@@ -3813,6 +3885,9 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3813
3885
|
};
|
|
3814
3886
|
emit?.(event);
|
|
3815
3887
|
trigger(target, prop);
|
|
3888
|
+
if (isObject3(oldValue) && oldValue !== value) {
|
|
3889
|
+
evictDeep(oldValue);
|
|
3890
|
+
}
|
|
3816
3891
|
}
|
|
3817
3892
|
return result;
|
|
3818
3893
|
},
|
|
@@ -3835,11 +3910,16 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3835
3910
|
};
|
|
3836
3911
|
emit?.(event);
|
|
3837
3912
|
trigger(target, prop);
|
|
3913
|
+
if (isObject3(oldValue)) {
|
|
3914
|
+
evictDeep(oldValue);
|
|
3915
|
+
}
|
|
3838
3916
|
}
|
|
3839
3917
|
return result;
|
|
3840
3918
|
}
|
|
3841
3919
|
});
|
|
3842
3920
|
globalSeen.set(obj, proxy);
|
|
3921
|
+
proxyStats.created++;
|
|
3922
|
+
proxyStats.objects++;
|
|
3843
3923
|
return proxy;
|
|
3844
3924
|
}
|
|
3845
3925
|
// src/ref.ts
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2308,6 +2308,59 @@ var pathConcatCache = new Map;
|
|
|
2308
2308
|
var MAX_PATH_CACHE_SIZE = 1000;
|
|
2309
2309
|
var globalSeen = new WeakMap;
|
|
2310
2310
|
var wrapperCache = new WeakMap;
|
|
2311
|
+
var proxyStats = {
|
|
2312
|
+
created: 0,
|
|
2313
|
+
arrays: 0,
|
|
2314
|
+
maps: 0,
|
|
2315
|
+
sets: 0,
|
|
2316
|
+
objects: 0,
|
|
2317
|
+
staleEvicted: 0
|
|
2318
|
+
};
|
|
2319
|
+
function getProxyStats() {
|
|
2320
|
+
return { ...proxyStats, pathConcatCacheSize: pathConcatCache.size };
|
|
2321
|
+
}
|
|
2322
|
+
function resetProxyStats() {
|
|
2323
|
+
proxyStats.created = 0;
|
|
2324
|
+
proxyStats.arrays = 0;
|
|
2325
|
+
proxyStats.maps = 0;
|
|
2326
|
+
proxyStats.sets = 0;
|
|
2327
|
+
proxyStats.objects = 0;
|
|
2328
|
+
proxyStats.staleEvicted = 0;
|
|
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
|
+
}
|
|
2311
2364
|
function cleanupPathCache(root) {
|
|
2312
2365
|
const cache = pathCache.get(root);
|
|
2313
2366
|
if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
|
|
@@ -3094,6 +3147,8 @@ function wrapSet(set, emit, path = []) {
|
|
|
3094
3147
|
});
|
|
3095
3148
|
globalSeen.set(set, proxy);
|
|
3096
3149
|
wrapperCache.set(set, proxy);
|
|
3150
|
+
proxyStats.created++;
|
|
3151
|
+
proxyStats.sets++;
|
|
3097
3152
|
return proxy;
|
|
3098
3153
|
}
|
|
3099
3154
|
|
|
@@ -3335,6 +3390,8 @@ function wrapMap(map, emit, path = []) {
|
|
|
3335
3390
|
});
|
|
3336
3391
|
globalSeen.set(map, proxy);
|
|
3337
3392
|
wrapperCache.set(map, proxy);
|
|
3393
|
+
proxyStats.created++;
|
|
3394
|
+
proxyStats.maps++;
|
|
3338
3395
|
return proxy;
|
|
3339
3396
|
}
|
|
3340
3397
|
|
|
@@ -3395,6 +3452,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3395
3452
|
oldValue
|
|
3396
3453
|
};
|
|
3397
3454
|
emit?.(event);
|
|
3455
|
+
if (isObject2(oldValue))
|
|
3456
|
+
evictDeep(oldValue);
|
|
3398
3457
|
trigger(target, Symbol.iterator);
|
|
3399
3458
|
if (oldLength !== newLength) {
|
|
3400
3459
|
trigger(target, "length");
|
|
@@ -3418,6 +3477,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3418
3477
|
oldValue
|
|
3419
3478
|
};
|
|
3420
3479
|
emit?.(event);
|
|
3480
|
+
if (isObject2(oldValue))
|
|
3481
|
+
evictDeep(oldValue);
|
|
3421
3482
|
trigger(target, Symbol.iterator);
|
|
3422
3483
|
if (oldLength !== newLength) {
|
|
3423
3484
|
trigger(target, "length");
|
|
@@ -3467,6 +3528,10 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3467
3528
|
oldValues: deletedItems.length > 0 ? deletedItems : undefined
|
|
3468
3529
|
};
|
|
3469
3530
|
emit?.(event);
|
|
3531
|
+
for (let i = 0;i < deletedItems.length; i++) {
|
|
3532
|
+
if (isObject2(deletedItems[i]))
|
|
3533
|
+
evictDeep(deletedItems[i]);
|
|
3534
|
+
}
|
|
3470
3535
|
trigger(target, Symbol.iterator);
|
|
3471
3536
|
if (oldLength !== newLength) {
|
|
3472
3537
|
trigger(target, "length");
|
|
@@ -3625,6 +3690,9 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3625
3690
|
newValue: value
|
|
3626
3691
|
};
|
|
3627
3692
|
emit?.(event);
|
|
3693
|
+
if (isObject2(oldValue) && oldValue !== value) {
|
|
3694
|
+
evictDeep(oldValue);
|
|
3695
|
+
}
|
|
3628
3696
|
trigger(target, prop);
|
|
3629
3697
|
}
|
|
3630
3698
|
return result;
|
|
@@ -3632,6 +3700,8 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3632
3700
|
});
|
|
3633
3701
|
globalSeen.set(arr, proxy);
|
|
3634
3702
|
wrapperCache.set(arr, proxy);
|
|
3703
|
+
proxyStats.created++;
|
|
3704
|
+
proxyStats.arrays++;
|
|
3635
3705
|
return proxy;
|
|
3636
3706
|
}
|
|
3637
3707
|
|
|
@@ -3753,6 +3823,9 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3753
3823
|
};
|
|
3754
3824
|
emit?.(event);
|
|
3755
3825
|
trigger(target, prop);
|
|
3826
|
+
if (isObject3(oldValue) && oldValue !== value) {
|
|
3827
|
+
evictDeep(oldValue);
|
|
3828
|
+
}
|
|
3756
3829
|
}
|
|
3757
3830
|
return result;
|
|
3758
3831
|
},
|
|
@@ -3775,11 +3848,16 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3775
3848
|
};
|
|
3776
3849
|
emit?.(event);
|
|
3777
3850
|
trigger(target, prop);
|
|
3851
|
+
if (isObject3(oldValue)) {
|
|
3852
|
+
evictDeep(oldValue);
|
|
3853
|
+
}
|
|
3778
3854
|
}
|
|
3779
3855
|
return result;
|
|
3780
3856
|
}
|
|
3781
3857
|
});
|
|
3782
3858
|
globalSeen.set(obj, proxy);
|
|
3859
|
+
proxyStats.created++;
|
|
3860
|
+
proxyStats.objects++;
|
|
3783
3861
|
return proxy;
|
|
3784
3862
|
}
|
|
3785
3863
|
// src/ref.ts
|
|
@@ -4413,6 +4491,7 @@ export {
|
|
|
4413
4491
|
toRaw,
|
|
4414
4492
|
setActiveEffect,
|
|
4415
4493
|
runCleanupFunctions,
|
|
4494
|
+
resetProxyStats,
|
|
4416
4495
|
ref,
|
|
4417
4496
|
reactive,
|
|
4418
4497
|
markRaw,
|
|
@@ -4420,6 +4499,7 @@ export {
|
|
|
4420
4499
|
isRef,
|
|
4421
4500
|
isReactive,
|
|
4422
4501
|
isComputed,
|
|
4502
|
+
getProxyStats,
|
|
4423
4503
|
deepToRaw,
|
|
4424
4504
|
deepEqual,
|
|
4425
4505
|
deepClone,
|
package/dist/utils.d.ts
CHANGED
|
@@ -2,6 +2,32 @@ export declare const pathCache: WeakMap<object, Map<string, any>>;
|
|
|
2
2
|
export declare const pathConcatCache: Map<string, any[]>;
|
|
3
3
|
export declare const globalSeen: WeakMap<any, any>;
|
|
4
4
|
export declare const wrapperCache: WeakMap<object, object>;
|
|
5
|
+
export declare const proxyStats: {
|
|
6
|
+
created: number;
|
|
7
|
+
arrays: number;
|
|
8
|
+
maps: number;
|
|
9
|
+
sets: number;
|
|
10
|
+
objects: number;
|
|
11
|
+
/** Number of old proxied values evicted when replaced via set trap */
|
|
12
|
+
staleEvicted: number;
|
|
13
|
+
};
|
|
14
|
+
export declare function getProxyStats(): {
|
|
15
|
+
pathConcatCacheSize: number;
|
|
16
|
+
created: number;
|
|
17
|
+
arrays: number;
|
|
18
|
+
maps: number;
|
|
19
|
+
sets: number;
|
|
20
|
+
objects: number;
|
|
21
|
+
/** Number of old proxied values evicted when replaced via set trap */
|
|
22
|
+
staleEvicted: number;
|
|
23
|
+
};
|
|
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;
|
|
5
31
|
export declare function deepEqual(a: any, b: any, seen?: WeakMap<any, any>): boolean;
|
|
6
32
|
export declare function getFromPathCache(root: object, pathKey: string): any | undefined;
|
|
7
33
|
export declare function setInPathCache(root: object, pathKey: string, value: any): void;
|