Provide lookup for default query parameters


I had originally posted this as a github issue, but it really belongs here ( I’m shamelessly copy and pasting.

I’m seeking feedback on the idea of adding a router function to lookup a default value for a query parameter. In my case, I have one or two query parameters that use the link-to helper and query-params subexpression with a bound computed property that has logic that ends up duplicating a default value. Yuck; here’s an example:

{{#link-to 'posts' (query-params sortBy=sortParam)}}Sort{{/link-to}}

App.HomeController = Ember.Controller.extend({
  sortBy: function() {
    var defaultValue = 'type',
        value = defaultValue;
    /* Some logic. No new value is determined. */
    return value;
  }.property('a', 'b', 'c', 'd')

App.PostsController = Ember.ArrayController.extend({
  queryParams: ['sortBy'],
  sortBy: 'type'

In this example, the sortBy computed property has to know what the default query-param is going to be in the posts controller. There is no way to indicate to the query-params subexpression that you’d like it to choose the default value. Any value you specify gets converted to string (including undefined and null).

So I see two possible options. 1) Is add a mechanism to the query-params subexpression that indicates a default value is desired (though this seems breaking) or 2) Provide a router hook similar to the private hook _queryParamsFor that makes it possible to look up the default value.

@machty @pwagenet