algoliasearch-helper-js
algoliasearch-helper-js copied to clipboard
A toggleNumericRefinement method?
Here is what we currently have:
- Facet =>
toggleRefinement
- Disjunctive facet =>
toggleRefinement
- Hierarchical facet =>
toggleRefinement
- Exclude =>
toggleFacetExclusion
- Numeric => Only
{add,remove}
- Tag =>
toggleTag
We should probably add toggleNumericRefinement
for consistency.
Yes, that's something I wanted as well.
Also, most of the time you're using a single operator and want to switch from 1 refinement to another. Like you're filtering with created_at>1 week ago
and you want to move to created_at>1 month ago
or created_at>1 day ago
. Not sure the toggleNumericRefinement
is enough for that use-case.
It isn't, we're now using an array of refinements by operator ( https://github.com/algolia/algoliasearch-helper-js/blob/d3bf223fcfe9da6a4a47c2349d758d402d67729a/dist/algoliasearch.helper.js#L8177 ) and all the other ones use the value to know which one to add/remove, so I wouldn't change the behaviour for this method only, but we could probably add a 4th parameter override
?
so I wouldn't change the behaviour for this method only, but we could probably add a 4th parameter override ?
Or maybe another method, because optional 4th parameter is not super nice :/
helper.toggleNumericRefinement(attribute, operator, value);
// and maybe
helper.switchNumericRefinement(attribute, operator, value); // clear + add ?
I like the switch method. This is pretty common to use this clear + add pattern. My concern would be that it's yet another kind of method. What do you think?
My concern would be that it's yet another kind of method. What do you think?
Yes true; maybe we should just go for toggle then. Even if the switch is a common pattern, we can definitely call clear+add
instead.
Maybe we could have that in the next major release and rethink the method names?