-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcalculatorReducer.js
37 lines (34 loc) · 982 Bytes
/
calculatorReducer.js
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
import types from '../actions/types';
const defaultState = {
result : 0,
sumInfo: {
frist : 0,
second : 0,
},
}
export default calculator = (state = defaultState, action) => {
// For Debugger
// console.log('payload:' + action.payload);
switch (action.type) {
case types.CALCULATOR_UPDATE_SUM_FIRST:
return {
// ...state,
result : action.payload + state.sumInfo.second,
sumInfo: {
frist:action.payload,
second:state.sumInfo.second
}
};
case types.CALCULATOR_UPDATE_SUM_SECOND:
return {
// ...state,
result : action.payload + state.sumInfo.frist,
sumInfo: {
frist:state.sumInfo.frist,
second:action.payload
}
};
default:
return state;
}
};