rsnext/examples/with-redux-saga/saga.js
Todor Totev 22b2920aac
enhance-with-redux-saga (#13764)
[11014](https://github.com/vercel/next.js/issues/11014)

Removed getInitialProps from _app
2020-06-05 14:59:13 +00:00

29 lines
677 B
JavaScript

import { all, call, delay, put, take, takeLatest } from 'redux-saga/effects'
import { actionTypes, failure, loadDataSuccess, tickClock } from './actions'
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