Package-level declarations

Types

Link copied to clipboard

A plugin that allows to cache the value of a property, scoping it to the pro.respawn.flowmvi.api.Store's lifecycle. This plugin will clear the value when PipelineContext is canceled and call the init block each time a store is started to initialize it again.

Link copied to clipboard
class JobManager<K : Any>

An entity that manages running jobs. Used with jobManagerPlugin and manageJobs. Will cancel and remove all jobs if the parent pro.respawn.flowmvi.api.Store is closed

Link copied to clipboard
typealias Recover<S, I, A> = suspend PipelineContext<S, I, A>.(e: Exception) -> Exception?
Link copied to clipboard
typealias Reduce<S, I, A> = suspend PipelineContext<S, I, A>.(intent: I) -> Unit

An operation that processes incoming MVIIntents

Link copied to clipboard

A class that manages the job that waits for subscribers to appear. This job is set by the awaitSubscribersPlugin when the store is launched. Use await or complete to manage the job. You can only complete the job once per one start of the store.

Link copied to clipboard
class TimeTravel<S : MVIState, I : MVIIntent, A : MVIAction>(maxStates: Int = DefaultHistorySize, maxIntents: Int = DefaultHistorySize, maxActions: Int = DefaultHistorySize, maxExceptions: Int = DefaultHistorySize)

A plugin that keeps track of changes in the store. It keeps references to last maxStates (inclusive) states and so on for other properties. Keep a reference to this plugin and use it to enable custom time travel support or validate the store's behavior in tests.

Link copied to clipboard
class UndoRedo(maxQueueSize: Int)

An object that allows to undo and redo any actions happening in the pro.respawn.flowmvi.api.Store. Keep a reference to the object instance to call undo, redo, and invoke. Don't forget to install the corresponding plugin with undoRedoPlugin.

Properties

Link copied to clipboard

Default name for the SavedStatePlugin

Link copied to clipboard

Default name for reducePlugin. This is hardcoded so that multiple reduce invocations are not allowed w/o explicit consent of the user as most often multiple reducers will conflict with each other. Provide your own name if you want to have multiple reducers.

Functions

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> androidLoggingPlugin(tag: String? = null, level: Int? = null): LazyPlugin<S, I, A>

Create a new loggingPlugin that prints using android's Log.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.androidLoggingPlugin(name: String? = null, level: Int? = null)

Create a new loggingPlugin that prints using android's Log.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.awaitSubscribers(manager: SubscriberManager = SubscriberManager(), minSubs: Int = 1, suspendStore: Boolean = true, timeout: Duration = Duration.INFINITE, name: String = SubscriberManager.Name): SubscriberManager

Installs a new awaitSubscribersPlugin

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> awaitSubscribersPlugin(manager: SubscriberManager, minSubs: Int = 1, suspendStore: Boolean = true, timeout: Duration = Duration.INFINITE, name: String = SubscriberManager.Name): StorePlugin<S, I, A>

Installs a new plugin using manager that will start waiting for new subscribers when the store launches. The plugin will wait for minSubs subscribers for a maximum duration of timeout. If suspendStore is true, then the store will not process any MVIIntents while it waits for subscribers. This plugin starts waiting after plugins installed before have finished their StorePlugin.onStart block. By default, cannot be installed multiple times, but name can be overridden to allow that, provided that you do not reuse the manager.

Link copied to clipboard
fun <T, S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.cache(name: String? = null, init: suspend PipelineContext<S, I, A>.() -> T): CachedValue<T, S, I, A>

Creates and installs a new CachedValue, returning a delegate that can be used to get access to the property that was cached. Please consult the documentation of the parent class to understand how to use this plugin.

Link copied to clipboard
fun <T, S : MVIState, I : MVIIntent, A : MVIAction> cached(init: suspend PipelineContext<S, I, A>.() -> T): CachedValue<T, S, I, A>

Creates and returns a new CachedValue.

Link copied to clipboard
fun <T, S : MVIState, I : MVIIntent, A : MVIAction> cachePlugin(value: CachedValue<T, S, I, A>, name: String? = null): StorePlugin<S, I, A>

Converts value to a StorePlugin. Mostly needed when storing a direct reference to the CachedValue out of the store's scope (which is less safe). For all other cases, use cache.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> compositePlugin(plugins: List<StorePlugin<S, I, A>>, name: String? = null): StorePlugin<S, I, A>

