diff options
author | Joffrey BION <joffrey.bion@gmail.com> | 2019-05-03 01:27:22 +0200 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-05-06 18:33:14 +0200 |
commit | 0d09d870d9adf789232a5e6165f44c605839833a (patch) | |
tree | 304cabb01f2b3a9b9afd338f784d957a5a55dd48 /frontend/src/redux/currentGame.ts | |
parent | Convert redux actions to typescript (diff) | |
download | seven-wonders-0d09d870d9adf789232a5e6165f44c605839833a.tar.gz seven-wonders-0d09d870d9adf789232a5e6165f44c605839833a.tar.bz2 seven-wonders-0d09d870d9adf789232a5e6165f44c605839833a.zip |
Convert reducers to typescript
Diffstat (limited to 'frontend/src/redux/currentGame.ts')
-rw-r--r-- | frontend/src/redux/currentGame.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/frontend/src/redux/currentGame.ts b/frontend/src/redux/currentGame.ts new file mode 100644 index 00000000..76006677 --- /dev/null +++ b/frontend/src/redux/currentGame.ts @@ -0,0 +1,41 @@ +import { combineReducers } from 'redux'; +import { ApiPlayerTurnInfo, ApiTable } from '../api/model'; +import { GlobalState } from '../reducers'; +import { Action } from './actions/all'; +import { TABLE_UPDATE_RECEIVED, TURN_INFO_RECEIVED } from './actions/game'; + +export type CurrentGameState = { + turnInfo: ApiPlayerTurnInfo | null; + table: ApiTable | null; +} + +export function createCurrentGameReducer() { + return combineReducers({ + turnInfo: turnInfoReducer, + table: tableUpdatesReducer, + }); +} + +const turnInfoReducer = (state: ApiPlayerTurnInfo | null = null, action: Action) => { + switch (action.type) { + case TURN_INFO_RECEIVED: + return action.turnInfo; + case TABLE_UPDATE_RECEIVED: + return null; + default: + return state; + } +}; + +const tableUpdatesReducer = (state: ApiTable | null = null, action: Action) => { + switch (action.type) { + case TURN_INFO_RECEIVED: + return action.turnInfo.table; + case TABLE_UPDATE_RECEIVED: + return action.table; + default: + return state; + } +}; + +export const getCurrentTurnInfo = (state: GlobalState): ApiPlayerTurnInfo | null => state.currentGame.turnInfo; |