Created
April 30, 2017 06:36
-
-
Save malexsan1/1a5443aad862fbc6624bad6ddad84625 to your computer and use it in GitHub Desktop.
Create Redux store with Saga and Loggers
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 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