Upcoming Async Router API

@kingpin2k I don’t understand why you couldn’t just use the activate hook on a route, which fires whenever it’s entered…

I was under the impression that the activate hook is only when the route has been entered for the first time and not after a transition has occurred/been inserted into the dom. Likewise SetupController is when the route handler’s context has changed, but the transition hasn’t completed.

And now that I’ve played with it I see that after the transition has occurred it is not inserted into the dom. Now what I really want is a routeRendered callback. Woh is me.

I have just upgraded our code to rc6 and the following code has stopped working correctly:

  redirect: ->
    messages = @modelfor('messages')
    item = messages.get('firstobject')
    return unless item
    @transitionto 'emails.show', item

Can anyone suggest a way that I can rewrite this under the new regime?

This post mentioned validateTransition but I do not see that in the latest source.

Can you be more specific about what doesn’t work, errors you might be getting? The code you posted seems find (though it should be modelFor and not modelfor).

There is no validateTransition any more, there’s only beforeModel model and afterModel

Previously I was using this code:

Radium.MessagesIndexRoute = Radium.Route.extend
  redirect: ->
    messages = @modelFor('messages')
    item = messages.get('firstObject')
    return unless item

    @send 'selectItem', item

But after the upgrade, the send cannot find the action in the events hash. The selectItem action is in a parent route like this:

Radium.MessagesRoute = Radium.Route.extend
  events:
    selectItem: (item) ->
      if item instanceof Radium.Email
        @transitionTo 'emails.show', item
      else if item instanceof Radium.Discussion
        @transitionTo 'messages.discussion', item

I’ve changed the code to this and all is good:

Radium.MessagesIndexRoute = Radium.Route.extend
  beforeModel: ->
    messages = @modelFor('messages')
    item = messages.get('firstObject')
    return unless item

    if item instanceof Radium.Email
      @transitionTo 'emails.show', item
    else if item instanceof Radium.Discussion
      @transitionTo 'messages.discussion', item

I am curious if it is intentional that send could not find the action after the upgrade?

Same here, i now even have to call all my parent route models to issue a redirect. Before i did:

this.transitionTo('thread.page', 1);

now i have to do:

this.transitionTo('thread.page',this.modelFor('parentOfParentRouteModel'), this.modelFor('parentRouteModel'), 1);

@BowlingX what version of ember are you on? RC6, or later? I’ve heard reports of this popping up more and more, but I thought I’d fixed this since RC6 was released, but perhaps it’s broken again?

@dagda1 That’s new behavior that definitely needs to be addressed. It’s not a bug per se, but enough of a surprise to folk that it needs to be addressed. The technical reason for this is that redirect and all the beforeModel, model, afterModel hooks fire before the router actually transitions into the route, which was cause for a lot of corner case bugs in pre-facelift router, but as you can see here, facelift router has some corner cases of its own.

The fix we want to implement is for Route#send to not just forward to the router, which will fire the event on currently active routes, but for Route#send to fire right on the route you specify, regardless of whether it is active, and bubble up the route hierachy. Calling Router#send (as opposed to Route#send) will continue today’s behavior of firing on currently active routes.

@machty I’m using latest master ( #2110734fee8fc3357883b1663065cac14a8c01c0).

@BowlingX I put together a quick JSBin to test the issue i thought you were reporting, and it seems to be working: http://jsbin.com/ucanam/620/edit

Would you mind taking that jsbin and changing it so that it highlights the issue you’re describing? I’d like to fix this today if it’s really still a problem.

http://jsbin.com/ucanam/629/edit, i changed it. The Problem only occurs if you are at the route you would be redirected to. If you then want to change the model it’s not being reflected.

Seems very similar to https://github.com/emberjs/ember.js/issues/3089 . Can you confirm?

@machty, yeah, seems this could be the same issue.

@BowlingX I think I’ve fixed it; does this seem to be working for you?

http://jsbin.com/ucanam/637/edit

@machty looks good to me. I tested your changes with my application and everything works like a charm now :smile: , thank you!

Cool, I’ll push the change probably today, but unfortunately it seems like the “similar issue” i posted above is not fixed by this code change, so still some work to do :confused: