I'm building a simple app with a persistent view. This view is always there.
The view depends on some data. Entering the application in a different state should
ensure that view is present with it's data. I thought the best way to do this
would be to create an initial state which calls connectOulet
to connect the data and view. That way all the subsequent states have to transition through this one. I can't figure out how to get the router to automatically transition to the next state after doing the connecting.
Here is my router (this doesn't work ATM). See comments.
Inbox.Router = Ember.Router.extend
enableLogging: true
location: "history"
initialState: "bootUp"
bootUp: Ember.Route.extend
root: Ember.Route.extend
route: '/'
# All states need to transition through this code
# How can I transition to root state after this code executes?
connectOutlets: (router, context) ->
router.get('applicationController').connectOutlet
outletName: "list"
name: "messages"
context: Inbox.store.findAll(Inbox.Message)
root: Ember.Route.extend
showMessage: Ember.Route.transitionTo('root.showingMessage')
initialState: 'dashboard'
dashboard: Ember.Route.extend
route: '/dashboard'
# Entering this state needs the messages view loaded
# with data
showingMessage: Ember.Route.extend
route: '/:id'
connectOutlets: (router, context) ->
router.get('applicationController').connectOutlet
outletName: "details"
name: "message"
context: context
serialize: (router, context) ->
id: context.get('id')
deserialize: (router, urlParams) ->
Inbox.store.find Inbox.Message, urlParams.id
Modeling this behavior with a FSM seems correct to me. Is this the correct way to do such a thing or is there a better way?