diff options
author | jbion <joffrey.bion@amadeus.com> | 2019-05-05 11:22:58 +0200 |
---|---|---|
committer | jbion <joffrey.bion@amadeus.com> | 2019-05-06 18:33:14 +0200 |
commit | 347877687301ec43367105a7f8c49fe16129fc00 (patch) | |
tree | 4999cf1978527658f70a21ce59d5f5d08a7169fd /frontend/src/sagas/game.js | |
parent | Convert reducers to typescript (diff) | |
download | seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.gz seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.bz2 seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.zip |
Convert redux sagas to TypeScript
Diffstat (limited to 'frontend/src/sagas/game.js')
-rw-r--r-- | frontend/src/sagas/game.js | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/frontend/src/sagas/game.js b/frontend/src/sagas/game.js deleted file mode 100644 index 661c277b..00000000 --- a/frontend/src/sagas/game.js +++ /dev/null @@ -1,81 +0,0 @@ -import { eventChannel } from 'redux-saga'; -import { apply, call, put, take } from 'redux-saga/effects'; -import type { ApiPlayerTurnInfo, ApiPreparedCard, ApiTable } from '../api/model'; -import { SevenWondersSession } from '../api/sevenWondersApi'; -import { actions, REQUEST_PREPARE_MOVE, REQUEST_SAY_READY } from '../redux/actions/game'; -import { ENTER_GAME } from '../redux/actions/lobby'; - -function* watchPlayerReady(session: SevenWondersSession, gameId: number) { - const channel = yield eventChannel(session.watchPlayerReady(gameId)); - try { - while (true) { - const username = yield take(channel); - yield put(actions.receivePlayerReady(username)); - } - } finally { - yield apply(channel, channel.close); - } -} - -function* watchTableUpdates(session: SevenWondersSession, gameId: number) { - const channel = yield eventChannel(session.watchTableUpdates(gameId)); - try { - while (true) { - const table: ApiTable = yield take(channel); - yield put(actions.receiveTableUpdate(table)); - } - } finally { - yield apply(channel, channel.close); - } -} - -function* watchPreparedCards(session: SevenWondersSession, gameId: number) { - const channel = yield eventChannel(session.watchPreparedCards(gameId)); - try { - while (true) { - const preparedCard: ApiPreparedCard = yield take(channel); - yield put(actions.receivePreparedCard(preparedCard)); - } - } finally { - yield apply(channel, channel.close); - } -} - -function* sayReady(session: SevenWondersSession) { - while (true) { - yield take(REQUEST_SAY_READY); - yield apply(session, session.sayReady); - } -} - -function* prepareMove(session: SevenWondersSession) { - while (true) { - let action = yield take(REQUEST_PREPARE_MOVE); - yield apply(session, session.prepareMove, [action.move]); - } -} - -function* watchTurnInfo(session: SevenWondersSession) { - const channel = yield eventChannel(session.watchTurnInfo()); - try { - while (true) { - const turnInfo: ApiPlayerTurnInfo = yield take(channel); - yield put(actions.receiveTurnInfo(turnInfo)); - } - } finally { - yield apply(channel, channel.close); - } -} - -export function* gameSaga(session: SevenWondersSession) { - const { gameId } = yield take(ENTER_GAME); - console.log('Entered game!', gameId); - yield [ - call(watchPlayerReady, session, gameId), - call(watchTableUpdates, session, gameId), - call(watchPreparedCards, session, gameId), - call(sayReady, session), - call(prepareMove, session), - call(watchTurnInfo, session) - ]; -} |