https://github.com/zunjae/vresult
Handle results nicely
https://github.com/zunjae/vresult
Last synced: about 1 year ago
JSON representation
Handle results nicely
- Host: GitHub
- URL: https://github.com/zunjae/vresult
- Owner: zunjae
- License: mit
- Created: 2019-09-19T08:26:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-10-23T07:32:19.000Z (over 6 years ago)
- Last Synced: 2025-03-11T15:16:23.120Z (about 1 year ago)
- Language: Kotlin
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VResult
Handle results nicely
## Example usage:
ViewModel class:
```kotlin
class KanonViewModel(val kanonService: KanonService): ViewModel {
var bookmarks: MutableLiveData>> = MutableLiveData()
fun loadBookmarks() {
launchListOperation(bookmarks) {
kanonService.userBookmarks().execute().body()
}
}
}
```
Fragment:
```kotlin
viewModel.bookmarks.observe(this, Observer { result ->
when (result) {
is VResult.Loading -> {
// show loading
}
is VResult.Success -> {
dataSource.set(result.response)
}
is VResult.NoResult -> {
// show no results
}
is VResult.Error -> {
// show error
}
}
})
```