-
Notifications
You must be signed in to change notification settings - Fork 93
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
Support for Hierarchical State Machine? #8
Comments
Hi @Bouke, thanks for your feedback. Your situation can be solved using
For more information, please see blacklisting technique in: StateMachineTests.swift#L116-L129 |
Oops, I forgot the handler part. Please use this instead: You can also do like this:
|
Well that's also what I meant by using the This state machine allows to go from Another solution would be to use SFSM (nested FSM), this could be modelled as 4 different state machines: Or the following picture, where an UML state machine is shown. In my example case both A and B would be within s1, and the transition from s1 to s2 would equal the |
Improve #8 by adding another `=>` helper to create StateRoute (conditional transition) using array.
Thank you for detailed information! To achieve your
Now complex routing becomes more declarative and understandable :) For nested FSM, please let me take some more time to dig into. |
Thanks for the changes, that already cleaned up some code. 👍 Being able to also specify handlers that way, would also be great. However these changes somewhat eases the burden on complex state machines; it would still be able to address so-to-speak categories. Like in the example above only define |
I added a |
I will merge #10 anyway and close this issue. |
Sorry, i haven't been able to look at this thoroughly. Good to hear that you'll be merging your solution. However, would it be somehow possible to also create a HSM with static typed states, with enums? |
In ver 4.0.0, I refactored many codes and now states with enums are supported for hierarchical state machine. |
Hi @inamiy, I really like your take on state machines in Swift. I'm now running into an issue in which support for a Hierarchical State Machine would benefit the architectural design. For example, I have three states: A, B and C. A and B are two variants; and it is possible to go from either A or B to C. However, from C it is only possible to go to A. So I would need a handler (A, B) => C and C => A. However SwiftState doesn't allow me to create a handler (A, B) => C, so either I duplicate the handler (no good), or disregard the current state and add nil => C (but that also allows C => C, and a future D => C). As the states grow complexer, this would result in headaches; as adding yet another state would require re-evaluating all the current handlers.
The text was updated successfully, but these errors were encountered: