diff options
Diffstat (limited to 'frontend/src/redux')
-rw-r--r-- | frontend/src/redux/app.js | 8 | ||||
-rw-r--r-- | frontend/src/redux/errors.js | 33 | ||||
-rw-r--r-- | frontend/src/redux/games.js | 53 | ||||
-rw-r--r-- | frontend/src/redux/players.js | 44 |
4 files changed, 73 insertions, 65 deletions
diff --git a/frontend/src/redux/app.js b/frontend/src/redux/app.js index 251b12a2..d24fbbfd 100644 --- a/frontend/src/redux/app.js +++ b/frontend/src/redux/app.js @@ -1,5 +1,5 @@ export const makeSelectLocationState = () => { - return (state) => { - return state.routing - } -} + return state => { + return state.routing; + }; +}; diff --git a/frontend/src/redux/errors.js b/frontend/src/redux/errors.js index 7d113db1..eb807fdc 100644 --- a/frontend/src/redux/errors.js +++ b/frontend/src/redux/errors.js @@ -1,37 +1,40 @@ -import Immutable from 'seamless-immutable' +import Immutable from "seamless-immutable"; export const types = { - ERROR_RECEIVED_ON_WS: 'ERROR/RECEIVED_ON_WS', -} + ERROR_RECEIVED_ON_WS: "ERROR/RECEIVED_ON_WS" +}; export const actions = { - errorReceived: (error) => ({ + errorReceived: error => ({ type: types.ERROR_RECEIVED_ON_WS, error - }), -} + }) +}; const initialState = Immutable.from({ nextId: 0, history: [] -}) +}); export default (state = initialState, action) => { switch (action.type) { case types.ERROR_RECEIVED_ON_WS: - let error = Object.assign({id: state.nextId, timestamp: new Date()}, action.error); - let newState = state.set('nextId', state.nextId + 1) - newState = addErrorToHistory(newState, error) - return newState + let error = Object.assign( + { id: state.nextId, timestamp: new Date() }, + action.error + ); + let newState = state.set("nextId", state.nextId + 1); + newState = addErrorToHistory(newState, error); + return newState; default: - return state + return state; } -} +}; function addErrorToHistory(state, error) { - return addToArray(state, 'history', error); + return addToArray(state, "history", error); } function addToArray(state, arrayKey, element) { - return state.set(arrayKey, state[arrayKey].concat([ element ])); + return state.set(arrayKey, state[arrayKey].concat([element])); } diff --git a/frontend/src/redux/games.js b/frontend/src/redux/games.js index 2986de07..a7115dcc 100644 --- a/frontend/src/redux/games.js +++ b/frontend/src/redux/games.js @@ -1,43 +1,46 @@ -import Immutable from 'seamless-immutable' +import Immutable from "seamless-immutable"; export const types = { - UPDATE_GAMES: 'GAME/UPDATE_GAMES', - REQUEST_CREATE_GAME: 'GAME/REQUEST_CREATE_GAME', - REQUEST_JOIN_GAME: 'GAME/REQUEST_JOIN_GAME', - REQUEST_START_GAME: 'GAME/REQUEST_JOIN_GAME', - ENTER_LOBBY: 'GAME/ENTER_LOBBY', - ENTER_GAME: 'GAME/ENTER_GAME', -} + UPDATE_GAMES: "GAME/UPDATE_GAMES", + REQUEST_CREATE_GAME: "GAME/REQUEST_CREATE_GAME", + REQUEST_JOIN_GAME: "GAME/REQUEST_JOIN_GAME", + REQUEST_START_GAME: "GAME/REQUEST_JOIN_GAME", + ENTER_LOBBY: "GAME/ENTER_LOBBY", + ENTER_GAME: "GAME/ENTER_GAME" +}; export const actions = { - updateGames: (games) => ({ type: types.UPDATE_GAMES, games: Immutable(games) }), - requestJoinGame: (gameId) => ({ type: types.REQUEST_JOIN_GAME, gameId }), - requestCreateGame: (gameName) => ({ type: types.REQUEST_CREATE_GAME, gameName }), + updateGames: games => ({ type: types.UPDATE_GAMES, games: Immutable(games) }), + requestJoinGame: gameId => ({ type: types.REQUEST_JOIN_GAME, gameId }), + requestCreateGame: gameName => ({ + type: types.REQUEST_CREATE_GAME, + gameName + }), requestStartGame: () => ({ type: types.REQUEST_START_GAME }), - enterLobby: (lobby) => ({ type: types.ENTER_LOBBY, lobby: Immutable(lobby) }), - enterGame: () => ({ type: types.ENTER_GAME }), -} + enterLobby: lobby => ({ type: types.ENTER_LOBBY, lobby: Immutable(lobby) }), + enterGame: () => ({ type: types.ENTER_GAME }) +}; const initialState = Immutable.from({ all: {}, - current: '' -}) + current: "" +}); export default (state = initialState, action) => { switch (action.type) { case types.UPDATE_GAMES: - return Immutable.merge(state, {all: action.games}, {deep: true}) + return Immutable.merge(state, { all: action.games }, { deep: true }); case types.ENTER_LOBBY: - return state.set('current', action.lobby.id) + return state.set("current", action.lobby.id); default: - return state + return state; } -} +}; -export const getAllGamesById = state => state.games.all +export const getAllGamesById = state => state.games.all; export const getAllGames = state => { - let gamesById = getAllGamesById(state) + let gamesById = getAllGamesById(state); return Object.keys(gamesById).map(k => gamesById[k]); -} -export const getGame = (state, id) => getAllGamesById(state)[id] -export const getCurrentGame = state => getGame(state, state.games.current) +}; +export const getGame = (state, id) => getAllGamesById(state)[id]; +export const getCurrentGame = state => getGame(state, state.games.current); diff --git a/frontend/src/redux/players.js b/frontend/src/redux/players.js index 2b530ca1..4016076f 100644 --- a/frontend/src/redux/players.js +++ b/frontend/src/redux/players.js @@ -1,44 +1,46 @@ -import Immutable from 'seamless-immutable' +import Immutable from "seamless-immutable"; export const types = { - REQUEST_CHOOSE_USERNAME: 'USER/REQUEST_CHOOSE_USERNAME', - SET_CURRENT_PLAYER: 'USER/SET_CURRENT_PLAYER', - UPDATE_PLAYERS: 'USER/UPDATE_PLAYERS' -} + REQUEST_CHOOSE_USERNAME: "USER/REQUEST_CHOOSE_USERNAME", + SET_CURRENT_PLAYER: "USER/SET_CURRENT_PLAYER", + UPDATE_PLAYERS: "USER/UPDATE_PLAYERS" +}; export const actions = { - chooseUsername: (username) => ({ + chooseUsername: username => ({ type: types.REQUEST_CHOOSE_USERNAME, username }), - setCurrentPlayer: (player) => ({ + setCurrentPlayer: player => ({ type: types.SET_CURRENT_PLAYER, player }), - updatePlayers: (players) => ({ + updatePlayers: players => ({ type: types.UPDATE_PLAYERS, players - }), -} + }) +}; const initialState = Immutable.from({ all: {}, - current: '' -}) + current: "" +}); export default (state = initialState, action) => { switch (action.type) { case types.SET_CURRENT_PLAYER: - const player = action.player - const withNewPlayer = state.setIn(['all', player.username], player) - return Immutable.set(withNewPlayer, 'current', player.username) + const player = action.player; + const withNewPlayer = state.setIn(["all", player.username], player); + return Immutable.set(withNewPlayer, "current", player.username); case types.UPDATE_PLAYERS: - return Immutable.merge(state, {all: action.players}, {deep: true}) + return Immutable.merge(state, { all: action.players }, { deep: true }); default: - return state + return state; } -} +}; -export const getCurrentPlayer = state => state.players.all && state.players.all[state.players.current] -export const getPlayer = (state, username) => state.players.all[username] -export const getPlayers = (state, usernames) => usernames.map(u => getPlayer(state, u)) +export const getCurrentPlayer = state => + state.players.all && state.players.all[state.players.current]; +export const getPlayer = (state, username) => state.players.all[username]; +export const getPlayers = (state, usernames) => + usernames.map(u => getPlayer(state, u)); |