@yiin/reactive-proxy-state 1.0.41 → 1.0.43

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
@@ -4,39 +4,60 @@ var __defProp = Object.defineProperty;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ function __accessProp(key) {
8
+ return this[key];
9
+ }
10
+ var __toESMCache_node;
11
+ var __toESMCache_esm;
7
12
  var __toESM = (mod, isNodeMode, target) => {
13
+ var canCache = mod != null && typeof mod === "object";
14
+ if (canCache) {
15
+ var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
16
+ var cached = cache.get(mod);
17
+ if (cached)
18
+ return cached;
19
+ }
8
20
  target = mod != null ? __create(__getProtoOf(mod)) : {};
9
21
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
22
  for (let key of __getOwnPropNames(mod))
11
23
  if (!__hasOwnProp.call(to, key))
12
24
  __defProp(to, key, {
13
- get: () => mod[key],
25
+ get: __accessProp.bind(mod, key),
14
26
  enumerable: true
15
27
  });
28
+ if (canCache)
29
+ cache.set(mod, to);
16
30
  return to;
17
31
  };
18
- var __moduleCache = /* @__PURE__ */ new WeakMap;
19
32
  var __toCommonJS = (from) => {
20
- var entry = __moduleCache.get(from), desc;
33
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
21
34
  if (entry)
22
35
  return entry;
23
36
  entry = __defProp({}, "__esModule", { value: true });
24
- if (from && typeof from === "object" || typeof from === "function")
25
- __getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
26
- get: () => from[key],
27
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
28
- }));
37
+ if (from && typeof from === "object" || typeof from === "function") {
38
+ for (var key of __getOwnPropNames(from))
39
+ if (!__hasOwnProp.call(entry, key))
40
+ __defProp(entry, key, {
41
+ get: __accessProp.bind(from, key),
42
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
43
+ });
44
+ }
29
45
  __moduleCache.set(from, entry);
30
46
  return entry;
31
47
  };
48
+ var __moduleCache;
32
49
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
50
+ var __returnValue = (v) => v;
51
+ function __exportSetter(name, newValue) {
52
+ this[name] = __returnValue.bind(null, newValue);
53
+ }
33
54
  var __export = (target, all) => {
34
55
  for (var name in all)
35
56
  __defProp(target, name, {
36
57
  get: all[name],
37
58
  enumerable: true,
38
59
  configurable: true,
39
- set: (newValue) => all[name] = () => newValue
60
+ set: __exportSetter.bind(all, name)
40
61
  });
41
62
  };
42
63
 
