@whitesev/utils 2.9.6 → 2.9.8

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 CHANGED
@@ -312,38 +312,44 @@ define((function () { 'use strict';
312
312
  if (target == null) {
313
313
  target = {};
314
314
  }
315
+ // 当前遍历的目标对象
316
+ let iteratorTarget;
315
317
  if (isAdd) {
316
- for (const sourceKeyName in source) {
317
- const targetKeyName = sourceKeyName;
318
- const targetValue = Reflect.get(target, targetKeyName);
319
- const sourceValue = Reflect.get(source, sourceKeyName);
320
- if (typeof sourceValue === "object" &&
321
- sourceValue != null &&
322
- sourceKeyName in target &&
323
- !UtilsContext.isDOM(sourceValue)) {
324
- /* 源端的值是object类型,且不是元素节点 */
325
- Reflect.set(target, sourceKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
326
- continue;
327
- }
328
- Reflect.set(target, sourceKeyName, sourceValue);
329
- }
318
+ // 追加并覆盖是以source为准
319
+ iteratorTarget = source;
330
320
  }
331
321
  else {
332
- for (const targetKeyName in target) {
333
- if (targetKeyName in source) {
334
- const targetValue = Reflect.get(target, targetKeyName);
335
- const sourceValue = Reflect.get(source, targetKeyName);
336
- if (typeof sourceValue === "object" &&
337
- sourceValue != null &&
338
- !UtilsContext.isDOM(sourceValue) &&
339
- Object.keys(sourceValue).length) {
340
- /* 源端的值是object类型,且不是元素节点 */
341
- Reflect.set(target, targetKeyName, UtilsContext.assign(targetValue, sourceValue, isAdd));
342
- continue;
322
+ // 覆盖以target为准
323
+ iteratorTarget = target;
324
+ }
325
+ for (const keyName in iteratorTarget) {
326
+ if (!isAdd && !(keyName in source)) {
327
+ // 仅替换 但是源端没有此键
328
+ continue;
329
+ }
330
+ const targetValue = Reflect.get(target, keyName);
331
+ const sourceValue = Reflect.get(source, keyName);
332
+ if (typeof sourceValue === "object" &&
333
+ sourceValue != null &&
334
+ keyName in target &&
335
+ !UtilsContext.isDOM(sourceValue)) {
336
+ // 源端的值是object类型,且不是元素节点
337
+ // 如果是数组,那此数组中有值,清空旧的数组再赋值
338
+ let childObjectValue;
339
+ if (Array.isArray(sourceValue)) {
340
+ if (Array.isArray(targetValue)) {
341
+ targetValue.length = 0;
343
342
  }
344
- /* 直接赋值 */
345
- Reflect.set(target, targetKeyName, sourceValue);
343
+ childObjectValue = sourceValue;
346
344
  }
345
+ else {
346
+ childObjectValue = UtilsContext.assign(targetValue, sourceValue, isAdd);
347
+ }
348
+ Reflect.set(target, keyName, childObjectValue);
349
+ }
350
+ else {
351
+ /* 直接赋值 */
352
+ Reflect.set(target, keyName, sourceValue);
347
353
  }
348
354
  }
349
355
  return target;
@@ -440,6 +446,9 @@ define((function () { 'use strict';
440
446
  }
441
447
  toJSON(data, errorCallBack) {
442
448
  let result = {};
449
+ if (data == null) {
450
+ return result;
451
+ }
443
452
  if (typeof data === "object") {
444
453
  return data;
445
454
  }
@@ -5492,7 +5501,7 @@ define((function () { 'use strict';
5492
5501
  }
5493
5502
  const domUtils = new DOMUtils();
5494
5503
 
5495
- const version = "2.9.6";
5504
+ const version = "2.9.8";
5496
5505
 
5497
5506
  class Utils {
5498
5507
  windowApi;
@@ -8030,7 +8039,7 @@ define((function () { 'use strict';
8030
8039
  }
8031
8040
  }
8032
8041
  /**
8033
- * 深度获取对象属性
8042
+ * 深度获取对象的某个属性
8034
8043
  * @param target 待获取的对象
8035
8044
  * @param handler 获取属性的回调
8036
8045
  */