Hey everyone, I have a question regarding Flow.
I have an architecture that looks something like this: UI + ViewModel <- Service <- Repository
In this pipeline, Service is maping data from the repository for something that can be consumed by the ViewModel using the map {} operator.
Now comes my question:
Is it a good idea to put code that changes the system state inside this map or is this a bad idea and I should only map data from one type to another inside the flow ?
So basically I would like to schedule/unschedule some alarms as data is registered/unregistered in the repository, but I have the feeling that a flow is more like a query to collect data than some method that can change the system state.
I would appreciate some input on what is an expected behavior of a Flow and how it can be use to model system behavior.
Thank you
m
Mikhail
10/25/2023, 4:37 AM
Looks like you need MVI pattern.
In case of flow you can use
transform
,
flatMapConcat
or
flatMapMerge
to launch coroutine inside of flow and emit data after delay. But this kind of code will be hard to maintain as it complexity grows.
u
uli
11/01/2023, 3:23 PM
I strongly believe all operator lambdas should be pure functions. Only act on your flows in the collector