Skip to content

Instantly share code, notes, and snippets.

@cohenItay
Created July 19, 2022 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cohenItay/58ee01349b0431200ac61747b6a3ef34 to your computer and use it in GitHub Desktop.
Save cohenItay/58ee01349b0431200ac61747b6a3ef34 to your computer and use it in GitHub Desktop.
sealed class LoadState<T> {
/**
* There is no concrete data at all, and nothing is being loaded.
*/
class Idle<T>: LoadState<T>() {
override fun equals(other: Any?): Boolean =
this === other || other is Idle<*>
override fun hashCode(): Int = javaClass.hashCode()
}
/**
* The loading work successfully replied the concrete data.
* @param model, the desired concrete data model
*/
data class Success<T>(val model: T) : LoadState<T>()
/**
* There is a failure, it could be infrastructure error (i.e network) or api-returned error (i.e server)
* @param apiError the error that has been returned from the api
* @param exception any appropriate exception (i.e HttpException)
* @param modelTypeId an identifier for the use of the owner which have created an instance of this class
*/
data class Failure<T>(
val apiError: ApiError? = null,
val exception: Exception? = null,
val modelTypeId: String? = null
) : LoadState<T>()
/**
* There is a loading process currently running.
* @param previousModel The previous concrete model which was published, if such exists.
* You might still need to use the old model while data is being loaded.
*/
data class InWork<T>(val previousModel: T?) : LoadState<T>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment