ScreenState

sealed interface ScreenState<out T>

The one UI state an offline-first screen renders. Collapses the usual scatter of isLoading / isFromCache / isRefreshing / error / networkStatus flags into a single exhaustive type a when can render. Produced by DecisionEngine.decide from a StoreData snapshot + Connectivity.

Original implementation of the offline-first screen-state pattern — the concept is a common one; this is a clean-room, dependency-free take (no Store5, no HTTP client) for the MIT toolkit.

Inheritors

Types

Link copied to clipboard
data class Content<T>(val data: T, val fetchedAt: Instant? = null, val freshness: FreshnessBand = FreshnessBand.Initial, val isRefreshing: Boolean = false) : ScreenState<T>

Data to show, with freshness metadata. isRefreshing drives a background-refresh indicator.

Link copied to clipboard
data object Empty : ScreenState<Nothing>

A fetch completed but returned no content (e.g. an empty list).

Link copied to clipboard
data class Error(val error: Throwable, val isNetworkError: Boolean = false) : ScreenState<Nothing>

A non-network error with no usable cache.

Link copied to clipboard
data object Loading : ScreenState<Nothing>

Initial load — nothing to show yet.

Link copied to clipboard
data class NoNetwork(val isCaptivePortal: Boolean = false) : ScreenState<Nothing>

Offline with no cached data. isCaptivePortal is true behind a hotel/airport WiFi login wall.

Link copied to clipboard

Auth required (401/403 / token expiry) with no usable cache — send the user to sign-in.