subscribe

@JvmName(name = "subscribeConsume")
fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S, I, A>.subscribe(lifecycle: SubscriberLifecycle = DefaultLifecycle, mode: SubscriptionMode = SubscriptionMode.Started, consume: suspend CoroutineScope.(action: A) -> Unit): State<S>

A function to subscribe to the store that follows the system lifecycle.

  • This function will assign the store a new subscriber when invoked, then populate the returned State with new states.

  • Provided consume parameter will be used to consume actions that come from the store.

  • Store's subscribers will not wait until the store is launched when they subscribe to the store. Such subscribers will not receive state updates or actions. Don't forget to launch the store.

Return

the State that contains the current state.

Parameters

mode

the subscription mode that should be reached in order to subscribe to the store. At specified moments in the UI lifecycle (Activity, Composable, Window etc), the store will subscribe and unsubscribe from the store.

consume

a lambda to consume actions with.

See also


fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S, I, A>.subscribe(lifecycle: SubscriberLifecycle = DefaultLifecycle, mode: SubscriptionMode = SubscriptionMode.Started): State<S>

A function to subscribe to the store that follows the system lifecycle.

  • This function will assign the store a new subscriber when invoked, then populate the returned State with new states.

  • Store's subscribers will not wait until the store is launched when they subscribe to the store. Such subscribers will not receive state updates or actions. Don't forget to launch the store.

Return

the State that contains the current state.

Parameters

mode

the subscription mode that should be reached in order to subscribe to the store. At specified moments in the UI lifecycle (Activity, Composable, Window etc), the store will subscribe and unsubscribe from the store.

See also


inline fun <S : MVIState, I : MVIIntent, A : MVIAction> LifecycleOwner.subscribe(store: Store<S, I, A>, noinline consume: suspend (action: A) -> Unit, crossinline render: suspend (state: S) -> Unit, lifecycleState: Lifecycle.State = Lifecycle.State.STARTED): Job

Subscribe to the store lifecycle-aware.

Parameters

consume

called on each new action. Implement action handling here.

render

called each time the state changes. Render state here.

lifecycleState

the minimum lifecycle state the LifecycleOwner must be in to receive updates.

See also


inline fun <S : MVIState, I : MVIIntent, A : MVIAction> LifecycleOwner.subscribe(store: Store<S, I, A>, crossinline render: suspend (state: S) -> Unit, lifecycleState: Lifecycle.State = Lifecycle.State.STARTED): Job

Subscribe to the store lifecycle-aware.

Parameters

render

called each time the state changes. Render state here.

lifecycleState

the minimum lifecycle state the LifecycleOwner must be in to receive updates.

See also


@JvmName(name = "subscribeAndConsume")
fun <S : MVIState, I : MVIIntent, A : MVIAction, T : LifecycleOwner, StateConsumer<S>, ActionConsumer<A>> T.subscribe(provider: Store<S, I, A>, lifecycleState: Lifecycle.State = Lifecycle.State.STARTED): Job

Subscribe to the store lifecycle-aware.

Parameters

lifecycleState

the minimum lifecycle state the LifecycleOwner must be in to receive updates.

See also


fun <S : MVIState, I : MVIIntent, A : MVIAction, T : LifecycleOwner, StateConsumer<S>> T.subscribe(provider: Store<S, I, A>, lifecycleState: Lifecycle.State = Lifecycle.State.STARTED): Job

Subscribe to the store lifecycle-aware. This function will not collect the store's actions.

Parameters

lifecycleState

the minimum lifecycle state the LifecycleOwner must be in to receive updates.

See also