2018-02-24 23:17:04 +00:00
|
|
|
import { put, takeLatest } from 'redux-saga/effects'
|
|
|
|
import es6promise from 'es6-promise'
|
2018-08-20 06:31:24 +00:00
|
|
|
import fetch from 'isomorphic-unfetch'
|
2018-02-24 23:17:04 +00:00
|
|
|
|
|
|
|
import { actionTypes, loadDataSuccess, loadDataError } from './actions'
|
|
|
|
|
|
|
|
es6promise.polyfill()
|
|
|
|
|
2018-08-20 06:31:24 +00:00
|
|
|
function * loadDataSaga () {
|
2018-02-24 23:17:04 +00:00
|
|
|
try {
|
|
|
|
const res = yield fetch('https://jsonplaceholder.typicode.com/users')
|
|
|
|
const data = yield res.json()
|
|
|
|
yield put(loadDataSuccess(data))
|
|
|
|
} catch (err) {
|
|
|
|
yield put(loadDataError(err))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default takeLatest(actionTypes.LOAD_DATA, loadDataSaga)
|