A plugin that delegates to plugins in the iteration order. This is an implementation of the "Composite" pattern and the "Chain or Responsibility" pattern.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> consoleLoggingPlugin(tag: String? = null, level: StoreLogLevel? = null): LazyPlugin<S, I, A>

A logging plugin that prints logs to the console using println. Tag is not used except for naming the plugin.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.consumeIntents(name: String = ConsumeIntentsPluginName)

Create and install a plugin that consumes intents and does nothing with them.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> consumeIntentsPlugin(name: String = ConsumeIntentsPluginName): StorePlugin<S, I, A>

Create a StorePlugin that simply consumes intents and does nothing with them. This is useful when you are using reducePlugin with consume = false You can add this to the end of your store declaration to consume the remaining unprocessed intents if you are sure that you already handled all of them fully

Link copied to clipboard

Installs a new disallowRestartPlugin. Please consult the docs of the parent function to learn more. This plugin can only be installed only once.

Link copied to clipboard

Disallow restart plugin will allow the store to be pro.respawn.flowmvi.api.Store.started only once. It will throw on any subsequent invocations of StorePlugin.onStart. You can use this when you are sure that you are not going to restart your store. I.e. you are using the scope with which you launch the store only once, such as viewModelScope on Android.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.enableLogging(tag: String? = null, level: StoreLogLevel? = null, name: String? = null, logger: StoreLogger? = null)

Install a new loggingPlugin.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.init(block: suspend PipelineContext<S, I, A>.() -> Unit)

Installs a plugin that invokes block when pro.respawn.flowmvi.api.Store.start is called.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> initPlugin(block: suspend PipelineContext<S, I, A>.() -> Unit): StorePlugin<S, I, A>

Creates a plugin that invokes block after pro.respawn.flowmvi.api.Store.start is called.

Link copied to clipboard
fun <K : Any, S : MVIState, I : MVIIntent, A : MVIAction> jobManagerPlugin(manager: JobManager<K>, name: String? = JobManager.Name): StorePlugin<S, I, A>

Create a new plugin that uses manager to manage jobs. This will cancel and remove all jobs when the parent pro.respawn.flowmvi.api.Store is closed.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> loggingPlugin(tag: String? = null, level: StoreLogLevel? = null, name: String? = null, logger: StoreLogger? = null): LazyPlugin<S, I, A>

Create a new StorePlugin that prints messages using log.

Link copied to clipboard
fun <K : Any, A : MVIAction, I : MVIIntent, S : MVIState> StoreBuilder<S, I, A>.manageJobs(jobs: JobManager<K> = JobManager(), name: String = JobManager.Name): JobManager<K>

Create and install a new plugin that uses JobManager to manage running jobs. The plugin will cancel all running jobs if the store is closed.

Link copied to clipboard

Log store's events using platform logger.

Link copied to clipboard

A plugin that does nothing. Useful for testing or mocking

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction, S2 : MVIState, I2 : MVIIntent> StoreBuilder<S, I, A>.parentStore(parent: Store<S2, I2, *>, name: String? = parent.name?.let { "ParentStorePlugin\$$it" }, minExternalSubscriptions: Int = 1, crossinline render: suspend PipelineContext<S, I, A>.(state: S2) -> Unit)

Install a new parentStorePlugin. This overload does not collect the parent store's actions.

inline fun <S : MVIState, I : MVIIntent, A : MVIAction, S2 : MVIState, I2 : MVIIntent, A2 : MVIAction> StoreBuilder<S, I, A>.parentStore(parent: Store<S2, I2, A2>, name: String? = parent.name?.let { "ParentStorePlugin\$$it" }, minExternalSubscriptions: Int = 1, crossinline consume: suspend PipelineContext<S, I, A>.(action: A2) -> Unit, crossinline render: suspend PipelineContext<S, I, A>.(state: S2) -> Unit)

Install a new parentStorePlugin.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction, S2 : MVIState, I2 : MVIIntent> parentStorePlugin(parent: Store<S2, I2, *>, name: String? = parent.name?.let { "ParentStorePlugin\$$it" }, minExternalSubscriptions: Int = 1, crossinline render: suspend PipelineContext<S, I, A>.(state: S2) -> Unit): StorePlugin<S, I, A>

Creates and installs a new plugin that will subscribe to the parent store at the same time the current store is subscribed to and when minExternalSubscriptions are reached.

