Skip to content

Commit c9520d1

Browse files
Switch lodash.isEqualWith to fast-equals
1 parent 63f5612 commit c9520d1

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
1515
should change the heading of the (upcoming) version to include a major version bump.
1616
1717
-->
18+
# 5.24.2
19+
20+
## @rjsf/utils
21+
22+
- switch `lodash.isEqualWith` to `fast-equals.createCustomEqual` providing `areFunctionsEqual` assuming any functions are equal.
1823

1924
# 5.24.1
2025

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/utils/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"react": "^16.14.0 || >=17"
3737
},
3838
"dependencies": {
39+
"fast-equals": "^5.2.2",
3940
"json-schema-merge-allof": "^0.8.1",
4041
"jsonpointer": "^5.0.1",
4142
"lodash": "^4.17.21",

packages/utils/src/deepEquals.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import isEqualWith from 'lodash/isEqualWith';
1+
import { createCustomEqual } from 'fast-equals';
22

3-
/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that
4-
* assumes all functions are equivalent.
3+
/** Implements a deep equals using the `fast-equals.createCustomEqual` function, providing a customized comparator that assumes all functions are equivalent.
54
*
65
* @param a - The first element to compare
76
* @param b - The second element to compare
87
* @returns - True if the `a` and `b` are deeply equal, false otherwise
98
*/
10-
export default function deepEquals(a: any, b: any): boolean {
11-
return isEqualWith(a, b, (obj: any, other: any) => {
12-
if (typeof obj === 'function' && typeof other === 'function') {
13-
// Assume all functions are equivalent
14-
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
15-
return true;
16-
}
17-
return undefined; // fallback to default isEquals behavior
18-
});
19-
}
9+
const deepEquals = createCustomEqual({
10+
createCustomConfig: () => ({
11+
// Assume all functions are equivalent
12+
// see https://github.com/rjsf-team/react-jsonschema-form/issues/255
13+
//
14+
// Performance improvement: knowing that typeof a === function, so, only needs to check if typeof b === function.
15+
// https://github.com/planttheidea/fast-equals/blob/c633c4e653cacf8fd5cbb309b6841df62322d74c/src/comparator.ts#L99
16+
areFunctionsEqual(_a, b) {
17+
return typeof b === 'function';
18+
},
19+
}),
20+
});
21+
22+
export default deepEquals;

0 commit comments

Comments
 (0)