Skip to content

Instantly share code, notes, and snippets.

@malexsan1
Created April 30, 2017 06:36
Show Gist options
  • Save malexsan1/1a5443aad862fbc6624bad6ddad84625 to your computer and use it in GitHub Desktop.
Save malexsan1/1a5443aad862fbc6624bad6ddad84625 to your computer and use it in GitHub Desktop.
Create Redux store with Saga and Loggers
import logger from 'redux-logger'
import createSagaMiddleware from 'redux-saga'
import { autoRehydrate } from 'redux-persist'
import { createStore, applyMiddleware, compose } from 'redux'
import RehydrationServices from '../'
// creates the store
export default (rootReducer, rootSaga) => {
/* ------------- Redux Configuration ------------- */
const middleware = []
const enhancers = []
/* ------------- Saga Middleware ------------- */
const sagaMiddleware = createSagaMiddleware()
middleware.push(sagaMiddleware)
/* ------------- Logger Middleware ------------- */
middleware.push(logger)
}
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middleware))
/* ------------- AutoRehydrate Enhancer ------------- */
enhancers.push(autoRehydrate())
/* ------------- Create Store ------------- */
const store = createStore(rootReducer, compose(...enhancers))
/* ------------- Persistance cache busting ------------- */
// configure persistStore and check reducer version number
RehydrationServices.updateReducers(store)
// kick off root saga
sagaMiddleware.run(rootSaga)
return store
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment