Question about repository patterns and exposing a ...
# coroutines
j
Question about repository patterns and exposing a Flow that is triggered by a separate repository's Flow. I want to create a repository that exposes a Flow of data that is initialized automatically when a subscriber starts collecting the Flow. After that, I want a fetch to be triggered based on the emitted values from a different repository. I don't want to trigger a fetch, however, if there is a running fetch call already going or if the other repository's value doesn't pass certain criteria. I came up with the following which seems to work but I'm not clear on if using scope like this is a good idea or if there is a better approach to take. Any thoughts? Note that I wanted to write
_data.value !is Output.Loading
in the filter lambda but that is an error because
_data
is not initialized.
a
Look at, stateIn, combine and mapLatest operators( or anything with Latest sufix).
🤔 1
j
I took a look into them and tried to use AI to help me with things and this is what I've got. Is this what you had in mind? The problem with this one is that I believe the first
initialRefreshTrigger
event is discarded because its value is ignored in the filter.
a
Something like this
Might be also the event value
Initial event triger could also be an event type instead of unit, then you could do a merge instead of combine