Browse Source
Merge pull request #6155 from abpframework/feat/deep-merge-node-instance
feat: add Node instance control to deepMerge
pull/6181/head
Muhammed Altuğ
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
20 additions and
3 deletions
-
npm/ng-packs/packages/core/src/lib/utils/common-utils.ts
-
npm/ng-packs/packages/core/src/lib/utils/object-utils.ts
|
|
|
@ -27,3 +27,11 @@ export function isArray(obj) { |
|
|
|
export function isObjectAndNotArray(obj) { |
|
|
|
return isObject(obj) && !isArray(obj); |
|
|
|
} |
|
|
|
|
|
|
|
export function isNode(obj) { |
|
|
|
return obj instanceof Node; |
|
|
|
} |
|
|
|
|
|
|
|
export function isObjectAndNotArrayNotNode(obj) { |
|
|
|
return isObjectAndNotArray(obj) && !isNode(obj); |
|
|
|
} |
|
|
|
|
|
|
|
@ -1,7 +1,14 @@ |
|
|
|
import { isObjectAndNotArray, isNullOrUndefined, exists, isArray, isObject } from './common-utils'; |
|
|
|
import { |
|
|
|
exists, |
|
|
|
isArray, |
|
|
|
isNode, |
|
|
|
isNullOrUndefined, |
|
|
|
isObject, |
|
|
|
isObjectAndNotArrayNotNode, |
|
|
|
} from './common-utils'; |
|
|
|
|
|
|
|
export function deepMerge(target, source) { |
|
|
|
if (isObjectAndNotArray(target) && isObjectAndNotArray(source)) { |
|
|
|
if (isObjectAndNotArrayNotNode(target) && isObjectAndNotArrayNotNode(source)) { |
|
|
|
return deepMergeRecursively(target, source); |
|
|
|
} else if (isNullOrUndefined(target) && isNullOrUndefined(source)) { |
|
|
|
return {}; |
|
|
|
@ -17,7 +24,9 @@ function deepMergeRecursively(target, source) { |
|
|
|
isArray(target) || |
|
|
|
isArray(source) || // at least one array
|
|
|
|
!isObject(target) || |
|
|
|
!isObject(source); // at least one not an object
|
|
|
|
!isObject(source) || // at least one not an object
|
|
|
|
isNode(target) || |
|
|
|
isNode(source); // at least one node
|
|
|
|
|
|
|
|
/** |
|
|
|
* if we will not recurse any further, |
|
|
|
|