xiaobailong24 / MVVMArms

Android MVVM Architecture Components based on MVPArms and Android Architecture Components.
Apache License 2.0
424 stars 64 forks source link

如果在viewmodel配合rxjava,该如何使用 #10

Closed magic0908 closed 6 years ago

magic0908 commented 6 years ago

看了demo,viewmodel是使用livedata的,但是个人觉得livedata远没有rxjava强大。如果在viewmodel使用rxjava,那么该如何实现类似livedata那样的动态更新数据?

xiaobailong24 commented 6 years ago

LiveData 是类似观察者模式的,可以在 View 层接收到数据变化的通知来刷新 UI。 RxJava 的话,就类似 MVP 中使用的方式了,需要手动调 View 层接口。

magic0908 commented 6 years ago

意思是说还需要在viewmodel持有view接口的实例,然后通过回调来通知view更新?如果是这样的话就和MVP没啥区别了,也没有意义了

xiaobailong24 commented 6 years ago

其实业务逻辑可以用 RxJava,UI 数据用 LiveData 就可以了