summaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
authorVictor Chabbert <chabbertvi@eisti.eu>2017-01-23 09:36:09 +0100
committerVictor Chabbert <chabbertvi@eisti.eu>2017-01-23 09:36:09 +0100
commit5552b7f22e7d6b6ac4646e5ebd0f848525de2ef3 (patch)
tree1df25c06388910d17a077d033bf9c2704807b546 /frontend
parentUse 7 wonders logo in the layout (diff)
downloadseven-wonders-5552b7f22e7d6b6ac4646e5ebd0f848525de2ef3.tar.gz
seven-wonders-5552b7f22e7d6b6ac4646e5ebd0f848525de2ef3.tar.bz2
seven-wonders-5552b7f22e7d6b6ac4646e5ebd0f848525de2ef3.zip
Resolves #2: Manual cancellation of sagas
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/routes.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/frontend/src/routes.js b/frontend/src/routes.js
index a707c435..c0adcde5 100644
--- a/frontend/src/routes.js
+++ b/frontend/src/routes.js
@@ -1,15 +1,20 @@
-import { spawn } from 'redux-saga/effects'
+import { fork, take, cancel } from 'redux-saga/effects'
import usernameChoiceSaga from './sagas/usernameChoice'
import gameBrowserSaga from './sagas/gameBrowser'
+import { LOCATION_CHANGE } from 'react-router-redux'
-// TODO: Remove spawn saga when redux-saga-router has cancelable saga on route change
export const makeSagaRoutes = wsConnection => ({
*'/'() {
- // FIXME: spawn is a memory whore because the saga lives forever
- yield spawn(usernameChoiceSaga, wsConnection)
+ const saga = yield fork(usernameChoiceSaga, wsConnection)
+ yield take(LOCATION_CHANGE)
+ yield cancel(saga)
+ yield console.log('canceled home')
},
*'/games'() {
- yield spawn(gameBrowserSaga, wsConnection)
+ const saga = yield fork(gameBrowserSaga, wsConnection)
+ yield take(LOCATION_CHANGE)
+ yield cancel(saga)
+ yield console.log('canceled games')
}
})
bgstack15