Created
August 20, 2019 06:19
-
-
Save chadedrupt/6b55cb096ae882ae00fe7a51405dd8bb to your computer and use it in GitHub Desktop.
mapSelector for reselect
This file contains 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
import { createSelector, Selector } from 'reselect' | |
import { isNil } from 'lodash' | |
export default function mapSelector<S, A, B>( | |
selector: Selector<S, A>, | |
mapping: (a: NonNullable<A>) => B | |
) { | |
return createSelector( | |
selector, | |
value => { | |
if (isNil(value)) return | |
return mapping(value as NonNullable<A>) | |
} | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This:
can become this: