summaryrefslogtreecommitdiff
path: root/frontend/src/sagas/home.ts
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2019-05-05 11:22:58 +0200
committerjbion <joffrey.bion@amadeus.com>2019-05-06 18:33:14 +0200
commit347877687301ec43367105a7f8c49fe16129fc00 (patch)
tree4999cf1978527658f70a21ce59d5f5d08a7169fd /frontend/src/sagas/home.ts
parentConvert reducers to typescript (diff)
downloadseven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.gz
seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.tar.bz2
seven-wonders-347877687301ec43367105a7f8c49fe16129fc00.zip
Convert redux sagas to TypeScript
Diffstat (limited to 'frontend/src/sagas/home.ts')
-rw-r--r--frontend/src/sagas/home.ts28
1 files changed, 28 insertions, 0 deletions
diff --git a/frontend/src/sagas/home.ts b/frontend/src/sagas/home.ts
new file mode 100644
index 00000000..585c536e
--- /dev/null
+++ b/frontend/src/sagas/home.ts
@@ -0,0 +1,28 @@
+import { push } from 'react-router-redux';
+import { eventChannel, SagaIterator } from 'redux-saga';
+import { all, apply, call, put, take } from 'redux-saga/effects';
+import { ApiPlayer } from '../api/model';
+import { SevenWondersSession } from '../api/sevenWondersApi';
+import { actions, REQUEST_CHOOSE_USERNAME } from '../redux/actions/user';
+
+function* sendUsername(session: SevenWondersSession): SagaIterator {
+ while (true) {
+ const { username } = yield take(REQUEST_CHOOSE_USERNAME);
+ // $FlowFixMe
+ yield apply(session, session.chooseName, [username]);
+ }
+}
+
+function* validateUsername(session: SevenWondersSession): any {
+ const usernameChannel = yield eventChannel(session.watchNameChoice());
+ while (true) {
+ const user: ApiPlayer = yield take(usernameChannel);
+ yield put(actions.setCurrentPlayer(user));
+ yield apply(usernameChannel, usernameChannel.close);
+ yield put(push('/games'));
+ }
+}
+
+export function* homeSaga(session: SevenWondersSession): SagaIterator {
+ yield all([call(sendUsername, session), call(validateUsername, session)]);
+}
bgstack15