mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
7adb6c57f4
Hi there I noticed you have not yet included the api breaking changes in `"redux-saga": "1.0.0"`. Therefore I felt free to upgrade the dependencies in `examples/with-redux-saga`. I do not know anything about apollo nor graphql, that is why I did not upgrade `examples/with-apollo-and-redux-saga`. But, I think you should do this on occasion. Keep the great work up. Regards
37 lines
791 B
JavaScript
37 lines
791 B
JavaScript
/* global fetch */
|
|
|
|
import { all, call, delay, 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 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
|