inline fun <S : MVIState, I : MVIIntent, A : MVIAction, S2 : MVIState, I2 : MVIIntent, A2 : MVIAction> parentStorePlugin(parent: Store<S2, I2, A2>, name: String? = parent.name?.let { "ParentStorePlugin\$$it" }, minExternalSubscriptions: Int = 1, crossinline consume: suspend PipelineContext<S, I, A>.(action: A2) -> Unit, crossinline render: suspend PipelineContext<S, I, A>.(state: S2) -> Unit): StorePlugin<S, I, A>

An overload of the parentStorePlugin that also consumes its MVIActions. Please see the other overload for more documentation.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> platformLoggingPlugin(tag: String? = null, level: StoreLogLevel? = null): LazyPlugin<S, I, A>

Creates a loggingPlugin that is suitable for each targeted platform. This plugin will log to:

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.recover(name: String? = null, recover: Recover<S, I, A>)

Create and install a recoverPlugin.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> recoverPlugin(name: String? = null, recover: Recover<S, I, A>): StorePlugin<S, I, A>

Create a plugin that simply invokes StorePlugin.onException and decides how to proceed accordingly. See the parent function for more information.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.reduce(consume: Boolean = true, name: String = ReducePluginName, crossinline reduce: Reduce<S, I, A>)

Create and install a reducePlugin.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> reducePlugin(consume: Boolean = true, name: String = ReducePluginName, crossinline reduce: Reduce<S, I, A>): StorePlugin<S, I, A>

Create a new plugin that simply invokes StorePlugin.onIntent, processes it and does not change the intent.

Link copied to clipboard
fun <K : Any> Job.register(manager: JobManager<K>, key: K): Job
Link copied to clipboard
suspend fun <K : Any> Job.registerOrReplace(manager: JobManager<K>, key: K): Job?
Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> savedStatePlugin(name: String = DefaultSavedStatePluginName, context: CoroutineContext = EmptyCoroutineContext, crossinline get: suspend S.() -> S?, crossinline set: suspend (S) -> Unit): StorePlugin<S, I, A>

A plugin that restores the pro.respawn.flowmvi.api.StateProvider.state using get in StorePlugin.onStart and saves using set asynchronously in StorePlugin.onState. There are platform overloads for this function.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.saveState(name: String = DefaultSavedStatePluginName, context: CoroutineContext = EmptyCoroutineContext, crossinline get: suspend S.() -> S?, crossinline set: suspend S.() -> Unit)

Creates and installs a new savedStatePlugin.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.timeTravel(historySize: Int = TimeTravel.DefaultHistorySize, name: String = TimeTravel.Name): TimeTravel<S, I, A>

Create a new TimeTravel and installs it. Keep a reference to the returning value to use its properties.

fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.timeTravel(timeTravel: TimeTravel<S, I, A>, name: String = TimeTravel.Name)

Create a new TimeTravel and installs it. Keep a reference to the object to use its properties.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> timeTravelPlugin(timeTravel: TimeTravel<S, I, A>, name: String = TimeTravel.Name): StorePlugin<S, I, A>

Install the specified timeTravel as a plugin.

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.undoRedo(maxQueueSize: Int, name: String? = null, resetOnException: Boolean = true): UndoRedo

Creates, installs and returns a new UndoRedo instance

Link copied to clipboard
fun <S : MVIState, I : MVIIntent, A : MVIAction> undoRedoPlugin(undoRedo: UndoRedo, name: String? = null, resetOnException: Boolean = true): StorePlugin<S, I, A>

Returns a plugin that manages the undoRedo provided.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> StoreBuilder<S, I, A>.whileSubscribed(name: String? = null, minSubscriptions: Int = 1, crossinline block: suspend PipelineContext<S, I, A>.() -> Unit)

Create and install a new whileSubscribed plugin. See the parent's function docs for more info.

Link copied to clipboard
inline fun <S : MVIState, I : MVIIntent, A : MVIAction> whileSubscribedPlugin(name: String? = null, minSubscriptions: Int = 1, crossinline block: suspend PipelineContext<S, I, A>.() -> Unit): StorePlugin<S, I, A>

Create a new plugin that invokes block each time the subscriber count reaches minSubscriptions. Nothing is invoked when more subscribers than minSubscriptions appear, however, the block will be invoked again if the subscriber count drops below minSubscriptions and then reaches the new value again. The block will be canceled when the subscription count drops below minSubscriptions.