Open
Conversation
|
This would be great. |
JaviRpo
approved these changes
Jul 1, 2021
| .map { it.value } | ||
| .firstOrNull() ?: error("Missing definition for state ${this.javaClass.simpleName}!") | ||
| .also { if (it.isEmpty()) error("Missing definition for state ${this.javaClass.simpleName}!") } | ||
| .fold(Graph.State<STATE, EVENT, SIDE_EFFECT>()) { acc, state -> |
There was a problem hiding this comment.
I like this change, this also works when we want to have a generic transition
private val stateMachine = StateMachine.create<String, Int, Nothing> {
initialState(STATE_A)
state(STATE_A) {
on(EVENT_1) {
transitionTo(STATE_B)
}
}
state(STATE_B) {
on(EVENT_2) {
transitionTo(STATE_A)
}
}
state<String> {
on(EVENT_3) {
transitionTo(STATE_C)
}
}
}
for example, this one, having state<String> or state(any()) we can move from any state to another state with the same event.
|
What do we need for this PR to be merged and have a version with this change? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consider the following state machine:
Currently, trying to transition from
STATE_AonEVENT_1will result in a valid transition, but attempting a transition onEVENT_2will result in an invalid transition. There's no warning or error given neither for the secondSTATE_Anor the secondSTATE_Bdefinitions. A similar behavior can be observed for on exit and on enter listeners - onlyfirstDefinitionOnExitListenerandfirstDefinitionOnEnterListenerwill be called when transitioning fromSTATE_AtoSTATE_B.This PR aims to make state machines take into account all the state definitions passed to the graph builder. This is achieved by merging all applicable state definitions when resolving a transition for a given state and event instead of just taking the first one that matches.