Created
August 26, 2020 22:46
-
-
Save GianpaMX/57592fd97fb8df4d5c163443bffee8a8 to your computer and use it in GitHub Desktop.
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
| 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