-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: formData change clear errorMessage
fix: merge errorSchema fix: merge errorSchema
- Loading branch information
Showing
3 changed files
with
44 additions
and
3 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 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,23 @@ | ||
import keys from 'lodash/keys'; | ||
import pickBy from 'lodash/pickBy'; | ||
import isEqual from 'lodash/isEqual'; | ||
|
||
/** | ||
* Compares two objects and returns the names of the fields that have changed. | ||
* This function iterates over each field of object `a`, using `_.isEqual` to compare the field value | ||
* with the corresponding field value in object `b`. If the values are different, the field name will | ||
* be included in the returned array. | ||
* | ||
* @param {any} a - The first object, representing the original data to compare. | ||
* @param {any} b - The second object, representing the updated data to compare. | ||
* @returns {string[]} - An array of field names that have changed. | ||
* | ||
* @example | ||
* const a = { name: 'John', age: 30 }; | ||
* const b = { name: 'John', age: 31 }; | ||
* const changedFields = getChangedFields(a, b); | ||
* console.log(changedFields); // Output: ['age'] | ||
*/ | ||
export default function getChangedFields(a: any, b: any): string[] { | ||
return keys(pickBy(a, (value, key) => !isEqual(value, b[key]))); | ||
} |
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