@@ -2621,12 +2642,13 @@ function deepClone(value, seen = new WeakMap) {
2621
2642
  if (value instanceof Date) {
2622
2643
  return new Date(value.getTime());
2623
2644
  }
2624
- if (seen.has(value)) {
2625
- return seen.get(value);
2645
+ const identity = toRaw(value);
2646
+ if (seen.has(identity)) {
2647
+ return seen.get(identity);
2626
2648
  }
2627
2649
  if (Array.isArray(value)) {
2628
2650
  const newArray = [];
2629
- seen.set(value, newArray);
2651
+ seen.set(identity, newArray);
2630
2652
  for (let i = 0;i < value.length; i++) {
2631
2653
  newArray[i] = deepClone(value[i], seen);
2632
2654
  }
@@ -2634,7 +2656,7 @@ function deepClone(value, seen = new WeakMap) {
2634
2656
  }
2635
2657
  if (value instanceof Map) {
2636
2658
  const newMap = new Map;
2637
- seen.set(value, newMap);
2659
+ seen.set(identity, newMap);
2638
2660
  value.forEach((val, key) => {
2639
2661
  newMap.set(deepClone(key, seen), deepClone(val, seen));
2640
2662
  });
@@ -2642,14 +2664,14 @@ function deepClone(value, seen = new WeakMap) {
2642
2664
  }
2643
2665
  if (value instanceof Set) {
2644
2666
  const newSet = new Set;
2645
- seen.set(value, newSet);
2667
+ seen.set(identity, newSet);
2646
2668
  value.forEach((val) => {
2647
2669
  newSet.add(deepClone(val, seen));
2648
2670
  });
2649
2671
  return newSet;
2650
2672
  }
2651
2673
  const newObject = Object.create(Object.getPrototypeOf(value));
2652
- seen.set(value, newObject);
2674
+ seen.set(identity, newObject);
2653
2675
  for (const key in value) {
2654
2676
  if (Object.prototype.hasOwnProperty.call(value, key)) {
2655
2677
  newObject[key] = deepClone(value[key], seen);
@@ -2704,6 +2726,10 @@ function validateCachedPath(root, fullPath, pathKey, cached) {
2704
2726
  }
2705
2727
  var actionHandlers = {
2706
2728
  set: function(parent, key, event) {
2729
+ if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
2730
+ console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
2731
+ return;
2732
+ }
2707
2733
  setValue(parent, key, event.newValue);
2708
2734
  },
2709
2735
  delete: function(parent, key) {
@@ -3778,7 +3804,7 @@ function wrapArray(arr, emit, path = []) {
3778
3804
  if (isObject2(value))
3779
3805
  value = unwrapForStore(value);
3780
3806
  const oldValue = target[prop];
3781
- if (oldValue === value)
3807
+ if (oldValue === value && Reflect.has(target, prop))
3782
3808
  return true;
3783
3809
  if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
3784
3810
  return true;
@@ -3786,20 +3812,30 @@ function wrapArray(arr, emit, path = []) {
3786
3812
  const result = Reflect.set(target, prop, value, receiver);
3787
3813
  const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
3788
3814
  if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
3789
- const propKey = String(prop);
3790
- const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
3791
- let newPath = getPathConcat(pathKey);
3792
- if (newPath === undefined) {
3793
- newPath = path.concat(propKey);
3794
- setPathConcat(pathKey, newPath);
3795
- }
3796
- const event = {
3797
- action: "set",
3798
- path: newPath,
3799
- oldValue,
3800
- newValue: isObject2(value) ? deepClone(value) : value
3815
+ const resolvePath = (key) => {
3816
+ const pathKey = path.length > 0 ? `${path.join(".")}.${key}` : key;
3817
+ let newPath = getPathConcat(pathKey);
3818
+ if (newPath === undefined) {
3819
+ newPath = path.concat(key);
3820
+ setPathConcat(pathKey, newPath);
3821
+ }
3822
+ return newPath;
3801
3823
  };
3802
- emit?.(event);
3824
+ if (Array.isArray(target) && prop === "length" && Number(value) > Number(oldValue)) {
3825
+ const oldLength = Number(oldValue);
3826
+ const newLength = Number(value);
3827
+ for (let i = oldLength;i < newLength; i++) {
3828
+ emit?.({ action: "set", path: resolvePath(String(i)), newValue: undefined });
3829
+ }
3830
+ } else {
3831
+ const event = {
3832
+ action: "set",
3833
+ path: resolvePath(String(prop)),
3834
+ oldValue,
3835
+ newValue: isObject2(value) ? deepClone(value) : value
3836
+ };
3837
+ emit?.(event);
3838
+ }
3803
3839
  if (isObject2(oldValue) && oldValue !== value) {
3804
3840
  evictDeep(oldValue);
3805
3841
  }
@@ -4359,9 +4395,6 @@ function diffAndCloneArray(curr, old, pathStack, emit) {
4359
4395
  changed = true;
4360
4396
  result = old.slice();
4361
4397
  }
4362
- pathStack.push("length");
4363
- emit({ action: "set", path: pathStack.slice(), newValue: curr.length, oldValue: old.length });
4364
- pathStack.pop();
4365
4398
  result.length = curr.length;
4366
4399
  for (let i = old.length;i < curr.length; i++) {
4367
4400
  pathStack.push(i);
package/dist/index.js CHANGED
@@ -3,15 +3,29 @@ 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;
6
11
  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
+ }
7
19
  target = mod != null ? __create(__getProtoOf(mod)) : {};
8
20
  const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
9
21
  for (let key of __getOwnPropNames(mod))
10
22
  if (!__hasOwnProp.call(to, key))
11
23
  __defProp(to, key, {
12
- get: () => mod[key],
24
+ get: __accessProp.bind(mod, key),
13
25
  enumerable: true
14
26
  });
27
+ if (canCache)
28
+ cache.set(mod, to);
15
29
  return to;
16
30
  };
17
31
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
@@ -2559,12 +2573,13 @@ function deepClone(value, seen = new WeakMap) {
2559
2573
  if (value instanceof Date) {
2560
2574
  return new Date(value.getTime());
2561
2575
  }
2562
- if (seen.has(value)) {
2563
- return seen.get(value);
2576
+ const identity = toRaw(value);
2577
+ if (seen.has(identity)) {
2578
+ return seen.get(identity);
2564
2579
  }
2565
2580
  if (Array.isArray(value)) {
2566
2581
  const newArray = [];
2567
- seen.set(value, newArray);
2582
+ seen.set(identity, newArray);
2568
2583
  for (let i = 0;i < value.length; i++) {
2569
2584
  newArray[i] = deepClone(value[i], seen);
2570
2585
  }
@@ -2572,7 +2587,7 @@ function deepClone(value, seen = new WeakMap) {
2572
2587
  }
2573
2588
  if (value instanceof Map) {
2574
2589
  const newMap = new Map;
2575
- seen.set(value, newMap);
2590
+ seen.set(identity, newMap);
2576
2591
  value.forEach((val, key) => {
2577
2592
  newMap.set(deepClone(key, seen), deepClone(val, seen));
2578
2593
  });
@@ -2580,14 +2595,14 @@ function deepClone(value, seen = new WeakMap) {
2580
2595
  }
2581
2596
  if (value instanceof Set) {
2582
2597
  const newSet = new Set;
2583
- seen.set(value, newSet);
2598
+ seen.set(identity, newSet);
2584
2599
  value.forEach((val) => {
2585
2600
  newSet.add(deepClone(val, seen));
2586
2601
  });
2587
2602
  return newSet;
2588
2603
  }
2589
2604
  const newObject = Object.create(Object.getPrototypeOf(value));
2590
- seen.set(value, newObject);
2605
+ seen.set(identity, newObject);
2591
2606
  for (const key in value) {
2592
2607
  if (Object.prototype.hasOwnProperty.call(value, key)) {
2593
2608
  newObject[key] = deepClone(value[key], seen);
@@ -2642,6 +2657,10 @@ function validateCachedPath(root, fullPath, pathKey, cached) {
2642
2657
  }
2643
2658
  var actionHandlers = {
2644
2659
  set: function(parent, key, event) {
2660
+ if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
2661
+ console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
2662
+ return;
2663
+ }
2645
2664
  setValue(parent, key, event.newValue);
2646
2665
  },
2647
2666
  delete: function(parent, key) {
@@ -3716,7 +3735,7 @@ function wrapArray(arr, emit, path = []) {
3716
3735
  if (isObject2(value))
3717
3736
  value = unwrapForStore(value);
3718
3737
  const oldValue = target[prop];
3719
- if (oldValue === value)
3738
+ if (oldValue === value && Reflect.has(target, prop))
3720
3739
  return true;
3721
3740
  if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
3722
3741
  return true;
@@ -3724,20 +3743,30 @@ function wrapArray(arr, emit, path = []) {
3724
3743
  const result = Reflect.set(target, prop, value, receiver);
3725
3744
  const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
3726
3745
  if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
3727
- const propKey = String(prop);
3728
- const pathKey = path.length > 0 ? `${path.join(".")}.${propKey}` : propKey;
3729
- let newPath = getPathConcat(pathKey);
3730
- if (newPath === undefined) {
3731
- newPath = path.concat(propKey);
3732
- setPathConcat(pathKey, newPath);
3733
- }
3734
- const event = {
3735
- action: "set",
3736
- path: newPath,
3737
- oldValue,
3738
- newValue: isObject2(value) ? deepClone(value) : value
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;
3739
3754
  };
3740
- emit?.(event);
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
+ }
3741
3770
  if (isObject2(oldValue) && oldValue !== value) {
3742
3771
  evictDeep(oldValue);
3743
3772
  }
@@ -4297,9 +4326,6 @@ function diffAndCloneArray(curr, old, pathStack, emit) {
4297
4326
  changed = true;
4298
4327
  result = old.slice();
4299
4328
  }
4300
- pathStack.push("length");
4301
- emit({ action: "set", path: pathStack.slice(), newValue: curr.length, oldValue: old.length });
4302
- pathStack.pop();
4303
4329
  result.length = curr.length;
4304
4330
  for (let i = old.length;i < curr.length; i++) {
4305
4331
  pathStack.push(i);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yiin/reactive-proxy-state",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "author": "Yiin <stanislovas@yiin.lt>",
5
5
  "repository": {
6
6
  "type": "git",