ComposedMiddleware

public struct ComposedMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol
extension ComposedMiddleware: Monoid

The ComposedMiddleware is a container of inner middlewares that are chained together in the order as they were composed. Whenever an EventProtocol or an ActionProtocol arrives to be handled by this ComposedMiddleware, it will delegate to its internal chain of middlewares.

It could be initialized manually by using the init() and configured by using the method append(middleware:), but if you’re ok with using custom operators you can compose two or more middlewares using the diamond operator:

let composedMiddleware = firstMiddleware <> secondMiddleware <> thirdMiddleware
  • Default initializer for ComposedMiddleware, use this only if you don’t like custom operators, otherwise create a ComposedMiddleware by composing two or more middlewares using the diamond operator, as shown below:

    let composedMiddleware = firstMiddleware <> secondMiddleware
    

    Declaration

    Swift

    public init()
  • Appends a new middleware to end of the composition (inner chain). Use this only if you don’t like custom operators, otherwise create a ComposedMiddleware append more middlewares to the composition by using the diamond operator, as shown below:

    let composedOfThreeMiddlewares = composedOfTwoMiddlewares <> thirdMiddleware
    

    Or

    let composedOfThreeMiddlewares = firstMiddleware <> secondMiddleware <> thirdMiddleware
    

    Declaration

    Swift

    public mutating func append<M: MiddlewareProtocol>(middleware: M)
        where M.InputActionType == InputActionType,
              M.OutputActionType == OutputActionType,
              M.StateType == StateType
  • Declaration

    Swift

    @available(*, deprecated, message: "Instead of relying on receiveContext, please use the getState from handle(action﹚ function,\nand when returning IO from the same handle(action﹚ function use the output from the closure")
    public func receiveContext(getState: @escaping () -> StateType, output: AnyActionHandler<OutputActionType>)
  • Handles the incoming actions. The ComposedMiddleware will forward each action to all its internal middlewares, in the order as they were composed together, and when all of them are done, the ActionType will be forwarded to the next middleware in the chain, or to the reducer pipeline in case this is the last middleware.

    The internal middlewares in this ComposedMiddleware container may trigger additional actions, as any middleware, and in this case the actions will be forwarded to the store by using the context property or the parent composed middleware object.

    Declaration

    Swift

    public func handle(action: InputActionType, from dispatcher: ActionSource, state: @escaping GetState<StateType>) -> IO<OutputActionType>

    Parameters

    action

    the action to be handled

    dispatcher

    information about the file, line and function that dispatched this action

    state

    a closure to obtain the most recent state

    Return Value

    possible Side-Effects wrapped in an IO struct

  • Undocumented

    Declaration

    Swift

    public func lift<GlobalInputActionType, GlobalOutputActionType, GlobalStateType>(
        inputAction inputActionMap: @escaping (GlobalInputActionType) -> InputActionType?,
        outputAction outputActionMap: @escaping (OutputActionType) -> GlobalOutputActionType,
        state stateMap: @escaping (GlobalStateType) -> StateType
    ) -> ComposedMiddleware<GlobalInputActionType, GlobalOutputActionType, GlobalStateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalOutputActionType, GlobalStateType>(
        outputAction outputActionMap: @escaping (OutputActionType) -> GlobalOutputActionType,
        state stateMap: @escaping (GlobalStateType) -> StateType
    ) -> ComposedMiddleware<InputActionType, GlobalOutputActionType, GlobalStateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalInputActionType, GlobalStateType>(
        inputAction inputActionMap: @escaping (GlobalInputActionType) -> InputActionType?,
        state stateMap: @escaping (GlobalStateType) -> StateType
    ) -> ComposedMiddleware<GlobalInputActionType, OutputActionType, GlobalStateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalInputActionType, GlobalOutputActionType>(
        inputAction inputActionMap: @escaping (GlobalInputActionType) -> InputActionType?,
        outputAction outputActionMap: @escaping (OutputActionType) -> GlobalOutputActionType
    ) -> ComposedMiddleware<GlobalInputActionType, GlobalOutputActionType, StateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalInputActionType>(
        inputAction inputActionMap: @escaping (GlobalInputActionType) -> InputActionType?
    ) -> ComposedMiddleware<GlobalInputActionType, OutputActionType, StateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalOutputActionType>(
        outputAction outputActionMap: @escaping (OutputActionType) -> GlobalOutputActionType
    ) -> ComposedMiddleware<InputActionType, GlobalOutputActionType, StateType>
  • Undocumented

    Declaration

    Swift

    public func lift<GlobalStateType>(
        state stateMap: @escaping (GlobalStateType) -> StateType
    ) -> ComposedMiddleware<InputActionType, OutputActionType, GlobalStateType>
  • Composed middleware identity is an empty composed middleware collection

    Declaration

    Swift

    public static var identity: ComposedMiddleware<InputActionType, OutputActionType, StateType> { get }