Last active
July 19, 2016 14:47
-
-
Save possibilities/5b5e9e028df89c6a9ec6 to your computer and use it in GitHub Desktop.
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 { createStore, applyMiddleware, compose } from 'redux' | |
import thunk from 'redux-thunk' | |
import reducer from '../reducers' | |
const helloWorldEnhancer = () => { | |
return nextCreateStore => (reducer, initialState) => { | |
const store = nextCreateStore(reducer, initialState) | |
const originalDispatch = store.dispatch | |
const dispatch = (...args) => { | |
console.info('dispatch: start', ...args) | |
const result = originalDispatch(...args) | |
console.info('dispatch: end', ...args) | |
return result | |
} | |
return { | |
...store, | |
dispatch | |
} | |
} | |
} | |
const finalCreateStore = compose( | |
applyMiddleware(thunk), | |
helloWorldEnhancer() | |
)(createStore) | |
export default function configureStore(initialState) { | |
const store = finalCreateStore(reducer, initialState) | |
if (module.hot) { | |
// Enable Webpack hot module replacement for reducers | |
module.hot.accept('../reducers', () => { | |
const nextReducer = require('../reducers') | |
store.replaceReducer(nextReducer) | |
}) | |
} | |
return store | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tentatively disagree with myself that this is a hello world because I'm not sure customizing
dispatch
is the most obvious case for an enhancer.