Closed mulderp closed 11 years ago
Not sure I understand the need for this added test. The group of tests below it:
test the case where you have a filter function on a specific key's value.
Nothing against merging this in (more tests are almost never a bad thing) but can you help me understand the motivation?
I was looking for documentation in the tests actually. The use case I was looking for that sometimes we need to filter "inclusive" not exclusive, e.g. Imagine buying a T-Shirt, we might like to filter for a size range "medium" to "large". So, we just check whether elements are part in a range. What might be interesting for documentation would be, filtering for a range is possible with:
_.contains(['medium','large'], val)
But I agree the location of the tests is not right, and maybe it would go best under documentation directly.
Is there something unclear about the existing documentation?
https://github.com/jmorrell/backbone.obscura#proxyfilterbyfiltername-filter
ex:
filtered.filterBy('a > 2', { a: function(val) {
return val > 2;
}});
shows that you can use arbitrary function predicates.
Would more examples make it clearer? Your case of filtering if it's included in a set is certainly a common case.
My confusion was that I didn't realize that
_.contains(range, val)
is a predicate. I jumped into fiddling with a function(range, val) { ... } first. And realized that this is a use case of {a: predicate(x) }.
Understandable. I'll add the _.contains example to the docs.
Add test for filter by Array, addresses: https://github.com/jmorrell/backbone.obscura/issues/3