Skip to content

Instantly share code, notes, and snippets.

@aaronjensen
Created August 7, 2015 16:22
Show Gist options
  • Save aaronjensen/d31b3a4a9eaea505507d to your computer and use it in GitHub Desktop.
Save aaronjensen/d31b3a4a9eaea505507d to your computer and use it in GitHub Desktop.
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);
};
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