Skip to content

Instantly share code, notes, and snippets.

@pirey
Created July 22, 2017 08:11
Show Gist options
  • Save pirey/2e3df961d2e3b5e096a16a8b64894eb5 to your computer and use it in GitHub Desktop.
Save pirey/2e3df961d2e3b5e096a16a8b64894eb5 to your computer and use it in GitHub Desktop.
const filterWhitelist = ar => key => ar.includes(key)
const sliceState = (state, whitelist) => Object.keys(state)
.filter(filterWhitelist(whitelist))
.reduce((sliced, key) => ({ ...sliced, [key]: state[key] }), {})
// usage
const slicer = paths => state => {
const { ui, auth } = state
return {
ui,
auth: sliceState(auth, ['isLoggedIn', 'token'])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment