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:
parent
5aedd339e0
commit
5cef37c529
@ -80,9 +80,9 @@ class ChessBoardSquare extends React.Component {
|
|||||||
|
|
||||||
isAvailableSquare() {
|
isAvailableSquare() {
|
||||||
const { store } = this.props;
|
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();
|
return square.join() == this.squareCoords.join();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,9 +18,9 @@ const chessBoardReducer = (state = defaultState, action) => {
|
|||||||
.set("moves", [])
|
.set("moves", [])
|
||||||
.toJS();
|
.toJS();
|
||||||
|
|
||||||
case "SET_MOVES":
|
case "SET_AVAILABLE_MOVES":
|
||||||
return Immutable.fromJS(state)
|
return Immutable.fromJS(state)
|
||||||
.set("moves", action.moves)
|
.set("availableMoves", action.availableMoves)
|
||||||
.toJS();
|
.toJS();
|
||||||
|
|
||||||
case "SET_GAME_ID":
|
case "SET_GAME_ID":
|
||||||
|
|||||||
@ -29,7 +29,7 @@ class Channel {
|
|||||||
getAvailableMoves(square) {
|
getAvailableMoves(square) {
|
||||||
this.channel.push("game:get_available_moves", { square })
|
this.channel.push("game:get_available_moves", { square })
|
||||||
.receive("ok", (data) => {
|
.receive("ok", (data) => {
|
||||||
this.store.dispatch(setMoves(data.moves));
|
this.store.dispatch(setAvailableMoves(data.moves));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
const SET_PLAYER = "SET_PLAYER";
|
const SET_PLAYER = "SET_PLAYER";
|
||||||
const SET_GAME = "SET_GAME";
|
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 SET_GAME_ID = "SET_GAME_ID";
|
||||||
const SELECT_PIECE = "SELECT_PIECE";
|
const SELECT_PIECE = "SELECT_PIECE";
|
||||||
|
|
||||||
@ -20,10 +20,10 @@ export const setGame = (data) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const setMoves = (moves) => {
|
export const setAvailableMoves = (availableMoves) => {
|
||||||
return {
|
return {
|
||||||
type: SET_MOVES,
|
type: SET_AVAILABLE_MOVES,
|
||||||
moves,
|
availableMoves,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ const defaultState = {
|
|||||||
turn: null,
|
turn: null,
|
||||||
state: null,
|
state: null,
|
||||||
|
|
||||||
moves: [],
|
availableMoves: [],
|
||||||
|
|
||||||
board: {
|
board: {
|
||||||
8: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
8: { a: null, b: null, c: null, d: null, e: null, f: null, g: null, h: null },
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user