AnyActionHandler

public struct AnyActionHandler<ActionType> : ActionHandler

ActionHandler defines a protocol for entities able to handle actions - defined by the associated type ActionType and AnyActionHandler erases this protocol to a generic struct type.

The only protocol requirement is a function that allows other entities to dispatch actions, so Views (or Presenters, ViewModels) in your UI layer, or even Middlewares can create actions of a certain type and send to your store, that is generalized by this protocol.

  • Erases the provided ActionHandler by using its inner methods from this wrapper

    Declaration

    Swift

    public init<A>(_ realHandler: A) where ActionType == A.ActionType, A : ActionHandler

    Parameters

    realHandler

    the concrete ActionHandler you’re erasing

  • Erases the any type that implements the dispatch function to act as a ActionHandler

    Declaration

    Swift

    public init(_ realHandler: @escaping (DispatchedAction<ActionType>) -> Void)

    Parameters

    realHandler

    a function with the same signature of ActionHandler.dispatch

  • The function that allows Views, ViewControllers, Presenters to dispatch actions to the store. Also way for a Middleware to trigger their own actions, usually in response to events or async operations.

    Declaration

    Swift

    public func dispatch(_ dispatchedAction: DispatchedAction<ActionType>)

    Parameters

    dispatchedAction

    struct holding the action (action to be dispatched) + dispatcher (information about the action source, containing file/line, function and additional information for debugging and logging purposes)