Skip to content

Instantly share code, notes, and snippets.

@alexmachina
Created October 9, 2020 13:33
Show Gist options
  • Select an option

  • Save alexmachina/92992ae8eec1c26f1beccb4991fdb874 to your computer and use it in GitHub Desktop.

Select an option

Save alexmachina/92992ae8eec1c26f1beccb4991fdb874 to your computer and use it in GitHub Desktop.
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