Created
October 9, 2020 13:33
-
-
Save alexmachina/92992ae8eec1c26f1beccb4991fdb874 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
| import { parseTime } from "./functions"; | |
| type IAction = { | |
| type: string; | |
| payload?: ITimerState; | |
| }; | |
| const reducer = (state: ITimerState, action: IAction): ITimerState => { | |
| switch (action.type) { | |
| case "decrement": | |
| const ms = state.ms - 1000; | |
| const time = parseTime(ms); | |
| return { ...state, ms, time }; | |
| case "play": | |
| return { ...state, status: "running" }; | |
| case "pause": | |
| return { ...state, status: "paused" }; | |
| case "finish": | |
| return { | |
| ...state, | |
| status: "finished", | |
| }; | |
| case "reset": | |
| return { ...state, ...action.payload }; | |
| default: | |
| return state; | |
| } | |
| }; | |
| export default reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment