delegate

fun <S : MVIState, I : MVIIntent, A : MVIAction, CS : MVIState, CI : MVIIntent, CA : MVIAction> StoreBuilder<S, I, A>.delegate(store: Store<CS, CI, CA>, mode: DelegationMode = DelegationMode.Default, name: String? = store.name?.let { "${it}DelegatePlugin" }, start: Boolean = true, blocking: Boolean = false, consume: ChildConsume<S, I, A, CA>? = null): StoreDelegate<CS, CI, CA>

Create a new StoreDelegate and install it as a storeDelegatePlugin.

The delegate can be used to project the state of the delegate store to the principal store and handle Actions using consume. The mode will be used to determine how and when the state/actions are projected.

val store = store(Loading) {
val feedState by delegate(feedStore) {
// handle actions
}
whileSubscribed {
feedState.collect { state ->
// use projection.
}
}
}

Return

A StoreDelegate instance that can be used to access the delegate store's state

Parameters

store

The store to delegate to

mode

The delegation mode that determines when and how the delegate's state/actions are projected

name

Optional name for the plugin, by default allows only one plugin per delegate.

start

Whether to automatically start the delegate store when the plugin is installed

blocking

Whether to wait for the delegate store to start before continuing (when start is true)

consume

Optional function to handle actions from the delegate store

See also