1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Refactor available moves JS

This commit is contained in:
Daniel Barber 2018-05-08 14:46:32 -04:00
parent 5aedd339e0
commit 5cef37c529
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
5 changed files with 10 additions and 10 deletions

View File

@ -80,9 +80,9 @@ class ChessBoardSquare extends React.Component {
isAvailableSquare() {
const { store } = this.props;
const moves = store.getState().moves;
const availableMoves = store.getState().availableMoves;
return _.find(moves, (square) => {
return _.find(availableMoves, (square) => {
return square.join() == this.squareCoords.join();
});
}

View File

@ -18,9 +18,9 @@ const chessBoardReducer = (state = defaultState, action) => {
.set("moves", [])
.toJS();
case "SET_MOVES":
case "SET_AVAILABLE_MOVES":
return Immutable.fromJS(state)
.set("moves", action.moves)
.set("availableMoves", action.availableMoves)
.toJS();
case "SET_GAME_ID":

View File

@ -29,7 +29,7 @@ class Channel {
getAvailableMoves(square) {
this.channel.push("game:get_available_moves", { square })
.receive("ok", (data) => {
this.store.dispatch(setMoves(data.moves));
this.store.dispatch(setAvailableMoves(data.moves));
});
}

View File

@ -1,6 +1,6 @@
const SET_PLAYER = "SET_PLAYER";
const SET_GAME = "SET_GAME";
const SET_MOVES = "SET_MOVES";
const SET_AVAILABLE_MOVES = "SET_AVAILABLE_MOVES";
const SET_GAME_ID = "SET_GAME_ID";
const SELECT_PIECE = "SELECT_PIECE";
@ -20,10 +20,10 @@ export const setGame = (data) => {
};
};
export const setMoves = (moves) => {
export const setAvailableMoves = (availableMoves) => {
return {
type: SET_MOVES,
moves,
type: SET_AVAILABLE_MOVES,
availableMoves,
};
};

View File

@ -5,7 +5,7 @@ const defaultState = {
turn: null,
state: null,
moves: [],
availableMoves: [],
board: {
8: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },