summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-01-20 22:38:13 +0100
committerVictor Chabbert <chabbertvi@eisti.eu>2017-01-20 23:25:26 +0100
commitd5ec07ad1a077f72682d44cc74f8b84d41a4ab82 (patch)
tree5bae8ddb3699ffba717cb1244aae405a10e64683
parentFix duplicated calls of sagas based on history (diff)
downloadseven-wonders-d5ec07ad1a077f72682d44cc74f8b84d41a4ab82.tar.gz
seven-wonders-d5ec07ad1a077f72682d44cc74f8b84d41a4ab82.tar.bz2
seven-wonders-d5ec07ad1a077f72682d44cc74f8b84d41a4ab82.zip
Remove shitty code and move generator stars to the right
-rw-r--r--frontend/src/containers/HomePage/saga.js56
-rw-r--r--frontend/src/sagas.js11
2 files changed, 3 insertions, 64 deletions
diff --git a/frontend/src/containers/HomePage/saga.js b/frontend/src/containers/HomePage/saga.js
index 349a1d15..24f385c9 100644
--- a/frontend/src/containers/HomePage/saga.js
+++ b/frontend/src/containers/HomePage/saga.js
@@ -1,57 +1,5 @@
-import { call, put, take } from 'redux-saga/effects'
-import { eventChannel } from 'redux-saga'
-import { ENTER_GAME } from './actions'
-import { setUsername } from '../UserRepo/actions'
-
-import gameBrowserSaga from '../GameBrowser/saga'
-
-function* sendUsername(socketConnection) {
- const { username: playerName } = yield take(ENTER_GAME)
- const { socket } = socketConnection
-
- socket.send("/app/chooseName", JSON.stringify({
- playerName
- }), {})
-}
-
-function createSocketChannel(socket) {
- return eventChannel(emit => {
- const receiveUsername = socket.subscribe('/user/queue/nameChoice', event => {
- emit(JSON.parse(event.body))
- })
-
- const unsubscribe = () => {
- receiveUsername.unsubscribe()
- }
-
- return unsubscribe
- })
-}
-
-function* validateUsername(socketConnection) {
- const { socket } = socketConnection
- const socketChannel = createSocketChannel(socket)
-
- const response = yield take(socketChannel)
-
- if (response.error) {
- return false
- }
-
- yield put(setUsername(response.userName, response.displayName, response.index))
- return true
-}
-
-function* homeSaga(socketConnection) {
- console.log('here')
- let validated = false
- do {
- const [, usernameValid] = yield [
- call(sendUsername, socketConnection),
- call(validateUsername, socketConnection)
- ]
- validated = usernameValid
- } while (!validated)
+function *homeSaga(wsConnection) {
+ yield console.log('home saga')
}
export default homeSaga
diff --git a/frontend/src/sagas.js b/frontend/src/sagas.js
index 2e34a0b7..fc2c839f 100644
--- a/frontend/src/sagas.js
+++ b/frontend/src/sagas.js
@@ -3,19 +3,16 @@ import { call } from 'redux-saga/effects'
import createWsConnection from './utils/createWebSocketConnection'
-
-// import errorSaga from './containers/App/saga'
import homeSaga from './containers/HomePage/saga'
let wsConnection
const routes = {
*'/'() {
- yield console.info('home saga running')
yield homeSaga(wsConnection)
}
}
-function* wsAwareSagas(history) {
+export default function *rootSaga(history) {
try {
wsConnection = yield call(createWsConnection)
} catch (error) {
@@ -25,9 +22,3 @@ function* wsAwareSagas(history) {
yield* router(history, routes)
}
-
-export default function* rootSaga(history) {
- yield [
- call(wsAwareSagas, history)
- ]
-}
bgstack15