sealed class LoadingState<out R> { object Loading : LoadingState<Nothing>() data class Failure(val error : Throwable) : LoadingState<Nothing>() data class Success<T>(val data : T) : LoadingState<T>() val isLoading get() = this is Loading val isSuccess get() = this is Success<*> }
/** * Return an observable [snapshot][androidx.compose.runtime.snapshots.Snapshot] [State] that * produces values over time from [key1]. * * [producer] is launched when [produceState] enters the composition and is cancelled when * [produceState] leaves the composition. If [key1] changes, a running [producer] will be * cancelled and re-launched for the new source. [producer] should use [ProduceStateScope.value] * to set new values on the returned [State]. * * The returned [State] conflates values; no change will be observable if * [ProduceStateScope.value] is used to set a value that is [equal][Any.equals] to its old value, * and observers may only see the latest value if several values are set in rapid succession. * * [produceState] may be used to observe either suspending or non-suspending sources of external * data, for example: * * @sample androidx.compose.runtime.samples.ProduceState * * @sample androidx.compose.runtime.samples.ProduceStateAwaitDispose */