Created
June 30, 2019 15:21
-
-
Save mattlockyer/872c4730d27d0e8fd7cdee589d36716d to your computer and use it in GitHub Desktop.
Generate functions that are based on a similar structure by name - e.g. set redux state of UI components
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
//example functions to set redux state of UI components | |
const {setDrawerState, setDialogState, setPopoverState} = ['Drawer', 'Dialog', 'Popover'].map((name) => ({ | |
['set' + name + 'State']: (state) => async (dispatch, getState) => { | |
const stateName = name.toLowerCase() + 'State' | |
const currentState = getState().appReducer[stateName] | |
dispatch({ type: 'UPDATE_UI_STATE', [stateName]: { ...currentState, ...state } }) | |
} | |
})).reduce((a, c) => ({...a, ...c})) | |
export { setDrawerState, setDialogState, setPopoverState } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment