diff options
author | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-22 13:45:26 +0100 |
---|---|---|
committer | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-22 14:48:37 +0100 |
commit | 91f2a61a7f5376c742da791523814bb4839b01ee (patch) | |
tree | e6cdbac1e062ebadb84a476bdba01cde231c1e36 /frontend/src/redux/players.js | |
parent | Fix node_modules path in travis.yml (diff) | |
download | seven-wonders-91f2a61a7f5376c742da791523814bb4839b01ee.tar.gz seven-wonders-91f2a61a7f5376c742da791523814bb4839b01ee.tar.bz2 seven-wonders-91f2a61a7f5376c742da791523814bb4839b01ee.zip |
Refactor user reducer to player reducer
Diffstat (limited to 'frontend/src/redux/players.js')
-rw-r--r-- | frontend/src/redux/players.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/frontend/src/redux/players.js b/frontend/src/redux/players.js new file mode 100644 index 00000000..e49d4bbf --- /dev/null +++ b/frontend/src/redux/players.js @@ -0,0 +1,36 @@ +import { fromJS } from 'immutable' + +export const types = { + SET_USERNAME: 'USER/SET_USERNAME', + CHOOSE_USERNAME: 'USER/CHOOSE_USERNAME' +} + +export const actions = { + setUsername: (username, displayName, index) => ({ + type: types.SET_USERNAME, + username, + index, + displayName + }), + chooseUsername: (username) => ({ type: types.CHOOSE_USERNAME, username }), +} + + +const initialState = fromJS({ + all: {}, + current: null +}) + +export default (state = initialState, action) => { + switch (action.type) { + case types.SET_USERNAME: + const user = fromJS({ + username: action.username, + displayName: action.displayName, + index: action.index, + }) + return state.setIn(['all', user.get('username')], user).set('current', user.get('username')) + default: + return state + } +} |