@yiin/reactive-proxy-state 1.0.40 → 1.0.42
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 +30 -19
- package/dist/index.js +30 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2704,6 +2704,10 @@ function validateCachedPath(root, fullPath, pathKey, cached) {
|
|
|
2704
2704
|
}
|
|
2705
2705
|
var actionHandlers = {
|
|
2706
2706
|
set: function(parent, key, event) {
|
|
2707
|
+
if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
|
|
2708
|
+
console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
|
|
2709
|
+
return;
|
|
2710
|
+
}
|
|
2707
2711
|
setValue(parent, key, event.newValue);
|
|
2708
2712
|
},
|
|
2709
2713
|
delete: function(parent, key) {
|
|
@@ -3295,7 +3299,7 @@ function wrapMap(map, emit, path = []) {
|
|
|
3295
3299
|
path: cachedPath,
|
|
3296
3300
|
key,
|
|
3297
3301
|
oldValue,
|
|
3298
|
-
newValue: value2
|
|
3302
|
+
newValue: value2 !== null && typeof value2 === "object" ? deepClone(value2) : value2
|
|
3299
3303
|
};
|
|
3300
3304
|
emit?.(event);
|
|
3301
3305
|
if (!existed) {
|
|
@@ -3778,7 +3782,7 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3778
3782
|
if (isObject2(value))
|
|
3779
3783
|
value = unwrapForStore(value);
|
|
3780
3784
|
const oldValue = target[prop];
|
|
3781
|
-
if (oldValue === value)
|
|
3785
|
+
if (oldValue === value && Reflect.has(target, prop))
|
|
3782
3786
|
return true;
|
|
3783
3787
|
if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
|
|
3784
3788
|
return true;
|
|
@@ -3786,20 +3790,30 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3786
3790
|
const result = Reflect.set(target, prop, value, receiver);
|
|
3787
3791
|
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
|
|
3788
3792
|
if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
|
|
3789
|
-
const
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
action: "set",
|
|
3798
|
-
path: newPath,
|
|
3799
|
-
oldValue,
|
|
3800
|
-
newValue: value
|
|
3793
|
+
const resolvePath = (key) => {
|
|
3794
|
+
const pathKey = path.length > 0 ? `${path.join(".")}.${key}` : key;
|
|
3795
|
+
let newPath = getPathConcat(pathKey);
|
|
3796
|
+
if (newPath === undefined) {
|
|
3797
|
+
newPath = path.concat(key);
|
|
3798
|
+
setPathConcat(pathKey, newPath);
|
|
3799
|
+
}
|
|
3800
|
+
return newPath;
|
|
3801
3801
|
};
|
|
3802
|
-
|
|
3802
|
+
if (Array.isArray(target) && prop === "length" && Number(value) > Number(oldValue)) {
|
|
3803
|
+
const oldLength = Number(oldValue);
|
|
3804
|
+
const newLength = Number(value);
|
|
3805
|
+
for (let i = oldLength;i < newLength; i++) {
|
|
3806
|
+
emit?.({ action: "set", path: resolvePath(String(i)), newValue: undefined });
|
|
3807
|
+
}
|
|
3808
|
+
} else {
|
|
3809
|
+
const event = {
|
|
3810
|
+
action: "set",
|
|
3811
|
+
path: resolvePath(String(prop)),
|
|
3812
|
+
oldValue,
|
|
3813
|
+
newValue: isObject2(value) ? deepClone(value) : value
|
|
3814
|
+
};
|
|
3815
|
+
emit?.(event);
|
|
3816
|
+
}
|
|
3803
3817
|
if (isObject2(oldValue) && oldValue !== value) {
|
|
3804
3818
|
evictDeep(oldValue);
|
|
3805
3819
|
}
|
|
@@ -3927,7 +3941,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3927
3941
|
action: "set",
|
|
3928
3942
|
path: newPath,
|
|
3929
3943
|
oldValue,
|
|
3930
|
-
newValue: value
|
|
3944
|
+
newValue: isObject3(value) ? deepClone(value) : value
|
|
3931
3945
|
};
|
|
3932
3946
|
emit?.(event);
|
|
3933
3947
|
trigger(target, prop);
|
|
@@ -4359,9 +4373,6 @@ function diffAndCloneArray(curr, old, pathStack, emit) {
|
|
|
4359
4373
|
changed = true;
|
|
4360
4374
|
result = old.slice();
|
|
4361
4375
|
}
|
|
4362
|
-
pathStack.push("length");
|
|
4363
|
-
emit({ action: "set", path: pathStack.slice(), newValue: curr.length, oldValue: old.length });
|
|
4364
|
-
pathStack.pop();
|
|
4365
4376
|
result.length = curr.length;
|
|
4366
4377
|
for (let i = old.length;i < curr.length; i++) {
|
|
4367
4378
|
pathStack.push(i);
|
package/dist/index.js
CHANGED
|
@@ -2642,6 +2642,10 @@ function validateCachedPath(root, fullPath, pathKey, cached) {
|
|
|
2642
2642
|
}
|
|
2643
2643
|
var actionHandlers = {
|
|
2644
2644
|
set: function(parent, key, event) {
|
|
2645
|
+
if (Array.isArray(parent) && key === "length" && Number(event.newValue) > parent.length) {
|
|
2646
|
+
console.warn(`refusing to grow array length via bare set at path ${event.path.join(".")}`);
|
|
2647
|
+
return;
|
|
2648
|
+
}
|
|
2645
2649
|
setValue(parent, key, event.newValue);
|
|
2646
2650
|
},
|
|
2647
2651
|
delete: function(parent, key) {
|
|
@@ -3233,7 +3237,7 @@ function wrapMap(map, emit, path = []) {
|
|
|
3233
3237
|
path: cachedPath,
|
|
3234
3238
|
key,
|
|
3235
3239
|
oldValue,
|
|
3236
|
-
newValue: value2
|
|
3240
|
+
newValue: value2 !== null && typeof value2 === "object" ? deepClone(value2) : value2
|
|
3237
3241
|
};
|
|
3238
3242
|
emit?.(event);
|
|
3239
3243
|
if (!existed) {
|
|
@@ -3716,7 +3720,7 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3716
3720
|
if (isObject2(value))
|
|
3717
3721
|
value = unwrapForStore(value);
|
|
3718
3722
|
const oldValue = target[prop];
|
|
3719
|
-
if (oldValue === value)
|
|
3723
|
+
if (oldValue === value && Reflect.has(target, prop))
|
|
3720
3724
|
return true;
|
|
3721
3725
|
if (isObject2(oldValue) && isObject2(value) && deepEqual(oldValue, value, new WeakMap))
|
|
3722
3726
|
return true;
|
|
@@ -3724,20 +3728,30 @@ function wrapArray(arr, emit, path = []) {
|
|
|
3724
3728
|
const result = Reflect.set(target, prop, value, receiver);
|
|
3725
3729
|
const isNumericIndex = typeof prop === "number" || typeof prop === "string" && !isNaN(parseInt(String(prop)));
|
|
3726
3730
|
if (result && (!descriptor || !descriptor.set || isNumericIndex)) {
|
|
3727
|
-
const
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
action: "set",
|
|
3736
|
-
path: newPath,
|
|
3737
|
-
oldValue,
|
|
3738
|
-
newValue: value
|
|
3731
|
+
const resolvePath = (key) => {
|
|
3732
|
+
const pathKey = path.length > 0 ? `${path.join(".")}.${key}` : key;
|
|
3733
|
+
let newPath = getPathConcat(pathKey);
|
|
3734
|
+
if (newPath === undefined) {
|
|
3735
|
+
newPath = path.concat(key);
|
|
3736
|
+
setPathConcat(pathKey, newPath);
|
|
3737
|
+
}
|
|
3738
|
+
return newPath;
|
|
3739
3739
|
};
|
|
3740
|
-
|
|
3740
|
+
if (Array.isArray(target) && prop === "length" && Number(value) > Number(oldValue)) {
|
|
3741
|
+
const oldLength = Number(oldValue);
|
|
3742
|
+
const newLength = Number(value);
|
|
3743
|
+
for (let i = oldLength;i < newLength; i++) {
|
|
3744
|
+
emit?.({ action: "set", path: resolvePath(String(i)), newValue: undefined });
|
|
3745
|
+
}
|
|
3746
|
+
} else {
|
|
3747
|
+
const event = {
|
|
3748
|
+
action: "set",
|
|
3749
|
+
path: resolvePath(String(prop)),
|
|
3750
|
+
oldValue,
|
|
3751
|
+
newValue: isObject2(value) ? deepClone(value) : value
|
|
3752
|
+
};
|
|
3753
|
+
emit?.(event);
|
|
3754
|
+
}
|
|
3741
3755
|
if (isObject2(oldValue) && oldValue !== value) {
|
|
3742
3756
|
evictDeep(oldValue);
|
|
3743
3757
|
}
|
|
@@ -3865,7 +3879,7 @@ function reactive(obj, emit, path = [], options) {
|
|
|
3865
3879
|
action: "set",
|
|
3866
3880
|
path: newPath,
|
|
3867
3881
|
oldValue,
|
|
3868
|
-
newValue: value
|
|
3882
|
+
newValue: isObject3(value) ? deepClone(value) : value
|
|
3869
3883
|
};
|
|
3870
3884
|
emit?.(event);
|
|
3871
3885
|
trigger(target, prop);
|
|
@@ -4297,9 +4311,6 @@ function diffAndCloneArray(curr, old, pathStack, emit) {
|
|
|
4297
4311
|
changed = true;
|
|
4298
4312
|
result = old.slice();
|
|
4299
4313
|
}
|
|
4300
|
-
pathStack.push("length");
|
|
4301
|
-
emit({ action: "set", path: pathStack.slice(), newValue: curr.length, oldValue: old.length });
|
|
4302
|
-
pathStack.pop();
|
|
4303
4314
|
result.length = curr.length;
|
|
4304
4315
|
for (let i = old.length;i < curr.length; i++) {
|
|
4305
4316
|
pathStack.push(i);
|