You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, so I was wondering if there's a recommended way to have more than one SideEffect for a transition? Is it simply repeating a transitionTo to the destination state but with different SideEffects?
And yes, I realize I could just simply have unique SideEffects for each transition, but that would lead to a lot of repeated code in my case. If I'm missing anything please let me know. Thanks!
For example (see // THIS comments):
val stateMachine =StateMachine.create<State, Event, SideEffect> {
initialState(State.Solid)
state<State.Solid> {
on<Event.OnMelted> {
transitionTo(State.Liquid, SideEffect.LogMelted)
transitionTo(State.Liquid, SideEffect.LogOtherLiquidInfo) // THIS
}
}
state<State.Liquid> {
on<Event.OnFroze> {
transitionTo(State.Solid, SideEffect.LogFrozen)
}
on<Event.OnVaporized> {
transitionTo(State.Gas, SideEffect.LogVaporized)
}
}
state<State.Gas> {
on<Event.OnCondensed> {
transitionTo(State.Liquid, SideEffect.LogCondensed)
transitionTo(State.Liquid, SideEffect.LogOtherLiquidInfo) // THIS
}
}
onTransition {
val validTransition = it as?StateMachine.Transition.Valid?:return@onTransition
when (validTransition.sideEffect) {
SideEffect.LogMelted-> logger.log(ON_MELTED_MESSAGE)
SideEffect.LogFrozen-> logger.log(ON_FROZEN_MESSAGE)
SideEffect.LogVaporized-> logger.log(ON_VAPORIZED_MESSAGE)
SideEffect.LogCondensed-> logger.log(ON_CONDENSED_MESSAGE)
SideEffect.LogOtherLiquidInfo-> logger.log(ON_OTHER_LIQUID_INFO) // THIS
}
}
}
The text was updated successfully, but these errors were encountered:
Oh, nevermind. In this case we could simply check the destination state, i.e. validTransition.toState == State.Liquid in the transition. So I guess this would be:
Hi, so I was wondering if there's a recommended way to have more than one SideEffect for a transition? Is it simply repeating a transitionTo to the destination state but with different SideEffects?
And yes, I realize I could just simply have unique SideEffects for each transition, but that would lead to a lot of repeated code in my case. If I'm missing anything please let me know. Thanks!
For example (see
// THIS
comments):The text was updated successfully, but these errors were encountered: