Last active
August 4, 2022 06:31
-
-
Save sethdavis512/2ee26a29108b2ff420542b43341b6a95 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const composePromise = (...fns) => initialValue => | |
fns.reduceRight((res, fn) => Promise.resolve(res).then(fn), initialValue); | |
// Individual Promises | |
const saveAppFee = () => saveFees(a, b, c); | |
const saveLnpFee = () => saveFees(x, y, z); | |
// Composed Promises | |
const saveAppAndLnp = composePromise(saveAppFee, saveLnpFee); | |
const saveApp = composePromise(saveAppFee); | |
const saveLnp = composePromise(saveLnpFee); | |
// Add logic to return proper set of promises. | |
const determineFeeCalls = (shouldCallA, shouldCallB) => { | |
if (shouldCallA && shouldCallB) { | |
return saveAppAndLnp; | |
} else if (shouldCallA) { | |
return saveApp; | |
} else if (shouldCallB) { | |
return saveLnp; | |
} | |
}; | |
// Your condition here... | |
const shouldCallAppFee = true; | |
const shouldCallLnPFee = false; | |
// Call using currying | |
determineFeeCalls(shouldCallAppFee, shouldCallLnPFee)() | |
.then(() => { | |
history.push(`${Constants.BASE_PATH}/payment/license-summary-preview`); | |
}) | |
.catch(err => { | |
hideSpinner(); | |
// error handling here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment