Updating Ember Calls on a Route Does Not Call renderTemplate

I want the page to refresh automatically after updating the controller model property.

I follow this advice: How to reload the current route in Ember.js?

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

this.send("sessionChanged"); 

In the linked 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 is being printed (this means: the sessionChanged event dispatched by the controller was successfully captured by the handler in the route object) ... but I do not see DINGDONG being printed.

I am using ember-cli and I have log transition enabled. I could see this in my javascript console:

 Transitioned into 'gobernadores.gobernador.simulacion' 

(what is expected). I assume that going to "gobernadores.gobernador.simulacion" will cause a renderTemplate call (which for some reason is not happening here).

What might give us a hint here is perhaps the value of the "transitional" object returned from the "update". 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 this be the reason? If so, why is "isActive" incorrect?

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

Update the model on this route and on any child routes by running the beforeModel, model, and afterModel buttons in the same way that the routes will be entered when switching from another route. The current route parameters (for example, article_id) will be passed to the corresponding model hooks, and if another model is returned, setupController and its associated routes will also be restarted.

So ... maybe my question comes down to ...: what conditions must be met for the route update method to return the transition whose isActive is true?

I am using ember 1.10.0

Thanks, Raka

UPDATE

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

+8
source share
2 answers

I don't know why refresh doesn't redraw, but why don't you just call renderTemplate yourself?

But more of it is an anti-pattern. You are essentially trying to manage your own routines, each with its own template, remembering which one you want and invoke yourself on the right one. But what does Ember router do for a living. Just create some routines: one for crear simulation and one for show-simulation, and let Ember do the work.

Assuming you want to do something this way by folding templates inside and out, your approach is still not very similar to Ember. You must use the templateName property on the route. Place an observer on it to invoke the default renderTemplate when it changes. Get renderTemplate of your custom renderTemplate

+6
source share

What I ended up was, like a torazabur originally said, calling renderTemplate() manually. You can do this by returning true inside your sessionChanged action in the controller, if you intend to implement it there. This will trigger an action on your route. Then inside your route, just do the same sessionChanged action (as you already did) and call this.renderTemplate() .

What I also noticed is that when the user is not on the specified route, the action will no longer bubble up to the route from the controller (even if you go to it), so your route action will not be called anymore. In this case, setupController() seems to be called. Thought it was worth mentioning.

-one
source share

All Articles