-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateStore.js
47 lines (38 loc) · 1.31 KB
/
CreateStore.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
import { applyMiddleware, compose, createStore } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { persistReducer, persistStore } from 'redux-persist'
/**
* This import defaults to localStorage for web and AsyncStorage for react-native.
*
* Keep in mind this storage *is not secure*. Do not use it to store sensitive information
* (like API tokens, private and sensitive data, etc.).
*
* If you need to store sensitive information, use redux-persist-sensitive-storage.
* @see https://github.com/CodingZeal/redux-persist-sensitive-storage
*/
import storage from 'redux-persist/lib/storage'
const persistConfig = {
key: 'root',
storage: storage,
/**
* Blacklist state that we do not need/want to persist
*/
blacklist: [
// 'auth',
],
}
export default (rootReducer, rootSaga) => {
const middleware = []
const enhancers = []
// Connect the sagas to the redux store
const sagaMiddleware = createSagaMiddleware()
middleware.push(sagaMiddleware)
enhancers.push(applyMiddleware(...middleware))
// Redux persist
const persistedReducer = persistReducer(persistConfig, rootReducer)
const store = createStore(persistedReducer, compose(...enhancers))
const persistor = persistStore(store)
// Kick off the root saga
sagaMiddleware.run(rootSaga)
return { store, persistor }
}