Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember calling refresh on route does not cause the renderTemplate to be invoked

Tags:

I wanted to make the page to refresh automatically once a property of controller's model is updated.

I'm following this tip: How to reload current route in Ember.js?

So, I have an action method "runSimulation" in my controller, at the end of it I have this line :

this.send("sessionChanged");

In the associated route, I have:

actions: {
  sessionChanged: function() {
    console.log('YEAH');
    var transition = this.refresh();
    console.log(transition);
  }
},

renderTemplate: function(controller, model) {
  console.log('DINGDONG');
  var model = this.currentModel;
  if (model.simulation.params == undefined) {
    this.render('gobernador/crear-simulacion');
  } else {
    this.render('gobernador/show-simulacion');
  }
}

I could see that YEAH gets printed (meaning: the "sessionChanged" event sent by controller was successfully caught by the handler in the route object)..., but I don't see DINGDONG gets printed.

I'm using ember-cli, and I have the log transition enabled. I could see this in my javascript console:

Transitioned into 'gobernadores.gobernador.simulacion'

(which is expected). I suppose transitioning to "gobernadores.gobernador.simulacion" will cause the renderTemplate to be called (which for some reason is not happening here).

What might give us a clue here maybe the value of "transition" object returned from the execution of "refresh". In my case it gives:

{state: TransitionState, intent: C, **isActive: false,** router: Router, data: Object, resolvedModels: Object…} _visibleQueryParams: Objectdata: Object, handlerInfos: Array[4], intent: C, params: Object, pivotHandler: Class, promise: PromisequeryParams: Object, resolveIndex: 4,resolvedModels: Objectrouter: Routersequence: 4, state: TransitionStatetar, getName: "gobernador.simulacion"}

This "isActive" is false. Could it be the cause? If yes, why "isActive" is false?

I checked the API doc of Ember.Route::refresh ( http://emberjs.com/api/classes/Ember.Route.html#method_refresh ) ...

Refresh the model on this route and any child routes, firing the beforeModel, model, and afterModel hooks in a similar fashion to how routes are entered when transitioning in from other route. The current route params (e.g. article_id) will be passed in to the respective model hooks, and if a different model is returned, setupController and associated route hooks will re-fire as well.

So... maybe my question boil down to...: what conditions should be fulfilled for the refresh method of route to return a transition whose isActive is true?

I'm using ember 1.10.0

Thanks, Raka

UPDATE

I'm putting this link here..., just in case it gives some help in analysing the situation: http://blog.trackets.com/2013/02/08/router-request-lifecycle.html