Last active
January 18, 2020 23:59
-
-
Save Rasalexman/7c6a0fe69067a16e8a597bd8d5a07749 to your computer and use it in GitHub Desktop.
ViewModel with LiveData ViewEvent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyViewModel( | |
private val pagesRepository: IPagesRepository | |
) : ViewModel() { | |
val eventPageLiveData = MutableLiveData<ViewEvent<Int>>() | |
val resultLiveData: LiveData<Result<List<MyUIModel>>> by lazy { | |
eventPageLiveData.switchMap { pageEvent -> | |
liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) { | |
emit(pagesRepository.getNextPageData(pageEvent.data)) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment