@yiin/reactive-proxy-state 1.0.37 → 1.0.38

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 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,25 @@ 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
+ }
2371
2392
  function cleanupPathCache(root) {
2372
2393
  const cache = pathCache.get(root);
2373
2394
  if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
@@ -3154,6 +3175,8 @@ function wrapSet(set, emit, path = []) {
3154
3175
  });
3155
3176
  globalSeen.set(set, proxy);
3156
3177
  wrapperCache.set(set, proxy);
3178
+ proxyStats.created++;
3179
+ proxyStats.sets++;
3157
3180
  return proxy;
3158
3181
  }
3159
3182
 
@@ -3395,6 +3418,8 @@ function wrapMap(map, emit, path = []) {
3395
3418
  });
3396
3419
  globalSeen.set(map, proxy);
3397
3420
  wrapperCache.set(map, proxy);
3421
+ proxyStats.created++;
3422
+ proxyStats.maps++;
3398
3423
  return proxy;
3399
3424
  }
3400
3425
 
@@ -3692,6 +3717,8 @@ function wrapArray(arr, emit, path = []) {
3692
3717
  });
3693
3718
  globalSeen.set(arr, proxy);
3694
3719
  wrapperCache.set(arr, proxy);
3720
+ proxyStats.created++;
3721
+ proxyStats.arrays++;
3695
3722
  return proxy;
3696
3723
  }
3697
3724
 
@@ -3813,6 +3840,11 @@ function reactive(obj, emit, path = [], options) {
3813
3840
  };
3814
3841
  emit?.(event);
3815
3842
  trigger(target, prop);
3843
+ if (isObject3(oldValue) && oldValue !== value) {
3844
+ globalSeen.delete(oldValue);
3845
+ wrapperCache.delete(oldValue);
3846
+ proxyStats.staleEvicted++;
3847
+ }
3816
3848
  }
3817
3849
  return result;
3818
3850
  },
@@ -3835,11 +3867,18 @@ function reactive(obj, emit, path = [], options) {
3835
3867
  };
3836
3868
  emit?.(event);
3837
3869
  trigger(target, prop);
3870
+ if (isObject3(oldValue)) {
3871
+ globalSeen.delete(oldValue);
3872
+ wrapperCache.delete(oldValue);
3873
+ proxyStats.staleEvicted++;
3874
+ }
3838
3875
  }
3839
3876
  return result;
3840
3877
  }
3841
3878
  });
3842
3879
  globalSeen.set(obj, proxy);
3880
+ proxyStats.created++;
3881
+ proxyStats.objects++;
3843
3882
  return proxy;
3844
3883
  }
3845
3884
  // src/ref.ts
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './types';
2
- export { deepClone, deepEqual } from './utils';
2
+ export { deepClone, deepEqual, getProxyStats, resetProxyStats } from './utils';
3
3
  export * from './state';
4
4
  export * from './reactive';
5
5
  export * from './watch';
package/dist/index.js CHANGED
@@ -2308,6 +2308,25 @@ 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
+ }
2311
2330
  function cleanupPathCache(root) {
2312
2331
  const cache = pathCache.get(root);
2313
2332
  if (cache && pathCacheSize.get(root) > MAX_CACHE_SIZE) {
@@ -3094,6 +3113,8 @@ function wrapSet(set, emit, path = []) {
3094
3113
  });
3095
3114
  globalSeen.set(set, proxy);
3096
3115
  wrapperCache.set(set, proxy);
3116
+ proxyStats.created++;
3117
+ proxyStats.sets++;
3097
3118
  return proxy;
3098
3119
  }
3099
3120
 
@@ -3335,6 +3356,8 @@ function wrapMap(map, emit, path = []) {
3335
3356
  });
3336
3357
  globalSeen.set(map, proxy);
3337
3358
  wrapperCache.set(map, proxy);
3359
+ proxyStats.created++;
3360
+ proxyStats.maps++;
3338
3361
  return proxy;
3339
3362
  }
3340
3363
 
@@ -3632,6 +3655,8 @@ function wrapArray(arr, emit, path = []) {
3632
3655
  });
3633
3656
  globalSeen.set(arr, proxy);
3634
3657
  wrapperCache.set(arr, proxy);
3658
+ proxyStats.created++;
3659
+ proxyStats.arrays++;
3635
3660
  return proxy;
3636
3661
  }
3637
3662
 
@@ -3753,6 +3778,11 @@ function reactive(obj, emit, path = [], options) {
3753
3778
  };
3754
3779
  emit?.(event);
3755
3780
  trigger(target, prop);
3781
+ if (isObject3(oldValue) && oldValue !== value) {
3782
+ globalSeen.delete(oldValue);
3783
+ wrapperCache.delete(oldValue);
3784
+ proxyStats.staleEvicted++;
3785
+ }
3756
3786
  }
3757
3787
  return result;
3758
3788
  },
@@ -3775,11 +3805,18 @@ function reactive(obj, emit, path = [], options) {
3775
3805
  };
3776
3806
  emit?.(event);
3777
3807
  trigger(target, prop);
3808
+ if (isObject3(oldValue)) {
3809
+ globalSeen.delete(oldValue);
3810
+ wrapperCache.delete(oldValue);
3811
+ proxyStats.staleEvicted++;
3812
+ }
3778
3813
  }
3779
3814
  return result;
3780
3815
  }
3781
3816
  });
3782
3817
  globalSeen.set(obj, proxy);
3818
+ proxyStats.created++;
3819
+ proxyStats.objects++;
3783
3820
  return proxy;
3784
3821
  }
3785
3822
  // src/ref.ts
@@ -4413,6 +4450,7 @@ export {
4413
4450
  toRaw,
4414
4451
  setActiveEffect,
4415
4452
  runCleanupFunctions,
4453
+ resetProxyStats,
4416
4454
  ref,
4417
4455
  reactive,
4418
4456
  markRaw,
@@ -4420,6 +4458,7 @@ export {
4420
4458
  isRef,
4421
4459
  isReactive,
4422
4460
  isComputed,
4461
+ getProxyStats,
4423
4462
  deepToRaw,
4424
4463
  deepEqual,
4425
4464
  deepClone,
package/dist/utils.d.ts CHANGED
@@ -2,6 +2,26 @@ 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;
5
25
  export declare function deepEqual(a: any, b: any, seen?: WeakMap<any, any>): boolean;
6
26
  export declare function getFromPathCache(root: object, pathKey: string): any | undefined;
7
27
  export declare function setInPathCache(root: object, pathKey: string, value: any): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiin/reactive-proxy-state",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "author": "Yiin <stanislovas@yiin.lt>",
5
5
  "repository": {
6
6
  "type": "git",