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

commonMain.pro.respawn.flowmvi.plugins.RecoverPlugin.kt Maven / Gradle / Ivy

Go to download

A Kotlin Multiplatform MVI library based on plugins that is simple, fast, powerful & flexible

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

import pro.respawn.flowmvi.api.FlowMVIDSL
import pro.respawn.flowmvi.api.MVIAction
import pro.respawn.flowmvi.api.MVIIntent
import pro.respawn.flowmvi.api.MVIState
import pro.respawn.flowmvi.api.PipelineContext
import pro.respawn.flowmvi.api.StorePlugin
import pro.respawn.flowmvi.dsl.StoreBuilder
import pro.respawn.flowmvi.dsl.plugin

public typealias Recover = suspend PipelineContext.(e: Exception) -> Exception?

/**
 * Create and install a [recoverPlugin].
 */
@FlowMVIDSL
public fun  StoreBuilder.recover(
    name: String? = null,
    recover: Recover,
): Unit = install(recoverPlugin(name, recover))

/**
 * Create a plugin that simply invokes [StorePlugin.onException] and decides how to proceed accordingly.
 * See the parent function for more information.
 */
@FlowMVIDSL
public fun  recoverPlugin(
    name: String? = null,
    recover: Recover
): StorePlugin = plugin {
    this.name = name
    onException(recover)
}