shareDetailReducer.js
1.56 KB
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
41
42
43
44
45
46
47
48
'use strict';
import InitialState from './shareDetailInitialState';
import Immutable, {List} from "immutable";
const {
SHARE_DETAIL_REQUEST,
SHARE_DETAIL_SUCCESS,
SHARE_DETAIL_FAILURE,
ADD_FAVORITE_REQUEST,
ADD_FAVORITE_SUCCESS,
ADD_FAVORITE_FAILURE,
FAVORITE_INFO_REQUEST,
FAVORITE_INFO_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function appReducer(state = initialState, action) {
if (!(state instanceof InitialState)) return initialState.merge(state);
switch (action.type) {
case SHARE_DETAIL_REQUEST:
return state.set('isFetching', true);
case SHARE_DETAIL_SUCCESS:
return state.set('isFetching', false)
.set('productInfo', Immutable.fromJS(action.payload));
case SHARE_DETAIL_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_REQUEST:
return state.set('isFetching', true);
case ADD_FAVORITE_SUCCESS:
return state.set('isFetching', false)
.set('isCollect', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
case ADD_FAVORITE_FAILURE:
return state.set('isFetching', false)
.set('error', action.payload);
}
return state;
}