Skip to content

Instantly share code, notes, and snippets.

@rosschapman
Last active April 26, 2020 23:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosschapman/cc75f7d46f25d381a8b76872a9adb89b to your computer and use it in GitHub Desktop.
Save rosschapman/cc75f7d46f25d381a8b76872a9adb89b to your computer and use it in GitHub Desktop.
AppConductor with basic action manager
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