-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStore.js
More file actions
58 lines (49 loc) · 1.42 KB
/
Store.js
File metadata and controls
58 lines (49 loc) · 1.42 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
import { connect } from 'react-redux'
import {
reduxifyNavigator,
createReactNavigationReduxMiddleware,
createNavigationReducer,
} from 'react-navigation-redux-helpers'
import {
combineReducers, createStore, applyMiddleware, compose,
} from 'redux'
import { AsyncStorage } from 'react-native'
import { persistReducer, persistStore } from 'redux-persist'
import autoMergeLevel2 from 'redux-persist/lib/stateReconciler/autoMergeLevel2'
import { createLogger } from 'redux-logger'
import thunkMiddleware from 'redux-thunk'
import AppContainer from './src/Navigator'
import myReducer from './src/my/reducer'
const navReducer = createNavigationReducer(AppContainer)
const appReducer = combineReducers({
nav: navReducer,
my: myReducer,
})
const middleware = createReactNavigationReduxMiddleware(
'root',
state => state.nav,
)
const persistConfig = {
key: 'root',
storage: AsyncStorage,
blacklist: [],
version: 1,
stateReconciler: autoMergeLevel2,
}
const persistedReducer = persistReducer(persistConfig, appReducer)
const logger = createLogger({})
const enhancer = compose(applyMiddleware(
logger,
thunkMiddleware,
middleware,
))
const App = reduxifyNavigator(AppContainer, 'root')
const mapStateToProps = state => ({
state: state.nav,
})
export const AppWithNavigationState = connect(mapStateToProps)(App)
export const store = createStore(
persistedReducer,
enhancer,
)
export const persistor = persistStore(store)