Skip to content

Instantly share code, notes, and snippets.

@Rasalexman
Last active January 19, 2020 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rasalexman/6684ce93d441a7bd2c5092b3c3765c67 to your computer and use it in GitHub Desktop.
Save Rasalexman/6684ce93d441a7bd2c5092b3c3765c67 to your computer and use it in GitHub Desktop.
ViewModel with Flow
class MyViewModel(
private val pagesRepository: IPagesRepository
) : ViewModel() {
val eventPageLiveData = MutableLiveData<ViewEvent<Int>>()
val resultLiveData: LiveData<Result<List<MyUIModel>>> by lazy {
// do some work on IO
liveData(context = viewModelScope.coroutineContext + Dispatcher.IO) {
emitSource(pagesRepository.getNextPageData(eventPageLiveData).asLiveData())
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment