These are my thoughts on using the (bleeding edge) query-params-new from 1.6.0-beta.1+canary.01f3f32c
.
The currently handled parameter types are strings (of course), arrays (with the arr[]=foo1&arr[]=foo2
syntax, which is not the nicest but closest zu the standard) and booleans. The absence of integer parameters means having to use parseInt()
in every method where the parameter is used. (Setting the parameter to a number value is no problem)
I think there are two ways to determine whether to cast or not while parsing parameters:
- Check if param contains only digits and just assume that it's meant to be a numeric parameter then. Since this may cause unforeseen behaviour we shouldn't do this
- Add a descriptior to the controllers
queryParams
to force a query parameters data type (this would also allow providing an array when the present url isarr=foo1
without the[]
, but I'm not sure if this is a desirable thing)
This is a big one for my project. The simplest example is the pagination which starts at page=1
, which because its the home page should not need a set query param. Of course, I could start with page=false
to hide the parameter from the url but then I loose the ability to just bind this value to the pagination controller and have unecessary if-clouses to handle this case.
Also, when using string values as query params and the value gets set to ""
(empty string) because the user clears the search field, the query is still search=
, which is not nice. I wrote an observer method clearing empty query parameters, but maybe there should exist a common way to declare an empty parameter as not needed in the url:
clearStringQueryParams: function(target, changedKey) {
if (target.get(changedKey + '.length') === 0) {
target.set(changedKey, null);
}
}.observes('search', 'channel', 'author', ...),
Again, this could be achieved by a queryParam descriptor instead of the simple string in the queryParams
array.
I think these changes would really improve the experience when working with query params. Special thanks especially to @machty for his work on this topic.
Best, Stefan
These are great points, and I think they'll be addressed by the following:
Any concerns with this approach?