Skip to content

Instantly share code, notes, and snippets.

@featzima
Created July 2, 2018 22:42
Show Gist options
  • Save featzima/deac6def7045093f9fdeb57d1db1d698 to your computer and use it in GitHub Desktop.
Save featzima/deac6def7045093f9fdeb57d1db1d698 to your computer and use it in GitHub Desktop.
data class MyViewModel(
private val myEndpoint: MyEndpoint): DisposableViewModel() {
private val searchText = ChannelLiveData("")
private val inProgress = ChannelLiveData(false)
private val result = ChannelLiveData("")
init {
disposableLaunch {
searchText.consumeEach { searchText ->
inProgress.send(true)
val searchResult = myEndpoint.search(searchText)
inProgress.send(false)
result.send(searchResult)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment