Skip to content

Instantly share code, notes, and snippets.

@GianpaMX
Created August 26, 2020 22:46
Show Gist options
  • Save GianpaMX/57592fd97fb8df4d5c163443bffee8a8 to your computer and use it in GitHub Desktop.
Save GianpaMX/57592fd97fb8df4d5c163443bffee8a8 to your computer and use it in GitHub Desktop.
suspend operator fun invoke(action: Action): State {
val currentState = transitionApi
.getLastTransition()
?.state
?: throw IllegalNullStateException
val nextState = when {
currentState == State.IDLE && action == Action.START -> State.POMODORO
currentState == State.POMODORO && action == Action.STOP -> State.IDLE
currentState == State.POMODORO && action == Action.COMPLETE -> State.DONE
currentState == State.DONE && action == Action.TAKE -> State.BREAK
currentState == State.BREAK && action == Action.START -> State.POMODORO
currentState == State.BREAK && action == Action.COMPLETE -> State.IDLE
else -> throw IllegalActionException(currentState, action)
}
transitionApi.newTransition(timeApi.now(), nextState)
return nextState
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment