forked from rjsf-team/react-jsonschema-form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "feat: improve deepEquals performance (rjsf-team#4292)" (
rjsf-team#4300)" This reverts commit a4bb2bf.
- Loading branch information
1 parent
9d1ff6d
commit 415b44d
Showing
13 changed files
with
80 additions
and
41 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
@@ -1,19 +1,46 @@ | ||
import isEqualWith from 'lodash/isEqualWith'; | ||
import { createCustomEqual, State } from 'fast-equals'; | ||
|
||
/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that | ||
/** Check if all parameters are typeof function. | ||
* | ||
* @param a - The first element to check typeof | ||
* @param b - The second element to check typeof | ||
* @returns - if typeof a and b are equal to function return true, otherwise false | ||
*/ | ||
function isFunctions(a: any, b: any) { | ||
return typeof a === 'function' && typeof b === 'function'; | ||
} | ||
|
||
/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that | ||
* assumes all functions in objects are equivalent. | ||
* | ||
* @param a - The first element to compare | ||
* @param b - The second element to compare | ||
* @returns - True if the `a` and `b` are deeply equal, false otherwise | ||
*/ | ||
const customDeepEqual = createCustomEqual({ | ||
createInternalComparator: (comparator: (a: any, b: any, state: State<any>) => boolean) => { | ||
return (a: any, b: any, _idxA: any, _idxB: any, _parentA: any, _parentB: any, state: State<any>) => { | ||
if (isFunctions(a, b)) { | ||
// Assume all functions are equivalent | ||
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255 | ||
return true; | ||
} | ||
|
||
return comparator(a, b, state); | ||
}; | ||
}, | ||
}); | ||
|
||
/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that | ||
* assumes all functions are equivalent. | ||
* | ||
* @param a - The first element to compare | ||
* @param b - The second element to compare | ||
* @returns - True if the `a` and `b` are deeply equal, false otherwise | ||
*/ | ||
export default function deepEquals(a: any, b: any): boolean { | ||
return isEqualWith(a, b, (obj: any, other: any) => { | ||
if (typeof obj === 'function' && typeof other === 'function') { | ||
// Assume all functions are equivalent | ||
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255 | ||
return true; | ||
} | ||
return undefined; // fallback to default isEquals behavior | ||
}); | ||
if (isFunctions(a, b)) { | ||
return true; | ||
} | ||
return customDeepEqual(a, b); | ||
} |
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
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
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
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
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