summaryrefslogtreecommitdiff
path: root/frontend/src/redux/players.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/redux/players.js')
-rw-r--r--frontend/src/redux/players.js44
1 files changed, 23 insertions, 21 deletions
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));
bgstack15