Browse Source

refactor: improve readability of bool exp

pull/5126/head
bnymncoskuner 6 years ago
parent
commit
dee43694b1
  1. 10
      npm/ng-packs/packages/core/src/lib/utils/object-utils.ts

10
npm/ng-packs/packages/core/src/lib/utils/object-utils.ts

@ -4,7 +4,7 @@ export function deepMerge(target, source) {
} else if (isNullOrUndefined(target) && isNullOrUndefined(source)) {
return {};
} else {
return isNullOrUndefined(source) ? target : source;
return exists(source) ? source : target;
}
}
@ -15,14 +15,14 @@ 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
/**
* if we will not recurse any further,
* we will prioritize source if it is a defined value.
*/
if (shouldNotRecurse) {
return !isNullOrUndefined(source) ? source : target;
return exists(source) ? source : target;
}
const keysOfTarget = Object.keys(target);
@ -38,6 +38,10 @@ function isNullOrUndefined(obj) {
return obj === null || obj === undefined;
}
function exists(obj) {
return !isNullOrUndefined(obj);
}
function isObject(obj) {
return obj instanceof Object;
}

Loading…
Cancel
Save