|
1 | | -import isEqualWith from 'lodash/isEqualWith'; |
| 1 | +import { createCustomEqual } from 'fast-equals'; |
2 | 2 |
|
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. |
5 | 4 | * |
6 | 5 | * @param a - The first element to compare |
7 | 6 | * @param b - The second element to compare |
8 | 7 | * @returns - True if the `a` and `b` are deeply equal, false otherwise |
9 | 8 | */ |
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