Last active
April 24, 2020 20:12
-
-
Save rosschapman/90d9f13d5761fe411c3357246973d1e5 to your computer and use it in GitHub Desktop.
Separate action dispatch and process
This file contains 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
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