I'm trying to figure out how to best set up corout...
# coroutines
r
I'm trying to figure out how to best set up coroutines/flows to show updates to nested objects. Specifically, I need to display a
Group
object, which has some normal data to display (e.g.
id
), but also has a list of
User
objects (which each have their own data to display) I'd of course like my database to have group data separated from the
User
data, since `User`s can exist without a group, with multiple groups, etc. So, each group in the db will simply list the relevant
User
IDs; I call this a
ShallowGroup
I know how to get a flow to observe a single
User
, or how to get a flow to observe a single
ShallowGroup
but I can't figure out how to get from those a flow that produces full
Group
objects that reflect the changes to the inner
User
objects. My best understanding of how it would work: 1. Get a flow of
ShallowGroup
objects. 2. In a
map
call on that flow, use the user IDs in that
ShallowGroup
snapshot to get a flow for each
User
, and: 3. use
combine
on the previous list of flows of
Users
to get a flow which produces `List<User>`/`Group` 4. ?? somehow flatten the
Flow<Flow<Group>>
to just a
Flow<Group>
?? Note that the contents of each
ShallowGroup
object received determine which
User
objects need to be observed. Can someone point me to what the best way is to handle flows for nested objects like this?
l
flatMapLatest + distinctUntilChanged if needed.
🙌 1
☝️ 1
u
do a join inside at db level