Skip to content

Instantly share code, notes, and snippets.

@rafael-metractive
Created February 19, 2019 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafael-metractive/b73a23e6743843cd980cc5a3082ea5b1 to your computer and use it in GitHub Desktop.
Save rafael-metractive/b73a23e6743843cd980cc5a3082ea5b1 to your computer and use it in GitHub Desktop.
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