Created
February 19, 2019 01:11
-
-
Save rafael-metractive/b73a23e6743843cd980cc5a3082ea5b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'; | |
import { createReactNavigationReduxMiddleware, createNavigationReducer, reduxifyNavigator } from 'react-navigation-redux-helpers'; | |
import { connect } from 'react-redux'; | |
// Middlewares | |
import createSagaMiddleware from 'redux-saga'; | |
// Saga's | |
import user from './reducers/sagas/user' | |
import schedule from './reducers/sagas/schedule' | |
import evaluations from './reducers/sagas/evaluations' | |
import * as reducers from './reducers'; | |
export default navigator => { | |
const navReducer = createNavigationReducer(navigator) | |
const reducer = combineReducers({ | |
nav: navReducer, | |
...reducers | |
}) | |
const sagaMiddleware = createSagaMiddleware() | |
const navMiddleware = createReactNavigationReduxMiddleware( | |
"root", | |
state => state.nav | |
); | |
const store = createStore( | |
reducer, | |
compose( | |
applyMiddleware(navMiddleware), | |
applyMiddleware(sagaMiddleware) | |
) | |
) | |
const App = reduxifyNavigator(navigator, "root") | |
const mapStateToProps = state => ({ state: state.nav }) | |
const AppWithNavigationState = connect(mapStateToProps)(App) | |
// Run Saga's | |
sagaMiddleware.run(user) | |
sagaMiddleware.run(schedule) | |
sagaMiddleware.run(evaluations) | |
return { store, AppWithNavigationState } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment