Last active
April 26, 2020 23:27
-
-
Save rosschapman/cc75f7d46f25d381a8b76872a9adb89b to your computer and use it in GitHub Desktop.
AppConductor with basic action manager
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
class AppConductor extends React.Component { | |
userActions = { | |
submitForm: "SUBMIT_FORM" | |
}; | |
actionRouter = async (action) => { | |
switch (action.type) { | |
case "SUBMIT_FORM": | |
// wondering where all those calls are gonna go?? 😎 | |
default: | |
throw Error("It should be impossible to get here"); | |
} | |
}; | |
dispatch = (actionType) => (data) => { | |
let action = { | |
type: actionType, | |
payload: data | |
}; | |
return this.actionManager(action); | |
}; | |
render() { | |
let childProps = { | |
submitForm: this.actionDispatch(this.userActions.submitForm), | |
}; | |
return this.props.children(childProps); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment