-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ff94324
commit a4bb2bf
Showing
14 changed files
with
51 additions
and
80 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
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,46 +1,19 @@ | ||
import { createCustomEqual, State } from 'fast-equals'; | ||
import isEqualWith from 'lodash/isEqualWith'; | ||
|
||
/** 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 | ||
/** Implements a deep equals using the `lodash.isEqualWith` 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 { | ||
if (isFunctions(a, b)) { | ||
return true; | ||
} | ||
return customDeepEqual(a, b); | ||
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 | ||
}); | ||
} |
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