-
Notifications
You must be signed in to change notification settings - Fork 934
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: concat of mixed and subtype (#444)
* fix: concat of mixed and subtype * fix: concat with lazy
- Loading branch information
Showing
5 changed files
with
70 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import has from 'lodash/has'; | ||
import isSchema from './isSchema'; | ||
|
||
let isObject = obj => Object.prototype.toString.call(obj) === '[object Object]'; | ||
|
||
export default function prependDeep(target, source) { | ||
for (var key in source) | ||
if (has(source, key)) { | ||
var sourceVal = source[key], | ||
targetVal = target[key]; | ||
|
||
if (targetVal === undefined) { | ||
target[key] = sourceVal; | ||
} else if (targetVal === sourceVal) { | ||
continue; | ||
} else if (isSchema(targetVal)) { | ||
if (isSchema(sourceVal)) target[key] = sourceVal.concat(targetVal); | ||
} else if (isObject(targetVal)) { | ||
if (isObject(sourceVal)) | ||
target[key] = prependDeep(targetVal, sourceVal); | ||
} else if (Array.isArray(targetVal)) { | ||
if (Array.isArray(sourceVal)) target[key] = sourceVal.concat(targetVal); | ||
} | ||
} | ||
|
||
return target; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters