@whitesev/utils 2.9.6 → 2.9.7
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.amd.js +34 -28
- package/dist/index.amd.js.map +1 -1
- package/dist/index.amd.min.js +1 -1
- package/dist/index.amd.min.js.map +1 -1
- package/dist/index.cjs.js +34 -28
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.cjs.min.js +1 -1
- package/dist/index.cjs.min.js.map +1 -1
- package/dist/index.esm.js +34 -28
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +34 -28
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.system.js +34 -28
- package/dist/index.system.js.map +1 -1
- package/dist/index.system.min.js +1 -1
- package/dist/index.system.min.js.map +1 -1
- package/dist/index.umd.js +34 -28
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/CommonUtil.ts +33 -31
package/package.json
CHANGED
package/src/CommonUtil.ts
CHANGED
|
@@ -33,41 +33,43 @@ class CommonUtil {
|
|
|
33
33
|
if (target == null) {
|
|
34
34
|
target = {};
|
|
35
35
|
}
|
|
36
|
+
// 当前遍历的目标对象
|
|
37
|
+
let iteratorTarget;
|
|
36
38
|
if (isAdd) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const targetValue = Reflect.get(target, targetKeyName);
|
|
40
|
-
const sourceValue = Reflect.get(source, sourceKeyName);
|
|
41
|
-
if (
|
|
42
|
-
typeof sourceValue === "object" &&
|
|
43
|
-
sourceValue != null &&
|
|
44
|
-
sourceKeyName in target &&
|
|
45
|
-
!UtilsContext.isDOM(sourceValue)
|
|
46
|
-
) {
|
|
47
|
-
/* 源端的值是object类型,且不是元素节点 */
|
|
48
|
-
Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
Reflect.set(target, sourceKeyName, sourceValue);
|
|
52
|
-
}
|
|
39
|
+
// 追加并覆盖是以source为准
|
|
40
|
+
iteratorTarget = source;
|
|
53
41
|
} else {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
42
|
+
// 覆盖以target为准
|
|
43
|
+
iteratorTarget = target;
|
|
44
|
+
}
|
|
45
|
+
for (const keyName in iteratorTarget) {
|
|
46
|
+
if (!isAdd && !(keyName in source)) {
|
|
47
|
+
// 仅替换 但是源端没有此键
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const targetValue = Reflect.get(target, keyName);
|
|
51
|
+
const sourceValue = Reflect.get(source, keyName);
|
|
52
|
+
if (
|
|
53
|
+
typeof sourceValue === "object" &&
|
|
54
|
+
sourceValue != null &&
|
|
55
|
+
keyName in target &&
|
|
56
|
+
!UtilsContext.isDOM(sourceValue)
|
|
57
|
+
) {
|
|
58
|
+
// 源端的值是object类型,且不是元素节点
|
|
59
|
+
// 如果是数组,那此数组中有值,清空旧的数组再赋值
|
|
60
|
+
let childObjectValue;
|
|
61
|
+
if (Array.isArray(sourceValue)) {
|
|
62
|
+
if (Array.isArray(targetValue)) {
|
|
63
|
+
targetValue.length = 0;
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
childObjectValue = sourceValue;
|
|
66
|
+
} else {
|
|
67
|
+
childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
|
|
70
68
|
}
|
|
69
|
+
Reflect.set(target, keyName, childObjectValue);
|
|
70
|
+
} else {
|
|
71
|
+
/* 直接赋值 */
|
|
72
|
+
Reflect.set(target, keyName, sourceValue);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
75
|
|