Handling rejected models before application loads


#1

Ember Version: 1.0.0 e2ea0cf (2013-08-31 23:47:39 -0700)

Take this example:

App.Post = Ember.Object.extend
  findComment: (id) ->
    jQuery.Deferred().reject("notFound")

# Base Route
#
App.Route = Ember.Route.extend
  actions:
    error: (error, transition) ->
      # maybe you render a not found partial into the route, maybe
      # you render a flash message into the application

# /post/:post_id
#
App.PostRoute = App.Route.extend
  model: (params) ->
    App.Post.find(params.post_id)

# /post/:post_id/comments/:comment_id
#
App.CommentRoute = App.Route.extend
  model: (params) ->
    # Will be rejected
    @modelFor('post').findComment(params.comment_id)

Here’s what happens:

  • Vist /post/1/comments/1 directly
  • App.PostRoute#model returns a post
  • App.CommentRoute#model returns a rejected promise
  • Nothing renders (not the application or the post route)

Here’s what I would like to happen:

  • Vist /post/1/comments/1 directly
  • PostRoute#model returns a post
  • CommentRoute#model returns a rejected promise
  • ApplicationRoute renders the application template
  • PostRoute renders the post template
  • CommentRoute.actions#error renders a notFound partial into post

Is this possible?


#2

I think it would be good in general if (potentially as option) templates rendered as their model promises resolved (in hierarchical order of course) rather than only after all promises resolved. It would make the user experience of going to a nested route much better instead of seeing one generic "loading..." as all the models are resolved. This is how I intuitively expected it to work, as if each setupController were the then of the model promise, rather than doing all of the model hooks, then all of the setupController hooks etc.