birthReducer.js
1.09 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
'use strict';
import InitialState from './birthInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_TYPE,
SET_SIMILAR_PRODUCT_INDEX,
GET_BIRTH_PRODUCT_REQUEST,
GET_BIRTH_PRODUCT_SUCCESS,
GET_BIRTH_PRODUCT_FAILURE,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function birthReducer(state=initialState, action) {
switch(action.type) {
case SET_SIMILAR_PRODUCT_INDEX: {
return state.set('similarIndex', action.payload.rowID);
}
case GET_BIRTH_PRODUCT_REQUEST: {
return state.set('isFetching', true);
}
case GET_BIRTH_PRODUCT_SUCCESS:{
let json = action.payload;
return state.set('isFetching', false)
.set('list', Immutable.fromJS(json.list))
.set('currentPage', json.currentPage)
.set('pageCount', json.pageCount)
.set('total', json.total)
.set('endReached', json.endReached);
}
case GET_BIRTH_PRODUCT_FAILURE: {
return state.set('isFetching', false);
}
}
return state;
}