Skip to content

Commit

Permalink
fix(base.ts): improve map member
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Nov 3, 2019
1 parent 3323db3 commit 01fd8e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ export abstract class AutoMapperBase {
}

const sourceVal = (mapFrom as ValueSelector)(sourceObj);
// if (sourceVal === undefined || sourceVal === null) {
// delete (destinationObj as any)[path];
// return;
// }
if (sourceVal === undefined || sourceVal === null) {
set(destinationObj, destinationMemberPath, null);
return;
}

if (_isObjectLike(sourceVal)) {
if (_isDate(sourceVal)) {
Expand Down
5 changes: 2 additions & 3 deletions src/utils/common.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ export function _assertMappingErrors<T extends Dict<T> = any>(
if (propKeys.includes(key)) {
continue;
}
(obj[key as keyof T] === null || obj[key as keyof T] === undefined) &&
unmappedKeys.push(key);
unmappedKeys.push(key);
}

if (unmappedKeys.length) {
Expand Down Expand Up @@ -236,7 +235,7 @@ function _getTag(value: any): string {
export function _get<T>(object: T, path: string, defaultVal: any = null): any {
const _path = path.split('.').filter(Boolean);
const _val = _path.reduce((obj: any, key) => obj && obj[key], object);
return _val == undefined ? defaultVal : _val;
return _val === undefined ? defaultVal : _val;
}

export function _isEmpty(value: any): boolean {
Expand Down

0 comments on commit 01fd8e2

Please sign in to comment.