-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore.js
82 lines (68 loc) · 1.81 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { createStore, applyMiddleware } from "redux";
import { composeWithDevTools } from "redux-devtools-extension";
import thunkMiddleware from "redux-thunk";
const initialState = {
card: null,
account: null,
data: null,
checkin: null
};
export const actionTypes = {
RESET: "REST",
CARD: "CARD",
ACCOUNT: "ACCOUNT",
CHECKIN: "CHECKIN",
DATA: "DATA"
};
// REDUCERS
export const reducer = (state = initialState, action) => {
switch (action.type) {
case actionTypes.RESET:
return Object.assign({}, state, {
card: null,
account: null,
checkin: null
});
case actionTypes.CARD:
return Object.assign({}, state, {
card: action.card,
account: null,
checkin: null
});
case actionTypes.ACCOUNT:
return Object.assign({}, state, {
account: action.account,
checkin: null
});
case actionTypes.CHECKIN:
return Object.assign({}, state, {
checkin: action.checkin
});
case actionTypes.DATA:
return Object.assign({}, state, {
data: action.data
});
default:
return state;
}
};
// ACTIONS
export const reset = () => dispatch => {
return dispatch({ type: actionTypes.RESET });
};
export const setCard = card => dispatch => {
return dispatch({ type: actionTypes.CARD, card });
};
export const setAccount = account => dispatch => {
return dispatch({ type: actionTypes.ACCOUNT, account });
};
export const setCheckin = checkin => dispatch => {
return dispatch({ type: actionTypes.CHECKIN, checkin });
};
export const setData = data => dispatch => {
return dispatch({ type: actionTypes.DATA, data });
};
//
export function initializeStore(state = initialState) {
return createStore(reducer, state, composeWithDevTools(applyMiddleware(thunkMiddleware)));
}