Skip to content

Instantly share code, notes, and snippets.


PatilShreyas/ViewStateDemo.kt Secret

Last active Dec 29, 2020
What would you like to do?
sealed class ViewState {
object Loading: ViewState()
class Success(val someData: String): ViewState()
class Failure(val message: String): ViewState()
fun main() {
val message = when (getViewState()) {
is ViewState.Loading -> "Data is loading"
is ViewState.Success -> "Got data: ${state.someData}"
is ViewState.Failure -> "It failed! ${state.message}"
fun getViewState(): ViewState = listOf(ViewState.Loading, ViewState.Success("MyData"), ViewState.Failure("Error")).random()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment