Skip to content

Instantly share code, notes, and snippets.

@rosschapman
Last active April 24, 2020 20:12
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/90d9f13d5761fe411c3357246973d1e5 to your computer and use it in GitHub Desktop.
Save rosschapman/90d9f13d5761fe411c3357246973d1e5 to your computer and use it in GitHub Desktop.
Separate action dispatch and process
private processEntityCreate = async (payload: any) => {
// Update component status (sync)
this.statusMachine(this.statuses.waiting);
// Post request (async)
await this.apiAdapater.MY_ENTITY.post(action.payload);
// Update component status (sync)
this.statusMachine(this.statuses.success);
};
private actionDispatch = async (action: Action) => {
switch (action.type) {
case "SUBMIT_FORM":
console.time("actionManager:SUBMIT_FORM");
await this.processEntityCreate(action.payload);
console.timeEnd("actionManager:SUBMIT_FORM");
console.timeLog("actionManager:SUBMIT_FORM");
break;
default:
throw Error("It should be impossible to get here");
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment