fix: deepMerge
parent
477a658645
commit
e960ac6419
|
@ -58,26 +58,26 @@ export function deepMerge<T extends object | null | undefined, U extends object
|
||||||
if (!source) {
|
if (!source) {
|
||||||
return target as T & U
|
return target as T & U
|
||||||
}
|
}
|
||||||
if (isArray(target) && isArray(source)) {
|
return mergeWith({}, source, target, (sourceValue, targetValue) => {
|
||||||
switch (mergeArrays) {
|
if (isArray(targetValue) && isArray(sourceValue)) {
|
||||||
case 'union':
|
switch (mergeArrays) {
|
||||||
return unionWith(target, source, isEqual) as T & U
|
case 'union':
|
||||||
case 'intersection':
|
return unionWith(sourceValue, targetValue, isEqual)
|
||||||
return intersectionWith(target, source, isEqual) as T & U
|
case 'intersection':
|
||||||
case 'concat':
|
return intersectionWith(sourceValue, targetValue, isEqual)
|
||||||
return target.concat(source) as T & U
|
case 'concat':
|
||||||
case 'replace':
|
return sourceValue.concat(targetValue)
|
||||||
return source as T & U
|
case 'replace':
|
||||||
default:
|
return targetValue
|
||||||
throw new Error(`Unknown merge array strategy: ${mergeArrays}`)
|
default:
|
||||||
|
throw new Error(`Unknown merge array strategy: ${mergeArrays as string}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (isObject(targetValue) && isObject(sourceValue)) {
|
||||||
if (isObject(target) && isObject(source)) {
|
return deepMerge(sourceValue, targetValue, mergeArrays)
|
||||||
return mergeWith({}, target, source, (targetValue, sourceValue) => {
|
}
|
||||||
return deepMerge(targetValue, sourceValue, mergeArrays)
|
return undefined
|
||||||
}) as T & U
|
})
|
||||||
}
|
|
||||||
return source as T & U
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openWindow(url: string, opt?: { target?: TargetContext | string; noopener?: boolean; noreferrer?: boolean }) {
|
export function openWindow(url: string, opt?: { target?: TargetContext | string; noopener?: boolean; noreferrer?: boolean }) {
|
||||||
|
|
Loading…
Reference in New Issue