valoraciones.js
935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { merge } from 'ramda'
import {
VALORACION_REQUESTED,
VALORACION_RECEIVED,
VALORACION_FAILED,
VALORACION_POSTED,
VALORACION_POST_SUCCESS
} from '../actions/valoraciones'
const valoracion = {
data: null,
loading: true,
error: null
}
const toggle = (state, val) => {
if (state.valoracion === val) {
return null
}
return val
}
export default (state, action) => {
switch (action.type) {
case VALORACION_REQUESTED:
return merge(state, valoracion)
case VALORACION_POSTED:
return merge(state, { data: toggle(state, action.valoracion) })
case VALORACION_POST_SUCCESS:
return merge(state, { data: action.result.valoracion })
case VALORACION_RECEIVED:
return merge(state, { loading: false, error: null, data: action.valoracion })
case VALORACION_FAILED:
return merge(state, { loading: false, data: null, error: action.error })
default:
return state || valoracion
}
}