Bloc: [question] keeping state in state or in bloc ?

Created on 16 Jun 2019  路  2Comments  路  Source: felangel/bloc

The bloc is in charge of managing an objects list state

Object:

  • name
  • status (connected / disconnected)

This bloc is linked to a stream to get an update of each object info (connected/disconnected)

On the Page side, I need to display the list objects with the different status
This page is updated when ObjectsSuccess is fired

How to maintain the status of all the objects ?
I need to return all the objects in the ObjectsSuccessState so I need to keep this list

in the state ? so I need to get previous state to know other objects states
in the bloc itself (and the list of all objects states) ?

Any advice ?

question

Most helpful comment

Good question! Ultimately, there should be lower level repository classes that actually house _all_ the data for your running application, which your blocs can then access and combine/massage as needed for a specific page. Consider this set of layers:

UI/pages
   |
 (renders via)
   |
   v
State object
   |
 (produced by)
   |
   v
Blocs
   |
 (get data from)
   |
   v
Low level repositories
   |
 (make network requests to)
   |
   v
Your servers

Hope that helps!

All 2 comments

Good question! Ultimately, there should be lower level repository classes that actually house _all_ the data for your running application, which your blocs can then access and combine/massage as needed for a specific page. Consider this set of layers:

UI/pages
   |
 (renders via)
   |
   v
State object
   |
 (produced by)
   |
   v
Blocs
   |
 (get data from)
   |
   v
Low level repositories
   |
 (make network requests to)
   |
   v
Your servers

Hope that helps!

Hey @fvisticot 馃憢
Thanks for opening an issue!

As @craiglabenz mentioned, the bloc should rely on the repository layer to retrieve the Stream of information. If you are still unsure of how to proceed in this particular case, please share a link to a sample application with your current approach and I would be happy to take a look and give suggestions 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

krusek picture krusek  路  3Comments

rsnider19 picture rsnider19  路  3Comments

hivesey picture hivesey  路  3Comments

komapeb picture komapeb  路  3Comments

wheel1992 picture wheel1992  路  3Comments