Package-level declarations

Types

Link copied to clipboard

Type alias for a Redux middleware equivalent. The key difference is that dispatch, getState and next are provided by a MiddlewareScope.

Example of defining a middleware:

fun customMiddleware(): Middleware<AppState> = {
{ action ->
when (action) {
is CustomAction -> dispatch(OtherAction)
else -> next(action)
}
}
}
Link copied to clipboard

The scope that provides necessary operations for a middleware.

Functions

Link copied to clipboard
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.

Link copied to clipboard
inline fun <State, T : Action> consumingMiddleware(crossinline block: MiddlewareScope<State>.(T) -> Unit): Middleware<State>

Creates a middleware with consumingDispatch that consumes actions with given supertype T. Other actions are passed to the next middleware.

Link copied to clipboard

This function only returns given dispatch. It has a few benefits over simple DispatchFunction lambda that are illustrated with this example:

Link copied to clipboard
inline fun <State> middleware(crossinline block: MiddlewareScope<State>.(action: Action) -> Unit): Middleware<State>

Creates a middleware.

Link copied to clipboard

Creates a dispatch function that executes a given block and passes every action to the next middleware.

Link copied to clipboard
inline fun <T : Action> MiddlewareScope<*>.translucentDispatchOf(crossinline block: (T) -> Unit): DispatchFunction

Creates a dispatch function that executes a given block for every action with given supertype T and passes every action to the next middleware.

Link copied to clipboard
inline fun <State> translucentMiddleware(crossinline block: MiddlewareScope<State>.(Action) -> Unit): Middleware<State>

Creates a middleware with translucentDispatch that executes a given block and passes every action to the next middleware.