Last active
January 19, 2020 01:03
-
-
Save Rasalexman/6684ce93d441a7bd2c5092b3c3765c67 to your computer and use it in GitHub Desktop.
ViewModel with Flow
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 { | |
// 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