1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/assets/js/reducers/chess-board.js
Dan Barber c0facfa4d5
Players take turns
Restricts players to only be able to move their own pieces and only when
it's their turn.
2018-02-24 15:52:22 -05:00

31 lines
713 B
JavaScript

import Immutable from "immutable";
import defaultState from "../store/default-state";
const chessBoardReducer = (state = defaultState, action) => {
switch (action.type) {
case "SET_GAME":
return Immutable.fromJS(state)
.set("board", action.board)
.set("player", action.player)
.set("turn", action.turn)
.set("selectedSquare", null)
.toJS();
case "SET_GAME_ID":
return Immutable.fromJS(state)
.set("gameId", action.gameId)
.toJS();
case "SELECT_PIECE":
return Immutable.fromJS(state)
.set("selectedSquare", action.coords)
.toJS();
default:
return state;
}
}
export default chessBoardReducer;