small structure changes for less redundancy

This commit is contained in:
Nathaniel Tampus
2023-03-12 13:29:06 +08:00
parent fb43d2d9c7
commit e2a0f361cf
5 changed files with 183 additions and 192 deletions

View File

@@ -0,0 +1,21 @@
import type { Action, CustomSquares, Lobby } from "@/types";
export function lobbyReducer(lobby: Lobby, action: Action): Lobby {
switch (action.type) {
case "updateLobby":
return { ...lobby, ...action.payload };
case "setSide":
return { ...lobby, side: action.payload };
case "setGame":
return { ...lobby, actualGame: action.payload };
default:
throw new Error("Invalid action type");
}
}
export function squareReducer(squares: CustomSquares, action: Partial<CustomSquares>) {
return { ...squares, ...action };
}