Repository navigation
Expand file tree
/
Copy pathstore.js
More file actions
68 lines (60 loc) · 1.5 KB
/
Copy pathstore.js
File metadata and controls
68 lines (60 loc) · 1.5 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
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
const InitialState = {
user: null,
records: {
prevMonthRecord: [],
lastMonthRecord: [],
currMonthRecord: [],
},
problems: [],
}
export const actionTypes = {
GETRECORDS: 'GETRECORDS',
GETPROBLEMS: 'GETPROBLEMS',
LOGIN: 'LOGIN',
LOGOUT: 'LOGOUT',
}
// REDUCERS
export const reducer = (state = InitialState, action) => {
switch (action.type) {
case actionTypes.GETRECORDS:
return Object.assign({}, state, {
records: action.payload
})
case actionTypes.GETPROBLEMS:
return Object.assign({}, state, {
problems: action.payload
})
case actionTypes.LOGIN:
return Object.assign({}, state, {
user: action.payload
})
case actionTypes.LOGOUT:
return Object.assign({}, state, {
user: null
})
default:
return state
}
}
// ACTIONS
export const getRecords = (data) => {
return { type: actionTypes.GETRECORDS, payload: data }
}
export const getProblems = (data) => {
return { type: actionTypes.GETPROBLEMS, payload: data }
}
export const login = (data) => {
return { type: actionTypes.LOGIN, payload: data }
}
export const logout = (data) => {
return { type: actionTypes.LOGOUT }
}
export function initializeStore (initialState = InitialState) {
return createStore(
reducer,
initialState,
composeWithDevTools(applyMiddleware())
)
}