1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/app/reducers/chess-board.js
2016-12-08 17:46:28 +01:00

23 lines
554 B
JavaScript

import defaultState from "store/default-state";
import movePiece from "reducers/move-piece";
const chessBoardReducer = (state = defaultState, action) => {
switch (action.type) {
case "MOVE_PIECE":
const newState = {
board: movePiece(state.board, action.from, action.to),
selectedSquare: null
}
return Object.assign({}, state, newState);
case "SELECT_PIECE":
return Object.assign({}, state, { selectedSquare: action.coords });
default:
return state;
}
}
export default chessBoardReducer;