Created
April 18, 2020 10:44
-
-
Save Haosvit/085e0b69e6115a50a69dca229f2f28dc to your computer and use it in GitHub Desktop.
Redux devTools extension compose with options
This file contains hidden or 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 { applyMiddleware, compose, createStore } from 'redux'; | |
import createSagaMiddleware from 'redux-saga'; | |
import rootReducer from './rootReducer'; | |
import rootSaga from './rootSaga'; | |
declare global { | |
interface Window { | |
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: any; | |
} | |
} | |
const initialiseSagaMiddleware = createSagaMiddleware(); | |
const composeEnhancers = | |
process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ | |
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ | |
actionSanitizer: (action) => { | |
const message = action.payload && action.payload.message; | |
return (action.type as string).endsWith('FAILURE') | |
? { | |
...action, | |
payload: !!message ? `(DEV) Error message: ${message}` : undefined, | |
} | |
: action; | |
}, | |
}) | |
: compose; | |
const enhancer = composeEnhancers(applyMiddleware(initialiseSagaMiddleware)); | |
const store = createStore(rootReducer, enhancer); | |
initialiseSagaMiddleware.run(rootSaga); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment