import Shogi from '../src/shogi';
import * as CONST from '../constants/actionTypes';

const InitialState = {
  board: Shogi.Board,
  isHoldingPiece: undefined,
  blackPieceStand: [],
  whitePieceStand: [],
  promoteModal: false
};

const ShogiReducer = (state = InitialState, action) => {
  switch (action.type) {
  case CONST.HOLD_PIECE:
    if (action.piece.type == '*') {
      return state;
    } else {
      let newBoard = state.board.enhanceMovablePoint(action.piece);
      return Object.assign(
        {},
        state,
        {
          board: newBoard,
          blackPieceStand: state.blackPieceStand,
          whitePieceStand: state.whitePieceStand,
          isHoldingPiece: action.piece
        }
      );
    }
  case CONST.MOVE_PIECE:
    // if same piece click, release piece.
    if (state.isHoldingPiece) {
      let newBoard = state.board.movePiece(state.isHoldingPiece, action.piece);

      if (newBoard.takedPiece) {
        const takedPiece = newBoard.takedPiece;
        // TODO: Use constants. Refactor.
        switch (newBoard.takedPiece.team()) {
        case 'white':
          return Object.assign(
            {},
            state,
            {
              board: newBoard,
              isHoldingPiece: undefined,
              blackPieceStand: state.blackPieceStand.concat([takedPiece.toOpponentPiece()]),
              whitePieceStand: state.whitePieceStand
            }
          );
        case 'black':
          return Object.assign(
            {},
            state,
            {
              board: newBoard,
              isHoldingPiece: undefined,
              blackPieceStand: state.blackPieceStand,
              whitePieceStand: state.whitePieceStand.concat([takedPiece.toOpponentPiece()])
            }
          );
        }
      } else {
        return Object.assign(
          {},
          state,
          {
            board: newBoard,
            isHoldingPiece: undefined,
            blackPieceStand: state.blackPieceStand,
            whitePieceStand: state.whitePieceStand
          }
        );
      }
    } else {
      return Object.assign({}, state, { isHoldingPiece: action.piece });
    }
  case CONST.SHOW_PROMOTE_MODAL:
    return Object.assign({}, state, { promoteModal: true });
  case CONST.HIDE_PROMOTE_MODAL:
    return Object.assign({}, state, { promoteModal: false });
  default:
    return state;
  }
};

export default ShogiReducer;

@@ -4,2422 +4,172 @@
 ort 
-Shogi from '../src/shogi';%0Aimport * as CONST from '../constants/actionTypes';%0A%0Aconst InitialState = %7B%0A  board: Shogi.Board,%0A  isHoldingPiece: undefined,%0A  blackPieceStand: %5B%5D,%0A  whitePieceStand: %5B%5D,%0A  promoteModal: false%0A%7D;%0A%0Aconst ShogiReducer = (state = InitialState, action) =%3E %7B%0A  switch (action.type) %7B%0A  case CONST.HOLD_PIECE:%0A    if (action.piece.type == '*') %7B%0A      return state;%0A    %7D else %7B%0A      let newBoard = state.board.enhanceMovablePoint(action.piece);%0A      return Object.assign(%0A        %7B%7D,%0A        state,%0A        %7B%0A          board: newBoard,%0A          blackPieceStand: state.blackPieceStand,%0A          whitePieceStand: state.whitePieceStand,%0A          isHoldingPiece: action.piece%0A        %7D%0A      );%0A    %7D%0A  case CONST.MOVE_PIECE:%0A    // if same piece click, release piece.%0A    if (state.isHoldingPiece) %7B%0A      let newBoard = state.board.movePiece(state.isHoldingPiece, action.piece);%0A%0A      if (newBoard.takedPiece) %7B%0A        const takedPiece = newBoard.takedPiece;%0A        // TODO: Use constants. Refactor.%0A        switch (newBoard.takedPiece.team()) %7B%0A        case 'white':%0A          return Object.assign(%0A            %7B%7D,%0A            state,%0A            %7B%0A              board: newBoard,%0A              isHoldingPiece: undefined,%0A              blackPieceStand: state.blackPieceStand.concat(%5BtakedPiece.toOpponentPiece()%5D),%0A              whitePieceStand: state.whitePieceStand%0A            %7D%0A          );%0A        case 'black':%0A          return Object.assign(%0A            %7B%7D,%0A            state,%0A            %7B%0A              board: newBoard,%0A              isHoldingPiece: undefined,%0A              blackPieceStand: state.blackPieceStand,%0A              whitePieceStand: state.whitePieceStand.concat(%5BtakedPiece.toOpponentPiece()%5D)%0A            %7D%0A          );%0A        %7D%0A      %7D else %7B%0A        return Object.assign(%0A          %7B%7D,%0A          state,%0A          %7B%0A            board: newBoard,%0A            isHoldingPiece: undefined,%0A            blackPieceStand: state.blackPieceStand,%0A            whitePieceStand: state.whitePieceStand%0A          %7D%0A        );%0A      %7D%0A    %7D else %7B%0A      return Object.assign(%7B%7D, state, %7B isHoldingPiece: action.piece %7D);%0A    %7D%0A  case CONST.SHOW_PROMOTE_MODAL:%0A    return Object.assign(%7B%7D, state, %7B promoteModal: true %7D);%0A  case CONST.HIDE_PROMOTE_MODAL:%0A    return Object.assign(%7B%7D, state, %7B promoteModal: false %7D);%0A  default:%0A    return state;%0A  %7D%0A%7D;%0A%0Aexport default ShogiReducer
+%7B combineReducers %7D from 'redux';%0Aimport shogi from './shogi';%0Aimport promoteModal from './promoteModal';%0A%0Aexport default combineReducers(%0A  %7B shogi, promoteModal %7D%0A)
 ;%0A

Use combineReducers, Extract reducers.