Skip to content

Instantly share code, notes, and snippets.

@iskenxan
Last active May 23, 2021 18:03
Show Gist options
  • Save iskenxan/09e153cd7f5aa815b5eff0fad76faba1 to your computer and use it in GitHub Desktop.
Save iskenxan/09e153cd7f5aa815b5eff0fad76faba1 to your computer and use it in GitHub Desktop.
import { generateDoorsContent } from "./utils";
const generateDoors = () => {
const initialContent = generateDoorsContent();
return [
{ behind: initialContent[0], isOpen: false },
{ behind: initialContent[1], isOpen: false },
{ behind: initialContent[2], isOpen: false }
];
};
export const INITIAL_STATE = {
doors: generateDoors()
};
export const RESET = "RESET";
export const OPEN_DOOR = "OPEN_DOOR";
export const UNDO = "UNDO";
export const reducer = (state, action) => {
return produce(
state,
(draft) => {
switch (action.type) {
case OPEN_DOOR: {
const { index } = action.payload;
draft.doors[index].isOpen = true;
break;
}
case RESET: {
draft.doors = generateDoors();
break;
}
default:
break;
}
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment