Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/jungsoft/formup
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-lb committed Jul 1, 2020
2 parents dcf04a2 + ce164b0 commit 3914b33
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 3914b33

Please sign in to comment.