Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've been working on same. I think you're on the right track, that quote from Tom about the entire point of states really gets to the heart of it. The router is changing fast so not sure there are established patterns here, but I can share what I've learned so far. </p> <p>To summarize the general issue: The Ember router uses url to serialize/deserialize app state. Other than knowing the requested route, it is stateless. The end user has complete control over this state, and can reload app in any state by entering a url. So all apps will have a common problem of when/how to verify that the requested state is 'valid' given user permissions and the current state of the model. </p> <p>Coming from Rails, my first instinct is to protect routes like we would in a before filter. This is tricky in Ember - since data load is async, it is not available during initial descent into the route hierarchy. Have not gotten this approach working myself, but other's have. Typical approaches seem to be </p> <ul> <li>use sproutcore statechart, which allows concurrent states (SinisterMinister)</li> <li>pause state transition midstream, waiting for data to load (suggested by lukemelia)</li> <li>in earlier versions of Ember router you could use mark transition as async but that's been removed</li> </ul> <p>Given what Tom said about states, I'm trying to avoid this situation whenever possible. Instead of trying to 'protect' a route, use a mix of routes + states to ensure that user cannot reach an invalid state in the first place. In your example, you'd change to:</p> <ul> <li>a single "routable" state at '/billing'</li> <li>2 "substates" named 'method' and 'address' (these should extend Ember.State instead of Ember.Router and don't set a route)</li> <li>the initialState of '/billing' route would be 'address'</li> <li>router.send('billingAddressUpdated') when BillingAddressModel changes (either via user action or async data load)</li> <li>billingAddressUpdated event transitions between 'method' and 'address' substates as appropriate </li> </ul> <p>BTW You'll need to use HEAD ember for this approach, as substates without routes were broken until a recent commit.</p> <p>Very curious to learn how others approach this problem. Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload