Created
August 7, 2015 16:22
-
-
Save aaronjensen/d31b3a4a9eaea505507d to your computer and use it in GitHub Desktop.
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
const { createStore, combineReducers, applyMiddleware, compose } = require('redux'); | |
const reducers = require('app/reducers'); | |
const thunkMiddleware = require('redux-thunk'); | |
const simpleDispatchThunkMiddleware = require('app/redux/simple_dispatch_thunk_middleware'); | |
const { batchedUpdates } = require('redux-batched-updates'); | |
const simpleDispatch = require('app/redux/simple_dispatch'); | |
const finalCreateStore = compose( | |
applyMiddleware(thunkMiddleware), | |
simpleDispatch, | |
batchedUpdates, | |
createStore | |
); | |
module.exports = function createAppStore(initialState = {}) { | |
return finalCreateStore(combineReducers(reducers), initialState); | |
}; |
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
module.exports = function simpleDispatch(next) { | |
return (...args) => { | |
const store = next(...args); | |
console.log('applying simpledispatch'); | |
function simpleDispatch(type, payload) { | |
console.log('simpleDispatch', type, payload); | |
if (typeof type === 'string') { | |
console.log('creating action'); | |
store.dispatch({ type, payload }); | |
} else { | |
console.log('dispatching as is'); | |
store.dispatch(type); | |
} | |
} | |
return { ...store, dispatch: simpleDispatch }; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment