How to Return LiveData from Repository

后端 未结 3 1907
日久生厌
日久生厌 2020-12-22 08:52

I just can\'t see how to chain LiveData from Repo to VM, so I have tried to boil this down to the most simple of example!:

Fragment

         


        
3条回答
  •  囚心锁ツ
    2020-12-22 09:23

    You're changing mCurrentName (the LiveData variable itself as opposed to it's contents) after you start observing it. The guidance seems to be to not use LiveData in Repository layer (use Coroutines/Flow instead for example)....but for now you could have something like following (or perhaps use one of the LiveData Transformations)

    private val mCurrentName = firestoreRepository.currentName()
    
    fun changeText(){
        firestoreRepository.changeText()
    }
    

提交回复
热议问题