IdentityMiddleware

public struct IdentityMiddleware<InputActionType, OutputActionType, StateType> : MiddlewareProtocol, Equatable

The IdentityMiddleware won’t do any operation, simply bypass actions through. It’s meant to provide identity axiom to middleware type to allow its conformance to monoid algebra. It will simply forward actions to the next middleware in the chain or to the reducers. It can be useful for Unit Tests or for some compositions.

  • Default initializer for IdentityMiddleware

    Declaration

    Swift

    public init()
  • 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>)
  • Undocumented

    Declaration

    Swift

    public func handle(action: InputActionType, from dispatcher: ActionSource, afterReducer: inout AfterReducer)
  • Handles the incoming actions and may or not start async tasks, check the latest state at any point or dispatch additional actions. This is also a good place for analytics, tracking, logging and telemetry. In this empty implementation, will do nothing but call next delegate.

    Declaration

    Swift

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

    Parameters

    action

    the action to be handled

    next

    opportunity to call the next middleware in the chain and, eventually, the reducer pipeline. Call it only once, not more or less than once. Call it from the same thread and runloop where the handle function is executed, never from a completion handler or dispatch queue block. In case you don’t need to compare state before and after it’s changed from the reducers, please consider to add a defer block with next() on it, at the beginning of handle function.

  • Undocumented

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

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

    Declaration

    Swift

    public func lift<GlobalStateType>(
        state: @escaping (GlobalStateType) -> StateType
    ) -> IdentityMiddleware<InputActionType, OutputActionType, GlobalStateType>