Move to Typescript.

This commit is contained in:
Manuel Friedli 2023-04-17 02:43:36 +02:00
parent 34618860a4
commit ac964ddd3f
16 changed files with 482 additions and 119 deletions

View file

@ -1,48 +0,0 @@
import handleUserClicked from "./userpathhandler";
export default function reduce(state, action) {
switch (action.type) {
case 'started_loading': {
return {
...state,
maze: null,
loading: true,
errorMessage: null
}
}
case 'loaded_maze': {
return {
...state,
loading: false,
maze: action.maze,
userPath: []
}
}
case 'loading_failed': {
return {
...state,
loading: false,
errorMessage: `Failed to load maze. Reason: ${action.reason}`
}
}
case 'toggled_show_solution': {
return {
...state,
showSolution: action.value
}
}
case 'closed_message_banner': {
return {
...state,
errorMessage: null
}
}
case 'clicked_cell': {
// There's so much logic involved, externalize that into its own file.
return handleUserClicked(state, action.x, action.y);
}
default: {
throw new Error(`Unknown action: ${action.type}`);
}
}
}