[英]What's the point of using LiveData in ViewModel if I can use Flow and StateFlow with lifecycleScope \ viewLifecycleOwner.lifecycleScope
Flow
has a lot of operators, LiveData
has only 3 (Transformations). Flow
有很多算子, LiveData
只有 3 个(Transformations)。 Is there any reason to keep using LiveData
except StateFlow is still experimental
?
除了 StateFlow 仍处于试验
阶段之外,还有什么理由继续使用 LiveData 吗?
UPD. UPD。 StateFlow, SharedFlow and corresponding operators are promoted to stable API in kotlinx.coroutines 1.4.0
在 kotlinx.coroutines 1.4.0 中,StateFlow、SharedFlow 和相应的算子被提升为稳定的 API
There is not much reason to use LiveData nowadays.现在没有太多理由使用 LiveData。 (State)Flow/Coroutines also brings new possibilites via lifecycleScope.launchWhenCreated/Started/Resumed, hard to do with LiveData.
(State)Flow/Coroutines 还通过lifecycleScope.launchWhenCreated/Started/Resumed 带来了新的可能性,LiveData 很难做到。
But there is one reason when LiveData is needed - DataBinding.但是需要 LiveData 有一个原因 - DataBinding。 It currently doesn't support observing Flow.
它目前不支持观察 Flow。
EDIT: there is going to be support for StateFlow in DataBinding in Android Studio 4.3: https://twitter.com/manuelvicnt/status/1314621067831521282编辑:Android Studio 4.3 中的 DataBinding 将支持 StateFlow: https://twitter.com/manuelvicnt/status/1314621067831521282
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.