offirgolan / ember-parachute

Improved Query Params for Ember

Home Page:https://offirgolan.github.io/ember-parachute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing query in setup hook

sevab opened this issue · comments

I'm doing query param validation on page load in the setup hook:

setup({ queryParams }) {
  if (this.isPastDate(queryParams.date)) {
    this.set('date', null);
  }
  this.fetchData(queryParams);
}

While the 'date' controller value updates, the URL still has the old value for date.

Is setup() hook not ideal for changing query params? Wanted to avoid using beforeModel() on the route, since this is more concise.

Resetting individual queryParams in beforeModel() is actually broken as well right now (emberjs/ember.js#14606), so hoping will find a way to get this to work.

Current workaround:

setup({ queryParams }) {
  if (this.isPastDate(queryParams.date)) {
   // ensure fetchData receives correct params in current run-loop
    queryParams.date = null;
    next(() => { this.set('date', null); });
  }
  this.fetchData(queryParams);
}