Created
July 16, 2016 20:36
-
-
Save jacobp100/8e5b8d3b66f1147146d49966c7e1e5de to your computer and use it in GitHub Desktop.
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
import serialize from 'form-serialize'; | |
import actionCreators from './actionCreators'; | |
export const formDispatcher = dispatch => event => { | |
event.preventDefault(); | |
const { currentTarget } = event; | |
const isChild = 'form' in currentTarget; | |
const form = isChild ? currentTarget.form : currentTarget; | |
const actionParams = serialize(form, { hash: true, empty: true }); | |
if (isChild && currentTarget.tagName === 'BUTTON' && currentTarget.name) { | |
actionParams[currentTarget.name] = currentTarget.value; | |
} | |
const actionCreator = actionCreators[actionParams['action-creator']]; | |
const action = actionCreator(actionParams); | |
dispatch(action); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment