Created
December 4, 2020 21:19
-
-
Save icorbrey/dfbfc2b992f5813d3b67cef2a1fbd459 to your computer and use it in GitHub Desktop.
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
export const getDispatchableActions = (dispatch, actions) => | |
getPropertyPairs(actions) | |
.map(toDispatchableActionPair(dispatch)) | |
.map(toPropertyObject) | |
.reduce(toSingleObject, {}) | |
const getPropertyPairs = object => Object | |
.keys(object) | |
.map(key => [key, object[key]]) | |
const toDispatchableActionPair = dispatch => ([name, action]) => [ | |
name, | |
(...params) => dispatch(action(...params)) | |
] | |
const toPropertyObject = ([key, property]) => ({ | |
[key]: property, | |
}) | |
const toSingleObject = (x, y) => ({ | |
...x, | |
...y, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment