Skip to content

Instantly share code, notes, and snippets.

@boostup
Created July 31, 2020 15:29
Show Gist options
  • Save boostup/60bed5c9abf03d187c51faa1a64ddec7 to your computer and use it in GitHub Desktop.
Save boostup/60bed5c9abf03d187c51faa1a64ddec7 to your computer and use it in GitHub Desktop.
const responseGoogleStatus = (responseType) => {
return (response) => {
console.log(responseType, response);
if (responseType == "Success") {
loggedIn = true;
token = response.accessToken;
}
if (responseType == "Failed") {
throw new Exception("Some error from Google API response", response);
}
};
};
//Then call the currying function to get a function back with 'responsType' (in this case) already 'filled in'
const successFn = responseGoogleStatus("Success")
const failureFn = responseGoogleStatus("Failed")
//Finally use successFn and failureFn as a callbacks for an API Promise for example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment