-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
62 lines (56 loc) · 1.07 KB
/
store.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
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
import { createStore, combineReducers } from 'redux/src/index';
// TYPES
export const INCREMENT = 'INCREMENT';
export const DECREMENT = 'DECREMENT';
export const SEX = 'SEX';
// Action Creators
export function IncrementActionCreator() {
return {
type: INCREMENT,
};
}
export function DecrementActionCreator() {
return {
type: DECREMENT,
};
}
export function SexActionCreator(sex) {
return {
type: SEX,
payload: sex,
};
}
// reducer
export function numReducer(state = {}, action) {
switch (action.type) {
case 'INCREMENT':
return {
num: state.num + 1,
};
case 'DECREMENT':
return {
num: state.num - 1,
};
default:
return state;
}
}
export function sexReducer(state = {}, action) {
switch (action.type) {
case 'SEX':
return {
girlOrBoy: action.payload,
};
default:
return state;
}
}
const reducers = combineReducers({ numReducer, sexReducer });
export default createStore(reducers, {
numReducer: {
num: 0,
},
sexReducer: {
girlOrBoy: 0,
},
});