Skip to content

Commit

Permalink
Merge pull request #26 from jungsoft/25-consider-merging-initialtouch…
Browse files Browse the repository at this point in the history
…ed-to-keep-behavior

Merge initialTouched generated object with options.initialTouched
  • Loading branch information
pedro-lb authored Jul 1, 2020
2 parents 62e0af9 + 405cc34 commit ce164b0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions packages/core/src/utils/mapInitialTouched.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import merge from 'merge';

/**
* Returns true if one value is possibly touched.
*
Expand All @@ -18,7 +20,7 @@ const evalIsTouched = (value: any) => !!(
* Recursively maps touched fields in an object.
* @param obj The object
*/
const recursiveMapTouched = (obj: object): object => {
const recursiveMapTouched = (obj?: object): object => {
const result = {
...(obj || {}),
};
Expand Down Expand Up @@ -47,21 +49,18 @@ const recursiveMapTouched = (obj: object): object => {
* which is optional.
*
* @param initialValues Value of initialValues
* @param initialTouched Value of initialTouched
* @param override Value of initialTouched
*/
const mapInitialTouched = (
initialValues?: object,
initialTouched?: object,
override?: object,
) => {
if (initialTouched) {
return initialTouched;
}

if (!initialValues) {
return undefined;
}
const touchedFromInitialValues = recursiveMapTouched(initialValues);

return recursiveMapTouched(initialValues);
return merge.recursive(
(touchedFromInitialValues || {}),
(override || {}),
);
};

export default mapInitialTouched;

0 comments on commit ce164b0

Please sign in to comment.