From e960ac6419bcf125aef9299048b95d013829c46e Mon Sep 17 00:00:00 2001 From: xingyu Date: Mon, 19 Jun 2023 11:14:38 +0800 Subject: [PATCH] fix: deepMerge --- src/utils/index.ts | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 01bfedf..b3d5f81 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -58,26 +58,26 @@ export function deepMerge { + if (isArray(targetValue) && isArray(sourceValue)) { + switch (mergeArrays) { + case 'union': + return unionWith(sourceValue, targetValue, isEqual) + case 'intersection': + return intersectionWith(sourceValue, targetValue, isEqual) + case 'concat': + return sourceValue.concat(targetValue) + case 'replace': + return targetValue + default: + throw new Error(`Unknown merge array strategy: ${mergeArrays as string}`) + } } - } - if (isObject(target) && isObject(source)) { - return mergeWith({}, target, source, (targetValue, sourceValue) => { - return deepMerge(targetValue, sourceValue, mergeArrays) - }) as T & U - } - return source as T & U + if (isObject(targetValue) && isObject(sourceValue)) { + return deepMerge(sourceValue, targetValue, mergeArrays) + } + return undefined + }) } export function openWindow(url: string, opt?: { target?: TargetContext | string; noopener?: boolean; noreferrer?: boolean }) {