Package-level declarations

Types

Link copied to clipboard

Writable saved property with a fallback applied only to reads and observation. Assignments are saved normally; reading a fallback never writes it to the handle. Created by StateValue.Companion.required or StateValue.Companion.default.

Link copied to clipboard

Lazily creates one holder using the ViewModel scope and the property name when no key is given.

Link copied to clipboard
class StateValue<T : Any>(handle: SavedStateHandle, key: String, serializer: KSerializer<T>, json: Json = Json, default: T? = null) : ReadWriteProperty<Any?, T?>

Serialized property delegate. Bind a property or supply a key before calling flow.

Link copied to clipboard
sealed class ViewModelState<T : Any>

Screen state stored as JSON in the supplied SavedStateHandle. Call APIs on the main thread, using a main-thread scope. Restoration guarantees are those of the handle's owner. Keep payloads small and replace collections instead of mutating them in place.

Functions

Link copied to clipboard
inline fun <T : Any> SavedStateHandle.saveResponseState(name: String = "", default: T? = null, json: Json = Json, serializer: KSerializer<T> = serializer<T>(), workerDispatcher: CoroutineDispatcher = Dispatchers.Default): StateDelegate<ViewModelState.Result<T>>

Creates result state as a ViewModel property, for example val users by handle.saveResponseState<List<User>>().

Link copied to clipboard
inline fun <T : Any> SavedStateHandle.saveState(name: String = "", default: T? = null, json: Json = Json, serializer: KSerializer<T> = serializer<T>(), workerDispatcher: CoroutineDispatcher = Dispatchers.Default): StateDelegate<ViewModelState.Regular<T>>

Creates plain saved state as a ViewModel property, for example val users by handle.saveState<List<User>>().

Link copied to clipboard
fun <A, B> StateFlow<A>.select(transform: (A) -> B): StateFlow<B>

Derives distinct immediate state. Keep transform pure and cheap; use selectAsync for heavy work.

Link copied to clipboard
fun <A, B> StateFlow<A>.selectAsync(scope: CoroutineScope, initialValue: B, workerDispatcher: CoroutineDispatcher = Dispatchers.Default, transform: suspend (A) -> B): StateFlow<B>

Computes an expensive projection on workerDispatcher, retaining its last completed value. Reading the returned StateFlow never invokes transform. New input cancels the old computation. Projection publication and output equality also run on the worker, using the same parent Job. scope controls observation; initialValue is visible until the first computation completes. Unlike select, this projection updates asynchronously. Keep inputs immutable. On JS/Wasm, a dispatcher does not provide a background thread: expensive work must cooperate with the event loop or use an application-provided worker implementation.

Link copied to clipboard
inline fun <T : Any> SavedStateHandle.value(key: String = "", default: T? = null, json: Json = Json, serializer: KSerializer<T> = serializer<T>()): StateValue<T>

Creates a saved property for use in common code, with no ViewModel requirement.