diff options
author | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-20 23:18:57 +0100 |
---|---|---|
committer | Victor Chabbert <chabbertvi@eisti.eu> | 2017-01-20 23:25:26 +0100 |
commit | cc3db2982dc22899a9ebea21e8a8dfbfd710f842 (patch) | |
tree | d8e138b300a8d8fded0651ac6be204d8c3342e68 /frontend/src/redux | |
parent | Remove shitty code and move generator stars to the right (diff) | |
download | seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.tar.gz seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.tar.bz2 seven-wonders-cc3db2982dc22899a9ebea21e8a8dfbfd710f842.zip |
DUCKS! Refactor front architecture
Diffstat (limited to 'frontend/src/redux')
-rw-r--r-- | frontend/src/redux/game.js | 27 | ||||
-rw-r--r-- | frontend/src/redux/user.js | 29 |
2 files changed, 56 insertions, 0 deletions
diff --git a/frontend/src/redux/game.js b/frontend/src/redux/game.js new file mode 100644 index 00000000..64373958 --- /dev/null +++ b/frontend/src/redux/game.js @@ -0,0 +1,27 @@ +import { Map } from 'immutable' + +export const types = { + NEW_GAME: 'GAME/NEW_GAME', + ENTER_GAME: 'GAME/ENTER_GAME', + JOIN_GAME: 'GAME/JOIN_GAME', + CREATE_GAME: 'GAME/CREATE_GAME', +} + +export const actions = { + newGame: (game) => ({ type: types.NEW_GAME, game }), + enterGame: (username) => ({ type: types.ENTER_GAME, username }), + joinGame: (id) => ({ type: types.JOIN_GAME, id }), + createGame: (name) => ({ type: types.CREATE_GAME, name }), +} + + +const initialState = Map({}) + +export default (state = initialState, action) => { + switch (action.type) { + case types.NEW_GAME: + return state.set(action.game.get('id'), action.game) + default: + return state + } +} diff --git a/frontend/src/redux/user.js b/frontend/src/redux/user.js new file mode 100644 index 00000000..0279b49c --- /dev/null +++ b/frontend/src/redux/user.js @@ -0,0 +1,29 @@ +import { fromJS } from 'immutable' + +export const types = { + SET_USERNAME: 'USER/SET_USERNAME', +} + +export const setUsername = (userName, displayName, index) => ({ + type: types.SET_USERNAME, + userName, + index, + displayName +}) + +const initialState = fromJS({ + username: '', + displayName: '', + id: null +}) + +export default (state = initialState, action) => { + switch (action.type) { + case types.SET_USERNAME: + return state.set('username', action.userName) + .set('displayName', action.displayName) + .set('id', action.index) + default: + return state + } +} |