diff options
Diffstat (limited to 'frontend/src/sagas/usernameChoice.js')
-rw-r--r-- | frontend/src/sagas/usernameChoice.js | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/frontend/src/sagas/usernameChoice.js b/frontend/src/sagas/usernameChoice.js deleted file mode 100644 index ad5b5341..00000000 --- a/frontend/src/sagas/usernameChoice.js +++ /dev/null @@ -1,41 +0,0 @@ -import { call, take, put } from 'redux-saga/effects' -import { eventChannel } from 'redux-saga' -import { push } from 'react-router-redux' -import { fromJS } from 'immutable' - -import { actions, types } from '../redux/players' - -function usernameValidationChannel(socket) { - return eventChannel(emitter => { - const receiveUsernameHandler = socket.subscribe('/user/queue/nameChoice', event => { - emitter(fromJS(JSON.parse(event.body))) - }) - return () => receiveUsernameHandler.unsubscribe() - }) -} - -function *usernameValidation({ socket }) { - const usernameChannel = yield call(usernameValidationChannel, socket) - const user = yield take(usernameChannel) - yield put(actions.setCurrentPlayer(user)) - usernameChannel.close() - yield put(push('/games')) -} - -function *sendUsername({ socket }) { - const { username } = yield take(types.REQUEST_CHOOSE_USERNAME) - - yield socket.send('/app/chooseName', JSON.stringify({ - playerName: username - })) -} - -function *usernameChoiceSaga(wsConnection) { - // TODO: Run sendUsername in loop when we have the ability to cancel saga on route change - yield [ - call(sendUsername, wsConnection), - call(usernameValidation, wsConnection), - ] -} - -export default usernameChoiceSaga |