Passed
Push — master ( 9a73f0...7331d4 )
by Huu-Phat
01:50 queued 11s
created

cms/src/posts/state/sagas.js   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 19
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
mnd 1
bc 1
fnc 2
dl 0
loc 19
rs 10
bpm 0.5
cpm 1.5
noi 0
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A sagas.js ➔ fetchPosts 0 8 2
A sagas.js ➔ postsSaga 0 3 1
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