-
-
Notifications
You must be signed in to change notification settings - Fork 96
Diff gives strange results when passing invalid values #29
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
Comments
Hey @niklas-e I'm not sure about this one. I agree the outputs in your example look odd (it is just returning the right hand side when the values are not the same). I think this is potentially a user land check, I'm not sure that it is semantic to return an empty object as the difference when called with primitives and I wouldn't want to throw an error. I think if the use case is that the value could be something other than an object then you may just want to wrap the call to deep-object-diff in a check to see the arguments are both objects and then you can put your own semantics around the this case. |
@mattphillips, fair enough. Though I still think there could be sanity checks for After all at least |
If we look at your examples they all make sense to me, with one assumption: deep-object-diff represents no diff as an empty object.
What are the differences between the original value of an object and the updated value of
What are the difference between the original value of
What is different between The same stands for any primitives, including So it wouldn’t make sense to say there is no difference between an object and a primitive, when there is. That’s why if in user land you may pass in a primitive and don’t want to receive the real difference between the primitive and an object or vice verse then you need to do a sanity check as that logic is specific to your use case. I hope that all makes sense 😆 |
Hey @niklas-e I'm going to go ahead and close this issue, feel free to re-open if you disagree with the points I have made above 😄 |
It seems to be somewhat unintuitive to return differences when passing non-object values. For example, if comparing an object to a number, it will return the number as a result. Same goes for undefined, null and string (and most likely all other types). I think it should throw an error or return an empty object when comparing non-object values,
Here's some tests: https://runkit.com/niklas-e/5a95669e6ac1ed0012f9ebbd
cc: @SamiEklund
The text was updated successfully, but these errors were encountered: