hegaojian / MvvmHelper

:chicken::basketball:这是一个快速开发的框架,Kotlin语言开发,MVVM+Jetpack架构,封装了公共头部、界面状态管理、ViewModel、LiveData、DataBinding、ViewBinding头部刷新、加载更多、沉浸式、全局通知、丰富好用的拓展函数、RxHttp网络请求等等一系列工具
Apache License 2.0
417 stars 60 forks source link

How to use AppViewModel as JetpackMvvm project #33

Closed Bugzer0 closed 1 year ago

Bugzer0 commented 1 year ago

I want to use global variable, for example i use AppViewModel in JetpackMvvm project class AppViewModel : BaseViewModel() { var userInfo = UnPeekLiveData.Builder<UserInfo>().setAllowNullValue(true).create() } in MvvmHelper, is there any substitute? thanks for awesome lib

hegaojian commented 1 year ago

In fact, AppViewModel is equivalent to a global singleton object, in MvvmHelper, you can write it in the singleton class For example:

object GlobalObject{
 var userInfo = UnPeekLiveData.Builder<UserInfo>().setAllowNullValue(true).create() 
}