All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.pro.respawn.flowmvi.compose.dsl.SubscribeDsl.kt Maven / Gradle / Ivy

Go to download

A Kotlin Multiplatform MVI library based on coroutines with a powerful plugin system

There is a newer version: 3.0.0
Show newest version
package pro.respawn.flowmvi.compose.dsl

import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import kotlinx.coroutines.CoroutineScope
import pro.respawn.flowmvi.api.FlowMVIDSL
import pro.respawn.flowmvi.api.ImmutableStore
import pro.respawn.flowmvi.api.MVIAction
import pro.respawn.flowmvi.api.MVIIntent
import pro.respawn.flowmvi.api.MVIState
import pro.respawn.flowmvi.api.Store

/**
 * 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.
 *
 * @param consume a lambda to consume actions with.
 * @return the [State] that contains the [Store.state].
 * @see Store.subscribe
 */
@Composable
@FlowMVIDSL
public expect inline fun  ImmutableStore.subscribe(
    noinline consume: suspend CoroutineScope.(action: A) -> Unit,
): State

/**
 * A function to subscribe to the store that follows the system lifecycle.
 *
 * * This function will not collect [MVIAction]s.
 * * 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.
 *   upon leaving that state, the function will unsubscribe.
 * @return the [State] that contains the [Store.state].
 * @see Store.subscribe
 */
@Composable
@FlowMVIDSL
public expect inline fun  ImmutableStore.subscribe(): State