Middleware

public protocol Middleware

Extends the store functionality by providing a middle layer between dispatched actions and the store’s reducer.

Before an action is given to a reducer, middleware have an opportunity to handle it themselves. They may dispatch their own actions, transform the current action, or block it entirely.

Middleware can also be used to set up external hooks from services.

  • Undocumented

    Declaration

    Swift

    associatedtype State
  • Perform any middleware actions within this function.

    Declaration

    Swift

    func run(store: StoreProxy<State>, action: Action) -> Action?

    Parameters

    store

    The store object. Use store.next when the middleware is complete.

    action

    The latest dispatched action to process.

    Return Value

    An optional action to pass to the next middleware.

  • compile(store:) Default implementation

    Compiles the middleware into a SendAction closure.

    Default Implementation

    Declaration

    Swift

    func compile(store: StoreProxy<State>) -> SendAction

    Parameters

    store

    A reference to the store used by the middleware.

    Return Value

    The SendAction that performs the middleware.

  • callAsFunction(store:) Extension method

    Apply the middleware to a store proxy.

    Declaration

    Swift

    @inlinable
    public func callAsFunction(store: StoreProxy<State>) -> SendAction

    Parameters

    store

    The store proxy.

    Return Value

    A SendAction function that performs the middleware for the provided store proxy.