Skip to content

Instantly share code, notes, and snippets.

@featzima
Created November 28, 2018 09:28
Show Gist options
  • Save featzima/c3d1ae5f9bb76a9ddbbffdd6c36f6d83 to your computer and use it in GitHub Desktop.
Save featzima/c3d1ae5f9bb76a9ddbbffdd6c36f6d83 to your computer and use it in GitHub Desktop.
private sealed class State {
object KerberosAuthorization : State()
object EmailAuthorization : State()
object UsernameAuthorization : State()
object ExchangeUrlAuthorization : State()
}
private sealed class Event {
object OnKerberosAuthorizationFailed : Event()
object OnEmailAuthorizationFailed : Event()
object OnUsernameAuthorizationFailed : Event()
}
private class SideEffect
private val stateMachine = StateMachine.create<State, Event, SideEffect> {
initialState(State.KerberosAuthorization)
state<State.KerberosAuthorization> {
on<Event.OnKerberosAuthorizationFailed> {
transitionTo(State.EmailAuthorization, SideEffect())
}
}
state<State.EmailAuthorization> {
on<Event.OnEmailAuthorizationFailed> {
transitionTo(State.UsernameAuthorization, SideEffect())
}
}
state<State.UsernameAuthorization> {
on<Event.OnUsernameAuthorizationFailed> {
transitionTo(State.ExchangeUrlAuthorization, SideEffect())
}
}
onTransition {
val validTransition = it as? StateMachine.Transition.Valid ?: return@onTransition
state.postValue(validTransition.toState)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment