-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Ignore constructor equality for t.same #630
Comments
👍 Do you have a suggestion on how we could solve this? |
Are you open to swapping out deeper for something else? I know I've used On Thu, Mar 10, 2016, 10:54 AM Sindre Sorhus [email protected]
|
Maybe, if it does the same except for the constructor checking. We previously tried with |
I guess I'm not so sure checking the constructor is a terrible idea. Two objects with different constructors are not strictly equal. Specifically, you could certainly write an
The docs indicate this behavior was a specific choice in |
If you want looser constructor checking, take a look at I'd be super amused if somebody found a use for |
I've used deep-equal and it's really lightweight. It checks for prototype On Thu, Mar 10, 2016, 5:39 PM Forrest L Norvell [email protected]
|
We moved away from deep-equal because of inspect-js/node-deep-equal#19. I see no reason not to emulate |
FWIW, I wrote The only dependency that |
👍 this just leaves me more convinced that we want to stick with Perhaps AVA should add |
|
I don't see the reason to have both to be honest. Same reason we don't have
👎 We definitely don't want to include more native dependencies for such a minor to none gain. |
This isn't completely analogous to It seems @mattkrick is claiming there are cases where a looser "structurally equal" comparison is desirable. Maybe we should keep |
IMHO the strictest method should be the one you think of the soonest, so +1. I wonder if performance-wise it'd be feasible to run |
I'd still argue against having 2 |
In which case you could just use |
I'm having a hard time thinking of when I would ever want it to check the equality of the constructors of objects. And I would honestly prefer one method, not two. It's very easy to add another method, but it adds a lot of overhead for users. Now they must think hard about which method to use in which cases and know about the subtle differences between them. |
Personally, I avoid making decisions based on the constructor function & go off of the shape of the object, or a signature property, or the |
OK, @novemberborn Can you think of a reason for keeping the strict one around? @mattkrick are you interested in making a PR swapping |
Nah, happen to loosen it up. If you're really concerned then as @mattkrick says write some |
Description
t.same now uses deeper, which checks the equality of the constructors of objects. I argue that a deep equal should ignore the constructor. Here's why:
Two objects created with different instances of the constructor will fail.
Constructor is not a key in Object.keys, not part of JSON, and not returned by tools like graphQL. That means one must recreate the result in order to append the constructor without adding it as a key (unless I'm doing it wrong).
Insanely difficult to debug and makes you pull your hair out because logging both objects returns two identical objects and you start to question your sanity when the diff returns nothing.
Environment
Affects all, but running on 5.7.1, OSX (Darwin 15.x)
The text was updated successfully, but these errors were encountered: