hegaojian / JetpackMvvm

:chicken::basketball:一个Jetpack结合MVVM的快速开发框架,基于MVVM模式集成谷歌官方推荐的JetPack组件库:LiveData、ViewModel、Lifecycle、Navigation组件 使用Kotlin语言,添加大量拓展函数,简化代码 加入Retrofit网络请求,协程,帮你简化各种操作,让你快速开发项目
https://github.com/hegaojian/JetpackMvvm
Apache License 2.0
3.13k stars 610 forks source link

Repository层不需要吗? #87

Closed TOPWN closed 2 years ago

TOPWN commented 2 years ago

我看这个网络框架是在viewmodel里直接调用apiservice进行网络请求,而标准的mvvm架构里应该是需要一个repository类来管理不同的请求数据源的,不知道作者选择去掉这一层是怎么考量的?

class UserRepository {
   private val webservice: Webservice = TODO()
   // ...
   suspend fun getUser(userId: String) =
       // This isn't an optimal implementation because it doesn't take into
       // account caching. We'll look at how to improve upon this in the next
       // sections.
       webservice.getUser(userId)
}
hegaojian commented 2 years ago

这个 repository是按需写的,在demo里面的数据基本上都是网络请求获取,其实之前写过一个 repository ,但是我觉得在这种简单的项目里面反而有点多余,所以直接去掉了。当然你可以按照标准来写。