Skip to content

Consider switching deep equal module #1055

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

Closed
sindresorhus opened this issue Sep 27, 2016 · 8 comments
Closed

Consider switching deep equal module #1055

sindresorhus opened this issue Sep 27, 2016 · 8 comments
Assignees
Labels

Comments

@sindresorhus
Copy link
Member

We currently use: https://github.com/sotojuan/not-so-shallow

I know this is something like the third time, but someone pointed out our current module has a lot of issues, and I'm personally not interested or have time to fix those, nor maintain a deep equal module.

I'd like to look into whether we could use lodash.isEqual.

// @jdalton

@jdalton
Copy link
Contributor

jdalton commented Sep 27, 2016

Hiya!

Ok so lodash.isEqual supports comparing:

arrays, array buffers, booleans, date objects, error objects, maps, numbers, Object objects, regexes, sets, strings, symbols, and typed arrays. Object objects are compared by their own, not inherited, enumerable properties. Functions and DOM nodes are not supported.

It is an equivalence method so somethings may be seen as equiv that aren't strictly equal, like 1 and Object(1) (legacy rules). The behavior can be customized with lodash.isEqualWith.

function deepEqual(a, b) {
  return isEqualWith(a, b, function(a, b) {
    if (typeof a !== typeof b) {
      return false;
    }
  });
}

@sindresorhus
Copy link
Member Author

I assume it does strict value equality checks?

Does it handle circular references?

I noticed it doesn't handle Node.js buffers? Would you able to add that?
See https://nodejs.org/api/buffer.html#buffer_buf_equals_otherbuffer

Would you be willing to ensure lodash.isEqual handles these issues: https://github.com/sotojuan/not-so-shallow/issues ?

It is an equivalence method so somethings may be seen as equiv that aren't like 1 and Object(1) (legacy rules).

That's fine. They're not equal.

The behavior can be customized with lodash.isEqualWith.

My goal is not having to do that. Would be better if we all agreed what deep equality entails.

@jdalton
Copy link
Contributor

jdalton commented Sep 28, 2016

I assume it does strict value equality checks?

For primitives yep. For objects it recursively crawls.

Does it handle circular references?

Yes.

I noticed it doesn't handle Node.js buffers? Would you able to add that?

Node buffers fall under the typed array support.

Would you be willing to ensure lodash.isEqual handles these issues:
https://github.com/sotojuan/not-so-shallow/issues ?

I believe it already handles those issues.

My goal is not having to do that. Would be better if we all agreed what deep equality entails.

Yep, I agree. It's something for Lodash v5 for sure. In the meantime this method allows customization for the things you'd like to change and handles the rest.
It's a pretty good mix.

@sindresorhus
Copy link
Member Author

Node buffers fall under the typed array support.

I would be explicit about that in the docs. While Node.js buffers inherit from TypedArray, they're not entirely the same thing and not everyone knows buffers inherit from TypedArray.

@sindresorhus sindresorhus added enhancement new functionality help wanted and removed question labels Sep 28, 2016
@jdalton
Copy link
Contributor

jdalton commented Sep 28, 2016

I would be explicit about that in the docs. While Node.js buffers inherit from TypedArray, they're not entirely the same thing and not everyone knows buffers inherit from TypedArray.

C🕶L

Explicit support is probably better anyways.
I'll patch it up lodash/lodash@4495e74.

@vadimdemedes
Copy link
Contributor

@sindresorhus So I assume, until then we could use lodash.isEqualWith with an additional equality check just for buffers? It's pretty solid. Or do you want to keep searching for the module with the satisfying defaults?

@sindresorhus
Copy link
Member Author

@vdemedes It's already part of a Lodash release, so we can just use isEqual. We should bring in the tests from https://github.com/sotojuan/not-so-shallow/tree/master/test just to make sure we didn't break anything. Wanna do a PR?

@vadimdemedes
Copy link
Contributor

@sindresorhus Yes, definitely!

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

No branches or pull requests

3 participants