-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateStore.ts
36 lines (27 loc) · 1003 Bytes
/
CreateStore.ts
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
import { applyMiddleware, compose, createStore } from 'redux'
import createSagaMiddleware from 'redux-saga'
import { persistReducer, persistStore, createMigrate } from 'redux-persist'
import logger from 'redux-logger'
import AsyncStorage from '@react-native-async-storage/async-storage'
const rootPersistConfig = {
key: 'root',
storage: AsyncStorage,
blacklist: ['settings'],
whitelist: [],
version: 0,
}
export default (rootReducer: any, rootSaga: any) => {
const middleware = []
const enhancers = []
// Connect the sagas to the redux store
const sagaMiddleware = createSagaMiddleware()
middleware.push(sagaMiddleware)
enhancers.push(applyMiddleware(...middleware/*, logger*/))
// Redux persist
const persistedReducer = persistReducer(rootPersistConfig, rootReducer)
const store = createStore(persistedReducer, compose(...enhancers))
const persistor = persistStore(store)
// Kick off the root saga
sagaMiddleware.run(rootSaga)
return { store, persistor }
}