consumingDispatch
inline fun <T : Action> MiddlewareScope<*>.consumingDispatch(crossinline block: (T) -> Unit): DispatchFunction
Creates a dispatch function that consumes actions with given supertype T. Other actions are passed to the next middleware.
Example of usage:
sealed interface CustomAction : Action {
object A : CustomAction
object B : CustomAction
}
fun customMiddleware(): Middleware<AppState> = {
consumingDispatch<CustomAction> { action ->
when (action) { // this when is exhaustive!
CustomAction.A -> TODO()
CustomAction.B -> TODO()
}
}
}
Content copied to clipboard