-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
[Feature request] Add filter #53
Comments
What would the |
@anko objects will be equal because we ignore phone node |
I see! I played with some possible workarounds in this Observable notebook trying to see if any of them sound good. Performance-wise, none of them would be as good as having a filter function parameter like this. (Have you tried the alternatives, and found the performance to be a problem?) Perhaps we should pre-empt all similar future queries by letting the passed-in function instead implement completely custom comparison. Ignoring some property is just a subset of that power: diff(lhs, rhs, function compare(left, right, propertyName, defaultCompare) {
// Compare all properties as normal, except `phone`, which always
// compares as equal.
if (propertyName === "phone") return true
else return defaultCompare(left, right, propertyName)
}) That way when someone asks for e.g. case-insensitive string diff, or filtering a property except when null, or things like that, they can implement any such logic. |
@anko That sounds great!! |
You can look at some similar library. They have similar filter https://www.npmjs.com/package/deep-diff#changes |
+1 I've come across this I'd prefer the simple key-based filtering api like the one suggested: Also, while I haven't personally had a use for comparing values, I could see how this "fitler" could also be used for custom comparisons, which might be useful if you wanted to compare FWIW, the most common object-diffing usage for me is doing a restful HTTP PATCH that would look something like this:
|
Also needing this for another use case: ignore word casing. |
In order to compare objects, I want to filter some keys. For example:
The text was updated successfully, but these errors were encountered: