1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00
chess/web/static/js/reducers/chess-board.js
Dan Barber d888ab8d83
Make sure the JS works in PhantomJS
PhantomJS does not implement `Object.assign` which is how we were
updating the state immutably. I've switched it over to use the
ImmutableJS library instead.
2016-12-22 10:28:33 +00:00

37 lines
874 B
JavaScript

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