StateReceiver

interface StateReceiver<S : MVIState>

An entity that handles MVIState updates. This entity modifies the state of the StateProvider. This is most often implemented by a Store and exposed through PipelineContext.

Inheritors

Properties

Link copied to clipboard
abstract val state: S

Obtain the current value of state in an unsafe manner. It is recommended to always use withState or updateState as obtaining this value can lead to data races when the state transaction changes the value of the state previously obtained.

Functions

Link copied to clipboard
abstract suspend fun updateState(transform: suspend S.() -> S)

Obtain the current StateProvider.state and update it with the result of transform.

Link copied to clipboard
inline suspend fun <T : S, S : MVIState> StateReceiver<S>.updateState(crossinline transform: suspend T.() -> S)

A typed overload of StateReceiver.updateState.

Link copied to clipboard
abstract fun updateStateImmediate(block: S.() -> S)

A function that obtains current state and updates it atomically (in the thread context), and non-atomically in the coroutine context, which means it can cause races when you want to update states in parallel.

Link copied to clipboard
inline fun <T : S, S : MVIState> StateReceiver<S>.updateStateImmediate(crossinline transform: T.() -> S)
Link copied to clipboard
open fun useState(block: S.() -> S)
Link copied to clipboard
inline fun <T : S, S : MVIState> StateReceiver<S>.useState(crossinline transform: T.() -> S)
Link copied to clipboard
abstract suspend fun withState(block: suspend S.() -> Unit)

Obtain the current state and operate on it without changing the state.

Link copied to clipboard
inline suspend fun <T : S, S : MVIState> StateReceiver<S>.withState(crossinline block: suspend T.() -> Unit)

A typed overload of StateReceiver.withState.