| Total Complexity | 3 |
| Complexity/F | 1.5 |
| Lines of Code | 19 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { call, put, takeLatest } from 'redux-saga/effects' |
||
| 2 | import { fetchPostSummary } from 'posts/api/fetch' |
||
| 3 | import { FETCH_POSTS } from 'core/state/actionType' |
||
| 4 | import { toSuccess, toError, toRequest } from 'core/state/utils' |
||
| 5 | |||
| 6 | function* fetchPosts() { |
||
| 7 | try { |
||
| 8 | const posts = yield call(fetchPostSummary) |
||
| 9 | yield put({ type: toSuccess(FETCH_POSTS), payload: posts }) |
||
| 10 | } catch (e) { |
||
| 11 | yield put({ type: toError(FETCH_POSTS), message: e.message }) |
||
| 12 | } |
||
| 13 | } |
||
| 14 | |||
| 15 | function* postsSaga() { |
||
| 16 | yield takeLatest(toRequest(FETCH_POSTS), fetchPosts) |
||
| 17 | } |
||
| 18 | |||
| 19 | export default postsSaga |
||
| 20 |