|
1 | | -import { createCustomEqual, State } from 'fast-equals'; |
| 1 | +import isEqualWith from 'lodash/isEqualWith'; |
2 | 2 |
|
3 | | -/** Check if all parameters are typeof function. |
4 | | - * |
5 | | - * @param a - The first element to check typeof |
6 | | - * @param b - The second element to check typeof |
7 | | - * @returns - if typeof a and b are equal to function return true, otherwise false |
8 | | - */ |
9 | | -function isFunctions(a: any, b: any) { |
10 | | - return typeof a === 'function' && typeof b === 'function'; |
11 | | -} |
12 | | - |
13 | | -/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that |
14 | | - * assumes all functions in objects are equivalent. |
15 | | - * |
16 | | - * @param a - The first element to compare |
17 | | - * @param b - The second element to compare |
18 | | - * @returns - True if the `a` and `b` are deeply equal, false otherwise |
19 | | - */ |
20 | | -const customDeepEqual = createCustomEqual({ |
21 | | - createInternalComparator: (comparator: (a: any, b: any, state: State<any>) => boolean) => { |
22 | | - return (a: any, b: any, _idxA: any, _idxB: any, _parentA: any, _parentB: any, state: State<any>) => { |
23 | | - if (isFunctions(a, b)) { |
24 | | - // Assume all functions are equivalent |
25 | | - // see https://github.com/rjsf-team/react-jsonschema-form/issues/255 |
26 | | - return true; |
27 | | - } |
28 | | - |
29 | | - return comparator(a, b, state); |
30 | | - }; |
31 | | - }, |
32 | | -}); |
33 | | - |
34 | | -/** Implements a deep equals using the `fast-equal.createCustomEqual` function, that provides a customized comparator that |
| 3 | +/** Implements a deep equals using the `lodash.isEqualWith` function, that provides a customized comparator that |
35 | 4 | * assumes all functions are equivalent. |
36 | 5 | * |
37 | 6 | * @param a - The first element to compare |
38 | 7 | * @param b - The second element to compare |
39 | 8 | * @returns - True if the `a` and `b` are deeply equal, false otherwise |
40 | 9 | */ |
41 | 10 | export default function deepEquals(a: any, b: any): boolean { |
42 | | - if (isFunctions(a, b)) { |
43 | | - return true; |
44 | | - } |
45 | | - return customDeepEqual(a, b); |
| 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 | + }); |
46 | 19 | } |
0 commit comments