Eduard Boloș
12/16/2022, 7:23 PMFlow
with data binding, but it needs to be a StateFlow
, for one-way binding? As far as my imagination goes, you should be able to just collect a simple Flow
and update the view from the FlowCollector
, but I might be missing something. Also, are there any known workarounds? I didn't manage to find anything by Googling.
The context is that we are looking to migrate from LiveData to Flows, and we have hundreds, if not thousands of LDs that are bound in XML that now would become Flows, and going through each and one of them to transform them to a StateFlow
using the stateIn()
operator is not very feasible 😞commanderpepper
12/16/2022, 7:40 PMStateFlow
is desired over Flow
because it requires an initial state similar to LiveData
.Eduard Boloș
12/16/2022, 9:22 PMLiveData
doesn't require an initial value though
https://developer.android.com/reference/androidx/lifecycle/LiveData#LiveData()mattinger
12/22/2022, 4:14 AMmattinger
12/22/2022, 4:17 AMmattinger
12/22/2022, 4:18 AMEduard Boloș
12/23/2022, 10:20 AMStateFlow
is that you always have a value. The problem is that sometimes it's harder to have a StateFlow
at hand. For instance imagine if you need to apply several operations like map
, the result will be a simple Flow
because of the suspending nature of the operators the value won't be there right away. You could then do .stateIn(scope, started, initialValue)
, but when you have a lot of different fields you need to do this for, it becomes annoying, to say the least, or you might not even have a sensible initialValue
to begin with.
What would I expect to happen when using Flow
would be similar with what happens when using LiveData
, which is for nothing to be set on the view until a value is emitted 🤷