Skip to content

Instantly share code, notes, and snippets.

@styks1987
Last active April 17, 2019 14:45
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 styks1987/ced96ba63235442104860250b9b1a5f1 to your computer and use it in GitHub Desktop.
Save styks1987/ced96ba63235442104860250b9b1a5f1 to your computer and use it in GitHub Desktop.
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