interface StateHolder<State>

A container for managing state.

The state property is the only property that should be exposed to the UI level. All updating should be handled separately.

Example usage:



The type of the state.


Link copied to clipboard
object Companion


Link copied to clipboard
abstract val state: StateFlow<State>

The current state of type State exposed as a StateFlow.


Link copied to clipboard
abstract fun <T> addSource(flow: Flow<T>, scope: CoroutineScope, block: suspend (State, T) -> State): Job

Add a source of state from another Flow.

Link copied to clipboard
Link copied to clipboard
open operator fun getValue(stateOwner: StateOwner<State>, property: KProperty<*>): StateFlow<State>

Allows using delegation to access the StateHolder.state property.

Link copied to clipboard
abstract fun update(block: (State) -> State)

Updates the MutableStateFlow.value atomically using the specified function of its value. function may be evaluated multiple times, if value is being concurrently updated.