Last active
April 17, 2019 14:45
-
-
Save styks1987/ced96ba63235442104860250b9b1a5f1 to your computer and use it in GitHub Desktop.
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
handleClick1 = async () => { | |
await this._commonStateUpdate({foo: {$set: 1}}); | |
// This function requires the new value of foo in the state | |
this.doSomethingElse(); | |
} | |
handleClick2 = async () => { | |
await this._commonStateUpdate({foo: {$set: 2}}); | |
// This function requires the new value of foo in the state | |
this.doSomethingElse(); | |
} | |
// Called by a lot of other functions | |
// May have some default state information | |
_commonStateUpdate = (updateTarget) => { | |
// ... Do things that are common across calling functions | |
const updateTargetDefault = {foo: 0, saving: false, loading: false}; | |
if(updateTarget){ | |
updateTarget = update(updateTargetDefault, updateTarget} | |
} | |
// IS THIS OK? | |
const completeCallback = async () => {}; | |
this.setState(updateTarget, completeCallback); | |
// Return a promise to listen for | |
return completeCallback; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment