PipelineContext

PipelineContext is an entity that exposes the underlying logic of the Store to its StorePlugins.

Context is an implementation of the following:

Pipeline context is built based on the parent CoroutineScope and depends on it. Pipeline context is a child of the CoroutineContext of the store (scope). The pipeline's context is always the context the store was started with.

Types

Link copied to clipboard

A key of the PipelineContext in the parent coroutine context.

Properties

Link copied to clipboard
abstract val config: StoreConfiguration<S>

The StoreConfiguration of this store

Link copied to clipboard
Link copied to clipboard
open override val key: CoroutineContext.Key<*>
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 action(action: A)

Send a new side-effect to be processed by subscribers, only once. How actions will be distributed and handled depends on ActionShareBehavior. Actions that make the capacity overflow may be dropped or the function may suspend until the buffer is freed.

Link copied to clipboard
inline suspend fun <A : MVIAction> ActionReceiver<A>.action(vararg actions: A)

Alias for ActionReceiver.action for multiple actions

Link copied to clipboard
open fun close()

Same as cancel, but for resolving the ambiguity between context.cancel() and scope.cancel()

Link copied to clipboard
open suspend fun <T> Flow<T>.consume(context: CoroutineContext = EmptyCoroutineContext)

An alias for Flow.collect that does not override the context, amending it instead. Use as a safer alternative to Flow.flowOn and then Flow.collect

Link copied to clipboard
abstract suspend fun emit(intent: I)

Alias for intent with one difference - this function will suspend if pro.respawn.flowmvi.dsl.StoreBuilder.onOverflow permits it.

Link copied to clipboard
inline suspend fun <A : MVIAction> ActionReceiver<A>.emit(action: A)
inline suspend fun <A : MVIAction> ActionReceiver<A>.emit(vararg actions: A)

Alias for ActionReceiver.action for multiple actions

inline suspend fun <I : MVIIntent> IntentReceiver<I>.emit(vararg intents: I)

Alias for IntentReceiver.emit for multiple intents

Link copied to clipboard
open override fun <R> fold(initial: R, operation: (R, CoroutineContext.Element) -> R): R
Link copied to clipboard
open operator override fun <E : CoroutineContext.Element> get(key: CoroutineContext.Key<E>): E?
Link copied to clipboard
abstract fun intent(intent: I)

Send an intent asynchronously. The intent is sent to the receiver and is placed in a queue. When IntentReceiver is available (e.g. when the Store is started), the intent will be processed. Intents that overflow the buffer will be handled according to the behavior specified in pro.respawn.flowmvi.dsl.StoreBuilder.onOverflow. If the store is not started when an intent is sent, it will wait in the buffer, and will be processed once the store is started.

Link copied to clipboard
inline fun <I : MVIIntent> IntentReceiver<I>.intent(vararg intents: I)

Alias for IntentReceiver.intent for multiple intents

Link copied to clipboard
fun PipelineContext<*, *, *>.log(e: Exception, level: StoreLogLevel = StoreLogLevel.Error, tag: String? = config.name)
fun PipelineContext<*, *, *>.log(level: StoreLogLevel = StoreLogLevel.Debug, tag: String? = config.name, message: () -> String)

Write a message to StoreLogger. Tag is the Store.name by default.

Link copied to clipboard
open override fun minusKey(key: CoroutineContext.Key<*>): CoroutineContext
Link copied to clipboard
open operator fun plus(context: CoroutineContext): CoroutineContext
Link copied to clipboard
abstract fun send(action: A)

Alias for action with one difference - this function will launch a new coroutine to send the intent in background.

Link copied to clipboard
inline fun <A : MVIAction> ActionReceiver<A>.send(vararg actions: A)

Alias for ActionReceiver.send for multiple actions

fun <I : MVIIntent> IntentReceiver<I>.send(intent: I)
inline fun <I : MVIIntent> IntentReceiver<I>.send(vararg intents: I)

Alias for IntentReceiver.intent for multiple intents

Link copied to clipboard
@JvmName(name = "subscribeAndRender")
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> CoroutineScope.subscribe(store: ImmutableStore<S, I, A>, crossinline render: suspend (state: S) -> Unit): Job

Subscribe to the store and invoke render. This does not collect store's actions.

@JvmName(name = "subscribeConsume")
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> CoroutineScope.subscribe(store: ImmutableStore<S, I, A>, crossinline consume: suspend Provider<S, I, A>.() -> Unit): Job

Subscribe to the store. An overload of Store.subscribe that is applied on CoroutineScope.

@JvmName(name = "subscribeAndRender")
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> CoroutineScope.subscribe(store: ImmutableStore<S, I, A>, crossinline consume: suspend (action: A) -> Unit, crossinline render: suspend (state: S) -> Unit): Job

Subscribe to the store and invoke consume and render in parallel in the provided scope.

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.