From 324b51049acac27ea3e7f71acad47aa729dfd8db Mon Sep 17 00:00:00 2001 From: Joffrey BION Date: Mon, 24 Jul 2017 23:51:43 +0200 Subject: Improve sevenWondersApi and types --- frontend/src/sagas/errors.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'frontend/src/sagas/errors.js') diff --git a/frontend/src/sagas/errors.js b/frontend/src/sagas/errors.js index 86fa0124..eece98c8 100644 --- a/frontend/src/sagas/errors.js +++ b/frontend/src/sagas/errors.js @@ -1,10 +1,13 @@ -import {apply, cancelled, take} from 'redux-saga/effects'; -import {toastr} from 'react-redux-toastr'; -import {ApiError, SevenWondersSession} from '../api/sevenWondersApi'; -import type {Channel} from 'redux-saga'; +// @flow +import { toastr } from 'react-redux-toastr' +import type { Channel } from 'redux-saga' +import { eventChannel } from 'redux-saga' +import { apply, cancelled, take } from 'redux-saga/effects' +import type { ApiError } from '../api/model' +import type { SevenWondersSession } from '../api/sevenWondersApi' -export default function* errorHandlingSaga(session: SevenWondersSession) { - const errorChannel: Channel = yield apply(session, session.watchErrors, []); +export default function* errorHandlingSaga(session: SevenWondersSession): * { + const errorChannel: Channel = yield eventChannel(session.watchErrors()); try { while (true) { const error: ApiError = yield take(errorChannel); @@ -18,7 +21,7 @@ export default function* errorHandlingSaga(session: SevenWondersSession) { } } -function* handleOneError(err: ApiError) { +function* handleOneError(err: ApiError): * { console.error('Error received on web socket channel', err); const msg = buildMsg(err); yield apply(toastr, toastr.error, [msg, { icon: 'error' }]); -- cgit