rsnext/examples/with-redux-saga/saga.js
Willian Justen 18dc1f66c6 Remove isomorphic-unfetch from examples (#12948)
Since 9.4 release, fetch is pollyfilled by default from #12353,
so the import is not needed anymore.
2020-05-15 22:23:55 +02:00

33 lines
738 B
JavaScript

import { all, call, delay, put, take, takeLatest } from 'redux-saga/effects'
import es6promise from 'es6-promise'
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