doSomething().then(data => { doStuff(data).then(result => { doOtherStuff(data, result).then(outcome => { showOutcome(outcome, result, data); }); }); });
Instead of this you can do something like the following:
const concat = _.curry(_.concat, 2) doSomething() .then(data => doStuff(data).then(concat(data)) .then([data, result] => doOtherStuff(data, result).then(concat([data, result])) ) .then([data, result, outcome] => showOutcome(data, result, outcome) )
Or like this:
doSomething() .then(data => Promise.all([data, doStuff(data)])) .then(([data, result]) => Promise.all([data, result, doOtherStuff(data, result)])) .then(([data, result, outcome]) => showOutcome(data, result, outcome));
Clean and simple approach, but passing around of all the values is quite cumbersome.
My main point was that you can still get a "flat" result when you have interdependent calls.
You can also pull this off with callbacks.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Instead of this you can do something like the following:
Or like this:
Clean and simple approach, but passing around of all the values is quite cumbersome.
My main point was that you can still get a "flat" result when you have interdependent calls.
You can also pull this off with callbacks.