Skip to content

Instantly share code, notes, and snippets.

@Drjacky
Created November 7, 2018 16:16
Show Gist options
  • Select an option

  • Save Drjacky/e6d4379087e2b163ca546b2c6f28dd4a to your computer and use it in GitHub Desktop.

Select an option

Save Drjacky/e6d4379087e2b163ca546b2c6f28dd4a to your computer and use it in GitHub Desktop.

Revisions

  1. Drjacky created this gist Nov 7, 2018.
    20 changes: 20 additions & 0 deletions ResultState.kt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /**
    * A wrapper for database and network states.
    */
    sealed class ResultState<T> {

    /**
    * A state of [data] which shows that we know there is still an update to come.
    */
    data class Loading<T>(val data: T) : ResultState<T>()

    /**
    * A state that shows the [data] is the last known update.
    */
    data class Success<T>(val data: T) : ResultState<T>()

    /**
    * A state to show a [throwable] is thrown beside the [lastData] which is cached.
    */
    data class Error<T>(val throwable: Throwable, val lastData: T?) : ResultState<T>()
    }