Skip to content

Instantly share code, notes, and snippets.

@pokorson
Created December 29, 2017 09:53
Show Gist options
  • Save pokorson/d528860c95b7d48af348344906f056a4 to your computer and use it in GitHub Desktop.
Save pokorson/d528860c95b7d48af348344906f056a4 to your computer and use it in GitHub Desktop.
Apply namespace for selectors, for multiple levels of re-exporting selectors.
export default function applyScopeToSelectors(selectors, stateKey) {
return Object.keys(selectors).reduce((res, val) => {
if (typeof selectors[val] === 'object') {
return { ...res, [val]: applyScopeToSelectors(selectors[val], stateKey) };
}
return { ...res, [val]: state => selectors[val](state[stateKey]) };
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment