rcdilorenzo / news

6 stars 4 forks source link

Multiple data requests #18

Open Sylvenas opened 3 years ago

Sylvenas commented 3 years ago

Sorry to interrupt, I found this project from your speech video on YouTube. I have a doubt about multiple HTTP data requests.

How can I solve it more gracefully with functional style.

any ideas or examples codes, Thank you so much.

rcdilorenzo commented 3 years ago

@Sylvenas I'm not sure I understand what you're asking. Are you trying to do something different from the example or understand how that example works?

Sylvenas commented 3 years ago

Sorry I didn't describe my problem clearly, I understand the problem solved in this project.

The problem I failed to understand is, suppose I have a page where I need to query data from multiple server-side APIs, for example, on a song details page, I need to call

We know that using Promise.all to query multiple data at once will lead to large and coupled code.

But is there a better solution than using Promise.all to query data concurrently? How should I write this code using the functional programming style?

Thanks.

rcdilorenzo commented 3 years ago

I'm on mobile right now but you can just use chaining .then promise calls that call the next API request and pass along the previous result with its own response.

Then, these could be combined into a helper if the pattern is common enough.

I'll try to respond on desktop more clearly with a code example but maybe this is helpful in the meantime.

Sylvenas commented 3 years ago

Thank you for your help, I generally understand the ideas you introduced, if you have time, more look forward to your code on the solution, thanks again.