-
Notifications
You must be signed in to change notification settings - Fork 130
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
Is there a wildcard state syntax to signify all states? #27
Comments
state(StateMachine.Matcher.any()) {
on<Event.reset> {
transitionTo(State.Start)
}
} |
I tried the above syntax for transitioning from any state, and it does not work. I have a state machine defined and I am building up a set of test cases for each transition. All the state transitions work except the wildcard state matching above. My state machine definition:
This test passes:
This test fails:
The error message says the expected state is Thanks for any guidance you can give me. I am transitioning from Java to Kotlin, and the learning curve is steep! |
This doesn't work because if there are multiple definitions for the same state then the first one is used. This is from
You have two definitions for First:
and second:
and only the first one is used. You could move I guess the only way to do this would be to add the default transitions to every state unfortunately. You can define it like:
And then call if for every state like:
|
@kz89 Thanks for your quick reply! Your solution worked like a charm. Another solution, since the state machine is so small, is to add the following at the end of every state transition definition:
This seems to work as well, as all tests that I wrote passed, too. |
Is there a way to express all states as the start of a transition? In other words, if there is a transition that causes all states to go to one single state, how can that be expressed in the transition code? For example, consider a 'reset' transition that makes the state machine go to a Start state regardless of the current state I can write a transition rule from each state to Start using the event reset, but it would be more readable to have something like
Is there a syntax for something like this?
Thanks!
Mark
The text was updated successfully, but these errors were encountered: