diff options
author | Joffrey Bion <joffrey.bion@amadeus.com> | 2017-07-21 10:00:07 +0200 |
---|---|---|
committer | Joffrey Bion <joffrey.bion@amadeus.com> | 2017-07-21 16:29:16 +0200 |
commit | 859bafb1e4223216d8d818fb5566fd42aaf80705 (patch) | |
tree | 25994f3165019e5703c9647b3c435f86eb056cbb /frontend/src/sagas/home.js | |
parent | Rename actions in games.js (GAME -> GAMES) (diff) | |
download | seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.tar.gz seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.tar.bz2 seven-wonders-859bafb1e4223216d8d818fb5566fd42aaf80705.zip |
Isolate Seven Wonders API from sagas
Diffstat (limited to 'frontend/src/sagas/home.js')
-rw-r--r-- | frontend/src/sagas/home.js | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.js index 579c7fd6..eb65097b 100644 --- a/frontend/src/sagas/home.js +++ b/frontend/src/sagas/home.js @@ -1,18 +1,18 @@ import { apply, call, put, take } from 'redux-saga/effects'; -import { createSubscriptionChannel } from '../utils/websocket'; import { push } from 'react-router-redux'; import { actions, types } from '../redux/players'; +import type { SevenWondersSession } from '../api/sevenWondersApi'; -function* sendUsername({ socket }) { +function* sendUsername(session: SevenWondersSession) { while (true) { const { username } = yield take(types.REQUEST_CHOOSE_USERNAME); - yield apply(socket, socket.send, ['/app/chooseName', JSON.stringify({ playerName: username })]); + yield apply(session, session.chooseName, [username]); } } -function* validateUsername({ socket }) { - const usernameChannel = yield call(createSubscriptionChannel, socket, '/user/queue/nameChoice'); +function* validateUsername(session: SevenWondersSession) { + const usernameChannel = yield apply(session, session.watchNameChoice, []); while (true) { const user = yield take(usernameChannel); yield put(actions.setCurrentPlayer(user)); @@ -21,9 +21,8 @@ function* validateUsername({ socket }) { } } -function* usernameChoiceSaga(wsConnection) { - // TODO: Run sendUsername in loop when we have the ability to cancel saga on route change - yield [call(sendUsername, wsConnection), call(validateUsername, wsConnection)]; +function* homeSaga(session: SevenWondersSession) { + yield [call(sendUsername, session), call(validateUsername, session)]; } -export default usernameChoiceSaga; +export default homeSaga; |