Skip to content

Instantly share code, notes, and snippets.

@machty
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machty/3a714c22569863d4b9cc to your computer and use it in GitHub Desktop.
Save machty/3a714c22569863d4b9cc to your computer and use it in GitHub Desktop.

UPDATE: this is different from the Route-only approach i was suggesting recently; we're keeping things on the controller, but route-specific config lives on a queryParams config hash on the route

query-params-new needs another iteration, described here https://gist.github.com/machty/d687cab552ecee2f9162

query-params-new-new-new-final-new-24

From the bottom of http://emberjs.com/guides/routing/query-params/

These are examples from the QP guides on the ember site, rewritten according to the proposed API described at https://gist.github.com/machty/d687cab552ecee2f9162

Search Queries

Original: http://emberjs.jsbin.com/ucanam/3008/edit

Changes: None

Sort: client-side, no refiring of model hook

Original: http://emberjs.jsbin.com/ucanam/2937/edit

Changes: None

Sort: server-side, refire model hook

Original: http://emberjs.jsbin.com/ucanam/2942/edit

Same controller modifications as previous, but route is a bit different:

App.ApplicationRoute = Ember.Route.extend({
  queryParams: {
    sortBy: {
      refreshModel: true
    }
  }
  // no longer have to do the 
  // queryParamsDidChange + refresh() incantation
});

Pagination + Sorting

Original: http://emberjs.jsbin.com/ucanam/2950/edit

No change

Boolean values. False value removes QP from URL

Original: http://emberjs.jsbin.com/ucanam/2708/edit

Nothing changes in the code; the main Ember change happening here is that we now serialize boolean values into the URL as &x=true& and &x=false&, rather than just &x& to imply that x is true and false if absent from URL. This avoids the issue of ambiguity wrt deserializing true and false as strings "true" and "false" by inferring from the default value, which is a boolean, that the URL should be deserialized as booleans rather than strings.

I think this is pretty rad.

Global query params on app route

Original: http://emberjs.jsbin.com/ucanam/2719/edit

No Change

Opt-in to full transition via refresh()

Original: http://emberjs.jsbin.com/ucanam/2711/edit

App.IndexRoute = Ember.Route.extend({
  queryParams: {
    foo: {
      refreshModel: true
    }
  }
  // get rid of queryParamsDidChange
});

Aaaand...

the rest are about the same.

Control over pushState vs replaceState

query-params-new responded to all QP prop changes with a replaceState. The new default is going to be pushState, but we're also adding a way to make this configure, e.g.:

App.IndexRoute = Ember.Route.extend({
  queryParams: {
    foo: {
      replace: true
    }
  }
});

replace: true is mimicking the link-to replace=true API, if you're wondering.

@taras
Copy link

taras commented Mar 1, 2014

Is there a difference between defining queryParams in the route vs the controller?

@zigomir
Copy link

zigomir commented Mar 2, 2014

There is something wrong on Pagination + Sorting example. When you set pageSize it will only work for the very first page...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment