mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
cf31021e25
This reverts the changes made in [this pr](https://github.com/zeit/next.js/pull/6109). `redux-saga: "1.0.0"` changed the way it handles it's queues. Because of that we're still having trouble to implement the synchronous side-effects flow in `next-redux-saga`. See [this discussion](https://github.com/bbortt/next-redux-saga/pull/1) for more information. Therefore I would feel more comfortable not to mislead users by giving them a non-working example in the main branch.
38 lines
825 B
JavaScript
38 lines
825 B
JavaScript
/* global fetch */
|
|
|
|
import { delay } from 'redux-saga'
|
|
import { all, call, put, take, takeLatest } from 'redux-saga/effects'
|
|
import es6promise from 'es6-promise'
|
|
import 'isomorphic-unfetch'
|
|
|
|
import { actionTypes, failure, loadDataSuccess, tickClock } from './actions'
|
|
|
|
es6promise.polyfill()
|
|
|
|
function * runClockSaga () {
|
|
yield take(actionTypes.START_CLOCK)
|
|
while (true) {
|
|
yield put(tickClock(false))
|
|
yield call(delay, 1000)
|
|
}
|
|
}
|
|
|
|
function * loadDataSaga () {
|
|
try {
|
|
const res = yield fetch('https://jsonplaceholder.typicode.com/users')
|
|
const data = yield res.json()
|
|
yield put(loadDataSuccess(data))
|
|
} catch (err) {
|
|
yield put(failure(err))
|
|
}
|
|
}
|
|
|
|
function * rootSaga () {
|
|
yield all([
|
|
call(runClockSaga),
|
|
takeLatest(actionTypes.LOAD_DATA, loadDataSaga)
|
|
])
|
|
}
|
|
|
|
export default rootSaga
|