Skip to content

Instantly share code, notes, and snippets.

@grabbou
Last active September 15, 2015 22:49
Show Gist options
  • Save grabbou/bb84a5436d27bde8253d to your computer and use it in GitHub Desktop.
Save grabbou/bb84a5436d27bde8253d to your computer and use it in GitHub Desktop.
export default function injectDependencies({dependencies}) {
return({dispatch, getState}) => next => action =>
typeof action === 'function' ?
action({...dependencies, getState}) :
next(action);
}
// action
export function fetchOrders(orderId) {
return ({fetch}) => ({
types: [
FETCH_ORDERS,
FETCH_ORDERS_SUCCESS,
FETCH_ODERS_ERROR
],
payload: {
promise: fetch('/orders'),
orderId
}
})
};
// declaration
const middleware = injectDependencies({fetch: window.fetch});
const finalCreateStore = compose(
applyMiddlewares(middleware)
)(createStore);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment