Skip to content

Instantly share code, notes, and snippets.

@featzima
Created July 2, 2018 22:41
Show Gist options
  • Save featzima/bf00d66ddf1f7d1befc6065381891a96 to your computer and use it in GitHub Desktop.
Save featzima/bf00d66ddf1f7d1befc6065381891a96 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
.openSubscription()
.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