small structure changes for less redundancy
This commit is contained in:
21
client/src/components/game/reducers.ts
Normal file
21
client/src/components/game/reducers.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user