我有一个由其他sViewModel扩展的基础:ViewModel
abstract class BaseViewModel : ViewModel() {
protected val _state = MutableLiveData<Boolean>()
protected val state: LiveData<Boolean> = _state
...
}
我希望能够在state更改(_state.setValue(newvalue)或被_state.postValue(newvalue)调用)时做出反应(例如,添加日志语句),并且我想在BaseViewModel.
我怎么做?