Skip to content

Instantly share code, notes, and snippets.

@ghempton
Created July 20, 2012 17:43
Show Gist options
  • Save ghempton/3152166 to your computer and use it in GitHub Desktop.
Save ghempton/3152166 to your computer and use it in GitHub Desktop.
Async Routing Example

Example of the Need for Async Routing

App.Profile = DS.Model.extend({

});

App.User = DS.Model.extend({
  profile: DS.belongsTo(App.Profile)
});
App.Router = Em.Router.extend({

  user: Em.Route.extend({
    route: '/user/:user_id',
    connectOutlets: function(router, user) {
      router.get('userController').set('content', 'user');
      router.get('applicationController').connectOutlet('user');
    }
    profile: Em.Route.extend({
      route: '/profile',
      connectOutlets: function(router, context) {
        user = router.getPath('userController.content');

        // This line below is where we need async, can be null unless we know the user model is loaded
        router.get('profileController').set('content', user.get('profile'));

        router.get('userController').connectOutlet('profile');
      }
    });
  })

});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment