summaryrefslogtreecommitdiff
path: root/frontend/src/redux/players.js
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-05-28 20:42:21 +0200
committerVictor Chabbert <chabbertvi@eisti.eu>2017-05-28 20:42:21 +0200
commit0bf423172ffb2e4030b521b0985d133cb5c61dd9 (patch)
tree0c24821770274a414f80b3092d5be54902c042d9 /frontend/src/redux/players.js
parentFix proxy not working since CRA upgrade (diff)
downloadseven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.tar.gz
seven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.tar.bz2
seven-wonders-0bf423172ffb2e4030b521b0985d133cb5c61dd9.zip
Move to immutable with Records
Diffstat (limited to 'frontend/src/redux/players.js')
-rw-r--r--frontend/src/redux/players.js21
1 files changed, 7 insertions, 14 deletions
diff --git a/frontend/src/redux/players.js b/frontend/src/redux/players.js
index b11e920f..85b579f3 100644
--- a/frontend/src/redux/players.js
+++ b/frontend/src/redux/players.js
@@ -1,4 +1,4 @@
-import Immutable from 'seamless-immutable';
+import PlayerState, { Player } from '../models/players';
export const types = {
REQUEST_CHOOSE_USERNAME: 'USER/REQUEST_CHOOSE_USERNAME',
@@ -21,24 +21,17 @@ export const actions = {
}),
};
-const initialState = Immutable.from({
- all: {},
- current: '',
-});
-
-export default (state = initialState, action) => {
+export default (state = new PlayerState(), 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);
+ return state.addPlayer(action.player);
case types.UPDATE_PLAYERS:
- return Immutable.merge(state, { all: action.players }, { deep: true });
+ return state.addPlayers(action.players);
default:
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 = players => players.all.get(players.current, new Player({ displayName: '[ERROR]' }));
+export const getPlayer = (players, username) => players.all.get(username);
+export const getPlayers = (players, usernames) => usernames.map(u => getPlayer(players, u));
bgstack15