-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
81 lines (76 loc) · 1.73 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
import { createStore, applyMiddleware } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import { persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'
// INITIAL STATE
const initialState = {
database: {
string: '',
redis: '',
user: '',
host: '',
db: '',
password: '',
},
twitterUsername: '',
twitterClient: {
consumerKey: '',
consumerSecret: '',
accessToken: '',
accessTokenSecret: '',
},
querySettings: {
limit: 100,
offset: 0,
cursor: -1,
}
}
// ACTION TYPES
export const actionTypes = {
SET_DATABASE: 'SET_DATABASE',
SET_USERNAME: 'SET_TWITTER_USERNAME',
SET_TWITTER_CLIENT: 'SET_TWITTER_CLIENT',
SET_QUERY_SETTINGS: 'SET_QUERY_SETTINGS',
}
// REDUCERS
const reducer = (state = initialState, action) => {
switch (action.type) {
case 'SET_DATABASE':
return {
...state,
database: action.database
}
case 'SET_TWITTER_CLIENT':
return {
...state,
twitterClient: action.twitterClient // initialState.twitterClient
}
case 'SET_TWITTER_USERNAME':
return {
...state,
twitterUsername: action.twitterUsername
}
case 'SET_QUERY_SETTINGS':
return {
...state,
querySettings: action.querySettings
}
default:
return state
}
}
// INITIALIZE STORE
const persistedReducer = persistReducer({
key: 'primary',
storage,
whitelist: ['database', 'twitterUsername', 'twitterClient', 'querySettings']
}, reducer)
export const initializeStore = (preloadedState = initialState) => {
return createStore(
persistedReducer,
preloadedState,
composeWithDevTools(
applyMiddleware()
)
)
}