Florian
11/10/2020, 6:04 PMCasey Brooks
11/10/2020, 6:10 PMlifecycleScope
you pretty much get the same benefit with all the additional features and much nicer API of Flow. Personally, I don’t see any reason now to choose LiveData over Flow (especially StateFlow)Ian Lake
11/10/2020, 6:15 PMStateFlow
and SharedFlow
, there's no reason to purposefully choose LiveData for any new code you're writingFlorian
11/10/2020, 6:27 PMzhuinden
11/10/2020, 6:30 PMSavedStateHandle.getLiveData
then? Also, does this mean one has to reimplement Paging 3's cachedIn(viewModelScope)
or is there a replacement for it?rkeazor
11/10/2020, 6:39 PMIan Lake
11/10/2020, 6:43 PMshareIn
in your ViewModel is what you'd use to cache state across config changescachedIn
is just Paging 3's equivalent to shareIn
before shareIn
was a thing - expect for it to be unnecessary/removed in the futureSavedStateHandle
doesn't depend on coroutines (so it can't provide a StateFlow
directly), but you can always asFlow
anything that gives you a LiveData
Florian
11/10/2020, 6:52 PMSavedStateHandke#getStateFlow
?Ian Lake
11/10/2020, 6:57 PMdoesn't depend on coroutines (so it can't provide aSavedStateHandle
directly)StateFlow
Jan Skrasek
11/10/2020, 7:04 PMFlorian
11/10/2020, 7:21 PMzhuinden
11/10/2020, 8:31 PMFlorian
11/10/2020, 9:16 PMIan Lake
11/10/2020, 11:36 PM/**
* Similar to [kotlinx.coroutines.flow.launchIn] but using
* [androidx.lifecycle.LifecycleCoroutineScope.launchWhenStarted].
*/
fun <T> Flow<T>.launchWhenStartedIn(
lifecycleOwner: LifecycleOwner
) = lifecycleOwner.lifecycleScope.launchWhenStarted {
collect()
}
which then lets you use a more LiveData like syntax of
viewModel.yourFlow.onEach { items ->
// Do something with the items
}.launchWhenStartedIn(viewLifecycleOwner)
dave08
11/11/2020, 3:17 AMtakahirom
11/11/2020, 4:49 AMIan Lake
11/11/2020, 5:22 AMflow
or callbackFlow
) or a SharedFlow
(which replaces ConflatedBroadcastChannel
, etc.)Flow
) to Flow+replay (SharedFlow
which extends Flow
) and finally Flow+replay+always available current state (StateFlow
which extends SharedFlow
)LiveData
has none of those lower level constructs - it is solely a take it or leave it type of API (perfect for the 80% case, terrible for the rest). Anti-patterns like SingleLiveEvent
are just a sign that you're actually looking for one of those lower level APIs and you can avoid all that mess in the Flow worldgildor
11/11/2020, 3:07 PMNemanja Mladenović
11/12/2020, 7:11 AMgildor
11/12/2020, 7:12 AMNemanja Mladenović
11/12/2020, 7:15 AMgildor
11/12/2020, 7:20 AMdave08
11/12/2020, 10:10 AMNemanja Mladenović
11/12/2020, 10:12 AMOrhan Tozan
11/12/2020, 10:13 AMNemanja Mladenović
11/12/2020, 10:14 AMOrhan Tozan
11/12/2020, 10:16 AMdave08
11/12/2020, 10:24 AMNemanja Mladenović
11/12/2020, 12:03 PMgildor
11/12/2020, 12:40 PMdave08
11/12/2020, 12:48 PM... consumable state ...?
takahirom
11/12/2020, 2:35 PMOrhan Tozan
11/12/2020, 3:20 PMtakahirom
11/12/2020, 3:26 PMdave08
11/12/2020, 4:23 PMgildor
11/12/2020, 4:35 PMtakahirom
11/13/2020, 1:35 AMgildor
11/13/2020, 1:55 AMFlorian
11/13/2020, 3:14 PMOrhan Tozan
11/13/2020, 3:15 PMFlorian
11/13/2020, 3:15 PMOrhan Tozan
11/13/2020, 3:17 PMFlorian
11/13/2020, 3:19 PMOrhan Tozan
11/13/2020, 3:23 PMFlorian
11/13/2020, 3:30 PMRoshan P Varghese
11/29/2020, 4:54 PMFlorian
11/30/2020, 6:59 AM