summaryrefslogtreecommitdiff
path: root/frontend/src/sagas/home.js
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/sagas/home.js')
-rw-r--r--frontend/src/sagas/home.js22
1 files changed, 12 insertions, 10 deletions
diff --git a/frontend/src/sagas/home.js b/frontend/src/sagas/home.js
index b51bf4dc..0b30f784 100644
--- a/frontend/src/sagas/home.js
+++ b/frontend/src/sagas/home.js
@@ -1,28 +1,30 @@
-import { apply, call, put, take } from 'redux-saga/effects';
-import { push } from 'react-router-redux';
+// @flow
+import { apply, call, put, take } from 'redux-saga/effects'
+import { push } from 'react-router-redux'
+import { eventChannel } from 'redux-saga'
-import { actions, types } from '../redux/players';
-import type { SevenWondersSession } from '../api/sevenWondersApi';
-import { createChannel } from './utils';
+import { actions, types } from '../redux/players'
+import type { SevenWondersSession } from '../api/sevenWondersApi'
+import type { ApiPlayer } from '../api/model'
-function* sendUsername(session: SevenWondersSession) {
+function* sendUsername(session: SevenWondersSession): * {
while (true) {
const { username } = yield take(types.REQUEST_CHOOSE_USERNAME);
yield apply(session, session.chooseName, [username]);
}
}
-function* validateUsername(session: SevenWondersSession) {
- const usernameChannel = yield createChannel(session, session.watchNameChoice);
+function* validateUsername(session: SevenWondersSession): * {
+ const usernameChannel = yield eventChannel(session.watchNameChoice());
while (true) {
- const user = yield take(usernameChannel);
+ const user: ApiPlayer = yield take(usernameChannel);
yield put(actions.setCurrentPlayer(user));
yield apply(usernameChannel, usernameChannel.close);
yield put(push('/games'));
}
}
-function* homeSaga(session: SevenWondersSession) {
+function* homeSaga(session: SevenWondersSession): * {
yield [call(sendUsername, session), call(validateUsername, session)];
}
bgstack15