From 5cef37c529d99a213f222309b9b21180a4d22ce4 Mon Sep 17 00:00:00 2001 From: Dan Barber Date: Tue, 8 May 2018 14:46:32 -0400 Subject: [PATCH] Refactor available moves JS --- assets/js/components/chess-board-square.js | 4 ++-- assets/js/reducers/chess-board.js | 4 ++-- assets/js/services/channel.js | 2 +- assets/js/store/actions.js | 8 ++++---- assets/js/store/default-state.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/assets/js/components/chess-board-square.js b/assets/js/components/chess-board-square.js index bbb0c6e..57ad6a5 100644 --- a/assets/js/components/chess-board-square.js +++ b/assets/js/components/chess-board-square.js @@ -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(); }); } diff --git a/assets/js/reducers/chess-board.js b/assets/js/reducers/chess-board.js index 3a9d3b6..4519338 100644 --- a/assets/js/reducers/chess-board.js +++ b/assets/js/reducers/chess-board.js @@ -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": diff --git a/assets/js/services/channel.js b/assets/js/services/channel.js index 2330de2..72ce905 100644 --- a/assets/js/services/channel.js +++ b/assets/js/services/channel.js @@ -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)); }); } diff --git a/assets/js/store/actions.js b/assets/js/store/actions.js index 96ea577..400e4c2 100644 --- a/assets/js/store/actions.js +++ b/assets/js/store/actions.js @@ -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, }; }; diff --git a/assets/js/store/default-state.js b/assets/js/store/default-state.js index 1a3102e..743c392 100644 --- a/assets/js/store/default-state.js +++ b/assets/js/store/default-state.js @@ -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 },