NativeStore

class NativeStore<S : MVIState, I : MVIIntent, A : MVIAction>(store: Store<S, I, A>, autoStart: Boolean = false, scope: CoroutineScope = CoroutineScope(Dispatchers.Main.immediateOrDefault)) : Store<S, I, A> , CoroutineScope

This is an experimental wrapper for the store to support native platforms which do not have the coroutines api, such as iOS. Please fil an issue if you face any problems with this. You must call close when you are done working with the store. This stops the store.

Parameters

autoStart

whether to start the store immediately, false by default.

Constructors

Link copied to clipboard
constructor(store: Store<S, I, A>, autoStart: Boolean = false, scope: CoroutineScope = CoroutineScope(Dispatchers.Main.immediateOrDefault))

Properties

Link copied to clipboard
Link copied to clipboard
open override val name: String?

The name of the store. Used for debugging purposes and when storing multiple stores in a collection. Optional and configured through a pro.respawn.flowmvi.dsl.StoreBuilder

Link copied to clipboard
open override val state: S

Obtain the current state in an unsafe manner. This property is not thread-safe and parallel state updates will introduce a race condition when not handled properly. Such race conditions arise when using multiple data streams such as Flows.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
inline suspend fun <S : MVIState, I : MVIIntent, A : MVIAction> ImmutableStore<S, I, A>.collect(crossinline consume: suspend Provider<S, I, A>.() -> Unit)

Subscribe to this store and suspend until consume finishes (which should never return). This means the function will suspend forever.

Link copied to clipboard
open suspend override 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 <I : MVIIntent> IntentReceiver<I>.emit(vararg intents: I)

Alias for IntentReceiver.emit for multiple intents

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override 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 <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
open override fun start(scope: CoroutineScope): Job

Starts store intent processing in a new coroutine in the given scope. Intents are processed as long as the parent scope is active. Starting store processing when it is already started will result in an exception. Although not always needed, store can be launched multiple times, assuming you cancel the job used before or call Store.close.

Link copied to clipboard
open override fun CoroutineScope.subscribe(block: suspend Provider<S, I, A>.() -> Unit): Job

Subscribe to the store, obtaining a Provider to consume MVIStates and MVIActions. The store itself does not expose actions or states to prevent subscribers from affecting the store and to keep track of each subscription. When subscribe is invoked, a new StorePlugin.onSubscribe event is sent to all plugins with the new subscriber count. For more, see StorePlugin.

fun subscribe(onAction: (action: A) -> Unit, onState: (state: S) -> Unit): AutoCloseable

Same as Store.subscribe but does not manage the scope for you. close the subscription job manually.

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.