I am trying to figure out what the best practice is for structuring Promise logic with both modals and http requests. Say I have a situation like this:
// normal logic flowing to here
// ...
// encounter special case
if (needToDoSomeGuidedPreprocessing) {
doSomeAsyncHttpCall
.then(doSomeStuff);
.then(sendUpSomeDialogThatNeedsToConfirmToProceed)
}
// ...
// if dont need guided preprocessing, continue to normal operations
// (includes more dialogs). Also, if guided preprocessing worked, make sure
// code down here doesn't fire until pre-processing is done (i.e. all these
// operations need to be done sequentially, so .all( ) wont work
How can I accomodate my code to be readable here?
I thought of this but thought maybe there is some better way? The problem is that I have yet more async methods/dialogs after this, and would prefer to keep in a singular method rather than jumping out to an entirely new method.:
// ...
// encounter special case
if (needToDoSomeGuidedPreprocessing) {
doSomeAsyncHttpCall
.then(doSomeStuff);
.then(sendUpSomeDialogThatNeedsToConfirmToProceed)
.then(callSomeCommonMethod)
}
else{
callSomeCommonMethod()
}
// ...
Is this just the nature of dialogs/async operations or am I doing something wrong?