This repository has been archived by the owner on Feb 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
executable file
·82 lines (76 loc) · 2.26 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, combineReducers } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import thunkMiddleware from 'redux-thunk'
/*
|--------------------------------------------------------------------------
| WP CONFIG REDUCER
|--------------------------------------------------------------------------
|
*/
const wpReducer = (state = null, action) => {
switch(action.type) {
case 'SET_WP' :
return action.payload
default :
return state
}
}
export const setWp = wp => dispatch => {
return dispatch({ type: 'SET_WP', payload: wp })
}
/*
|--------------------------------------------------------------------------
| LANGUAGE REDUCER
|--------------------------------------------------------------------------
|
*/
const langReducer = (state = '', action) => {
switch(action.type) {
case 'SET_LANG' :
return action.payload
default :
return state
}
}
export const setLang = lang => dispatch => {
return dispatch({ type: 'SET_LANG', payload: lang })
}
/*
|--------------------------------------------------------------------------
| MENUS REDUCER
|--------------------------------------------------------------------------
|
*/
const menusReducer = (state = {}, action) => {
switch(action.type) {
case 'SET_MENU' :
const { lang, location, menu } = action.payload
if(lang) {
return {...state, [lang]: {...state[lang], [location]: menu }}
} else {
return {...state, [location]: menu}
}
default :
return state
}
}
export const setMenu = ({ menu, location, lang }) => dispatch => {
return dispatch({ type: 'SET_MENU', payload: { menu, location, lang } })
}
/*
|--------------------------------------------------------------------------
| COMBINED REDUCERS
|--------------------------------------------------------------------------
*/
const reducers = combineReducers({
wp: wpReducer,
lang: langReducer,
menus: menusReducer,
})
export const initializeStore = (initialState = {}) => {
return createStore(
reducers,
initialState,
composeWithDevTools(applyMiddleware(thunkMiddleware))
)
}