Created
July 22, 2017 08:11
-
-
Save pirey/2e3df961d2e3b5e096a16a8b64894eb5 to your computer and use it in GitHub Desktop.
state slicer for https://github.com/elgerlambert/redux-localstorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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