Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can create customEqual to handle functions #123

Closed
igorbrasileiro opened this issue Sep 9, 2024 · 2 comments · Fixed by #127
Closed

How can create customEqual to handle functions #123

igorbrasileiro opened this issue Sep 9, 2024 · 2 comments · Fixed by #127
Assignees

Comments

@igorbrasileiro
Copy link

igorbrasileiro commented Sep 9, 2024

How can compare objects with functions, and for all functions return true, using createCustomEqual?

my compare function

const customDeepEqual = createCustomEqual({
  createInternalComparator: (
    comparator: (a: any, b: any, state: State<Meta>) => boolean,
  ) => {
    return (
      a: any,
      b: any,
      _idxA: any,
      _idxB: any,
      _parentA: any,
      _parentB: any,
      state: State<Meta>,
    ) => {
      if (typeof a === "function" && typeof b === "function") {
        return true;
      }

      return comparator(a, b, state);
    };
  },
});

tests:

compare(() => {}, () => {}) // false, expected true
@planttheidea
Copy link
Owner

Functions are currently treated as pure primitives, and are therefore treated with SameValueZero equality directly instead of using the comparator function ... apologies, I swear this used to be in the documentation, I must have removed it. I can see how ignoring functions would be a valuable use-case, though; I'll see if I can add support for areFunctionsEqual.

@planttheidea
Copy link
Owner

Has been resolved as-of 5.1.0, as you can use the new areFunctionsEqual override in the custom equality config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants