felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.79k stars 3.39k forks source link

question: how to design the bloc layer so that the app can make multiple/parallel requests from the data layer? #3373

Closed FisherWL closed 2 years ago

FisherWL commented 2 years ago

Question

in a stock app, on the watchlist page, there's a vertical list of users' favorite stocks, user could add/remove stock(s) into/from the list, each item is showing the historic trends of the stock, as the screenshot below:

IMG_5C5551DAAEF9-1

the app's data layer is architectured as: stock trends data provider -> stock trends repository

how to design the bloc layer so that the app can make multiple/parallel requests from the data layer?

Desired Solution

parallel requests with bloc pattern

Alternatives Considered

I'm currently using FutureBuilder insider StatefulWidget to make the calls.

felangel commented 2 years ago

Hi @FisherWL 👋 Thanks for opening an issue!

I recommend going for a reactive repository approach in which you expose streams of data from the repository and you can manage multiple subscriptions in the bloc for each stock. This way stock updates can occur independently and in real-time and the bloc will handle updating the corresponding state property when a specific stock subscription emits new data.

Closing for now but if you still have questions the bloc discord is a great place to have these types of discussions with the community 👍