George Theocharis
08/04/2020, 3:47 PMmutableStateFlow.asLiveData()
is pretty much best of both worlds as you can have access to the operators privately while exposing a lifecycle aware state? Is there any huge pitfall I haven’t think of?wasyl
08/04/2020, 3:50 PMStateFlow
collected in e.g. fragment’s view lifecycle scope?streetsofboston
08/04/2020, 3:51 PMlifecycleScope
, even using the whenStarted { … }
or whenResumed { … }
constructs that make use of the Pausing Dispatcher.George Theocharis
08/04/2020, 3:55 PMstreetsofboston
08/04/2020, 3:58 PMGeorge Theocharis
08/04/2020, 3:58 PMIan Lake
08/04/2020, 4:00 PMshareIn
to land before swapping entirely away from using asLiveData()
as without the shareIn
you're going to lose the caching of the previous state. StateFlow obviously keeps it's current state all the time alreadyokarm
08/04/2020, 4:23 PMStateFlow
conflates by structural equality, therefore if you want to expose for example a domain entity implementing equals
in terms of its ID, then StateFlow
will never emit updates. Discovered this recently and had to go back to ConflatedBroadcastChannel
which conflates by referential equality.