panicbuyingReducer.js
3.38 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
import InitialState from './panicbuyingInitialState';
import Immutable, {Map} from 'immutable';
const {
SET_START_TIME,
QUERY_ACTIVITY_REQUEST,
QUERY_ACTIVITY_SUCCESS,
QUERY_ACTIVITY_FAILURE,
QUERY_PRODUCT_LIST_REQUEST,
QUERY_PRODUCT_LIST_SUCCESS,
QUERY_PRODUCT_LIST_FAILURE,
QUERY_PRODUCT_AND_REMIND_LIST_REQUEST,
QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS,
QUERY_PRODUCT_AND_REMIND_LIST_FAILURE,
SHOW_TIP_MESSAGE,
CLEAR_TIP_MESSAGE,
UPDATE_SECKILL_PRODUCT_VO_LIST,
UPDATE_SECKILL_PRODUCT_LIST,
} = require('../../constants/actionTypes').default;
const initialState = new InitialState;
export default function seckillReducer(state=initialState, action) {
switch(action.type) {
case SET_START_TIME: {
return state.set('startTime',action.payload)
}
case QUERY_ACTIVITY_REQUEST: {
return state.set('isFetching', true)
.set('ptr', true)
.set('error', null);
}
case QUERY_ACTIVITY_SUCCESS: {
let timeListInfo = action.payload.queryActivityInfo;
let focusActivity = action.payload.focusActivity;
let diff = Math.round((timeListInfo.currentTime - Date.now()) / 1000)
let newQueryActivity = state.queryActivityInfo.set('currentTime', timeListInfo.currentTime)
.set('secKillProductVoList', Immutable.fromJS(timeListInfo.secKillProductVoList));
return state.set('queryActivityInfo', newQueryActivity)
.set('localServerTimeDiff', diff)
.set('curActivity', Immutable.fromJS(focusActivity))
.set('error', null);
}
case QUERY_ACTIVITY_FAILURE: {
return state.set('isFetching', false)
.set('ptr', false)
.set('error', action.payload);
}
case QUERY_PRODUCT_LIST_REQUEST: {
return state.set('isFetching', true)
.set('ptr', true)
.set('curActivity', Immutable.fromJS(action.payload))
.set('error', null);
}
case QUERY_PRODUCT_LIST_SUCCESS: {
console.log(action.payload);
return state.set('isFetching', false)
.set('ptr', false)
.set('queryProductList', Immutable.fromJS(action.payload))
.set('error', null);
}
case QUERY_PRODUCT_LIST_FAILURE: {
return state.set('isFetching', false)
.set('ptr', false)
.set('error', action.payload);
}
case QUERY_PRODUCT_AND_REMIND_LIST_REQUEST: {
return state.set('isFetching', true)
.set('ptr', true)
.set('curActivity', Immutable.fromJS(action.payload))
.set('error', null);
}
case QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS: {
return state.set('isFetching', false)
.set('ptr', false)
.set('queryProductList', Immutable.fromJS(action.payload.queryProductList))
.set('queryRemindList', Immutable.fromJS(action.payload.remindList))
.set('error', null);
}
case QUERY_PRODUCT_AND_REMIND_LIST_FAILURE: {
return state.set('isFetching', false)
.set('ptr', false)
.set('error', action.payload);
}
case CLEAR_TIP_MESSAGE: {
return state.set('tipMessage', '');
}
case SHOW_TIP_MESSAGE: {
return state.set('tipMessage', Immutable.fromJS(action.payload));
}
case UPDATE_SECKILL_PRODUCT_VO_LIST: {
return state.setIn(['queryActivityInfo', 'secKillProductVoList'], Immutable.fromJS(action.payload.secKillProductVoList))
.set('ptr', true)
.set('isFetching', false)
.set('curActivity', Immutable.fromJS(action.payload.curActivity))
.set('error', null);
}
case UPDATE_SECKILL_PRODUCT_LIST: {
return state.set('queryProductList', Immutable.fromJS(action.payload))
.set('error', null);
}
}
return state;
}