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

Get last transition from current state? #6

Open
dhiraj opened this issue Oct 29, 2016 · 2 comments
Open

Get last transition from current state? #6

dhiraj opened this issue Oct 29, 2016 · 2 comments

Comments

@dhiraj
Copy link

dhiraj commented Oct 29, 2016

Is it possible to get the transition that was used to get to the current state of the FSM?

I'm currently having to loop over all the state variables, adding onEnter transitions to each just so that I can update a member property. While doing this seems to be working, I worry that I will forget to add a state into the loop's array and it will not get tracked.

@cipriancaba
Copy link
Owner

When you define an onEnter handler for a specific state, you will receive the transition as parameter, as shown below

locked.onEnter = { (transition: TurnstileTransition) -> Void in
  // called when the locked state defined above is entered. You also receive the type of transition that generated the state change
}

However, maybe I didn't understand the question correctly. Would you maybe be interested in a generic state handler that gets called for all of the state changes?

@dhiraj
Copy link
Author

dhiraj commented Nov 20, 2016

Yes, I was interested in having a generic state handler that would be called for all state changes. As it currently is, we have to write a separate handler for every state change.

But there are common functionalities that could be performed on every state change (like reset UI defaults, or model variables, etc.) that we need to call from every state change handler, where there's a chance we can forget to add the call in a new state handler that we're adding later, perhaps.

In my particular case, I was looking to have only 1 common state change handler across all states, where the UI would be updated with switch case handling all possible states. I did this by manually calling into my update UI method every time I did a transition, but having a common handler would be much cleaner, of course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants