summaryrefslogtreecommitdiff
path: root/frontend/src/redux/players.js
diff options
context:
space:
mode:
authorJoffrey Bion <joffrey.bion@gmail.com>2017-05-28 21:32:36 +0200
committerGitHub <noreply@github.com>2017-05-28 21:32:36 +0200
commitba9cd259ed1ca2370565265eab9fe2628ad6502c (patch)
tree0c24821770274a414f80b3092d5be54902c042d9 /frontend/src/redux/players.js
parentFix proxy not working since CRA upgrade (diff)
parentMove to immutable with Records (diff)
downloadseven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.tar.gz
seven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.tar.bz2
seven-wonders-ba9cd259ed1ca2370565265eab9fe2628ad6502c.zip
Merge pull request #14 from luxons/immutable
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