Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation for StateManager #682

Merged
merged 5 commits into from
Apr 14, 2012

Conversation

trek
Copy link
Member

@trek trek commented Apr 12, 2012

No description provided.

@wagenet
Copy link
Member

wagenet commented Apr 13, 2012

Looks pretty good, though I'm not the expert on States. However, from what I understand, you really should only call goToState from within a state action. You generally should rely on actions to transition the manager to a different state.

@trek
Copy link
Member Author

trek commented Apr 13, 2012

Excellent, just the sort of discussion I was hoping for. I've seen state actions mentioned several times, and always with the admonishment to always/only call them from "within a state". Sadly nobody ever provides an example of usage. I have an inkling of what they're getting – or at least suspect I do.

@wagenet
Copy link
Member

wagenet commented Apr 13, 2012

@trek Thanks for getting this discussion going!

I think it the scenario would look something like this:

Two states: unauthenticated, authenticated. You start in unauthenticated. To go to authenticated, don't call stateManager.goToState('authenticated'). Instead, make an action on unauthenticated called authenticate and call goToState in that action. Does that make sense?

@trek
Copy link
Member Author

trek commented Apr 13, 2012

That seems to be the go-to example, but nobody mentions where to make the call to the action. The presence of stateManager.send and parts of ActionHelper imply you'd call the send with the action name on the StateManager instance and let it handle finding the correct action function to call?

  aStateManager = Em.StateManager.create({
    initialState: 'unauthenticated',
    authenticated: Em.State.create({}),
    unauthenticated: Em.State.create({
      authenticate: function(stateManager, context){
        stateManager.goToState('authenticated')
      }
    })
  })

  aStateManager.send('authenticate')
  aStateManager.currentState.name // 'authenticated'

@wagenet
Copy link
Member

wagenet commented Apr 13, 2012

@trek The code you have above is my understanding of the recommended way to do it.

@jgwhite
Copy link
Contributor

jgwhite commented Apr 13, 2012

Terrific write up of Ember’s StateManager and a nice introduction to State Machines generally.

<h2>Photos</h2>
</div>
</body>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really be dashboard.get('navigationAreaView'), in case that property ever becomes watched for whatever reason.

@tomdale
Copy link
Member

tomdale commented Apr 13, 2012

Thanks Trek. @wagenet nailed our current feelings on how states should be built--dispatch events using send() and have them be the ones to call goToState(). By default, state managers will throw an exception if you send an event and it is not handled by the current state or one of its parent states. We may want to cover turning this feature on or off.

The other nit-pick I had was that there a few places where you're not using the get() accessor method. It happens to work in the examples because the given properties never become watched, but I'd prefer to use the idiomatic Ember way to make sure we're consistent and don't confuse newbies.

@wonk
Copy link

wonk commented Apr 13, 2012

Yow, delicious information!

Trek, thank you for such wonderful docs. (And thank you emberjs for such a juicy state machine.)

@trek
Copy link
Member Author

trek commented Apr 13, 2012

@tomdale are you talking about just the calls to dashboard.contentAreaView or also the areas where I'm checking the currentState name to demonstrate state changes? dashboard.contentAreaView should defiantly change but my gut reaction on the examples for verification of state name was to isolate only StateManager related behavior. I can change them over to getPath() if you think it won't complicated the examples.

@tomdale
Copy link
Member

tomdale commented Apr 14, 2012

@trek Yep, I'd change the state name stuff to getPath(). The reason is that I can't guarantee that a future implementation change may make some of those computed properties, in which case we'd probably forget to go back and update the documentation. :P


<body>
<script type='text/x-handlebars'>
<a href="#" {{action "anAction" target="App.appStates"}}> Go </a>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the the target here should be App.states not App.appStates? If not then can you add a bit explaining how appStates translates to the App.states property below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it's just a typo.

@tomdale
Copy link
Member

tomdale commented Apr 14, 2012

Gonna merge this in. @trek, if you have any more changes, please submit a new PR. Thanks!

tomdale added a commit that referenced this pull request Apr 14, 2012
@tomdale tomdale merged commit 6f3568c into emberjs:master Apr 14, 2012
sandstrom pushed a commit to sandstrom/ember.js that referenced this pull request Jun 17, 2021
…rn/ember-data-3.22.0

Bump ember-data from 3.21.2 to 3.22.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants