Skip to content

Instantly share code, notes, and snippets.

@smashercosmo
Created May 10, 2016 19:53
Show Gist options
  • Save smashercosmo/b6b9a53d7b70a2b7aa63f447a1f9d34f to your computer and use it in GitHub Desktop.
Save smashercosmo/b6b9a53d7b70a2b7aa63f447a1f9d34f to your computer and use it in GitHub Desktop.
const injectMiddleware = (staticDeps, dynamicDeps) => ({ dispatch, getState }) => next => action => {
const deps = {...staticDeps};
Object.keys(dynamicDeps).forEach(key => {
deps[key] = dynamicDeps[key]();
});
return next(typeof action === 'function'
? action({ ...deps, dispatch, getState })
: action
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment