-
Notifications
You must be signed in to change notification settings - Fork 27.4k
filterFilter compare custom objects in 1.3.6 #10464
Comments
@m7r: There have been a couple of regressions reported and fixes are submitted for those, but I can't really tell if your usecase falls under one of those categories (as I can't quite understand what is the issue here). Could you give an example (i.e. input, expected output, actual output) illustrating the problem/regression or better yet a live reproduction using plunkr / jsfiddle / ... ? |
@gkalpak http://plnkr.co/edit/fTbKNaot13K6v81xDwRL Switch the angular version to see better what I mean. |
We have to support objects in the default comparator, for the case when no predicate is supplied. However, this only applies when the two items being compared are both objects, it does not compare a string with an object. |
(Not sure what you mean by "predicate", so I assume "expression"; correct me if I'm wrong.) If no predicate is supplied, then the original array is returned (as was the case in pre-1.3.6). We don't need the comparator for that (since there's nothing to compare with) ? When two we have to compare two objects they are compared by So, if I understand correctly, you agree that we shouldn't convert objects to strings for comparing against a string ? Note, that an object might have a custom |
No, that only applies if the predicate is (Predicate, historically, was one or more comparators --- reflecting properties of the object, or custom functions --- where the result of the filter would require each predicate comparator to return true --- you've sort of mangled this a bit with your refactoring) |
AFAIKT, predicate was one or more filtering functions (and there was also a comparator).
Hm...so, what do you mean by "no predicate is supplied" then ?
Why is it incorrect ? What should happen instead. |
You're mistaken --- the predicate functions were either constructed based on input, or were already functions. There is predicateFn, but there used to be multiple predicateFns, not just one. So the idea is, for a generated predicate, if the properties it is comparing are objects, it needs to handle them specially.
Because we need to reverse the array if it's asked for
If the value is |
Hm...not sure why/how it can be asked to reverse the array.
Could you give an example ? We are probably talking about different things, because I see the same behaviour whether the expression is |
You're right, thinking of orderBy |
So, @caitp, regarding the original question, I see 3 options:
Which on should we go by ? |
@gkalpak - so what you are saying is that in option 3, it will return false unless the object has overridden the meaning of Let's go with option 3 |
I have added the
|
@petebacondarwin: Do you mean we should leave this for a community member's first contribution (as it is a "good first PR") or do you want me to submit a PR ? |
@gkalpak - if you have time go for it. I just wanted to put it out there as an option. |
@gkalpak I can look into it later today too. |
@gkalpak could you have a look at the changes please? |
@m7r: Sure, I'll take a look tomorrow. |
@m7r: I left some comments. They're mostly test-related; implementation-wise it looks good. |
@gkalpak Thanks for the comments I have updated my commit accordingly. |
First off all I am a big fan of the changed behavior as I can do finally filtering complex data as I could in angular 1.0.x
Only the default comparator should not return false if actual or expected is an object.
My use case are mongodb ObjectIds with a custom toString function.
From angular 1.0 to 1.3.5 the filterFilter could compare this custom object with a string or another ObjectId.
I know I can use my one comparator but i think the new comparator is a bit to picky.
A string like
'[object'
is in my opinion a user error.WDYT?
The text was updated successfully, but these errors were encountered: