AfterReducer

@available(*, deprecated, message: "Use `MiddlewareProtocol` instead of `Middleware`. It doesn't use `AfterReducer`. This struct will be removed on 1.0.")
public struct AfterReducer : Monoid

Wraps a closure that will be called after the Reducer pipeline has changed the state with the current action. With this structure, a middleware can schedule some callback to be executed with the new state, and evidently access this state to check what’s different. This can be very useful for Middlewares that perform logging, monitoring or telemetry, so you can check the state before and after reducers’ execution, or how much time it took for the whole chain to be called (in case this middleware is the first in the chain, of course). AfterReducer is a monoid, that means it can be combined with another AfterReducer to form a new one (that executes both operations in the reverse order) and an identity instance, that when combined with any other AfterReducer changes nothing in the result, acting as a neutral element in composition. The identity of an AfterReducer is the static instance doNothing(), that contains an empty closure for no-op. The combination between two AfterReducer instances occur in reverse order so the first middleware will have its “after reducer” closure executed last. This composition can be achieved by using the operator <>

  • The identity of an AfterReducer is the static instance doNothing(), that contains an empty closure for no-op. When combined with any other AfterReducer changes nothing in the result, acting as a neutral element in composition.

    Declaration

    Swift

    public static let identity: AfterReducer
  • Schedules some task to be executed right after Reducer chain has finished and new state is published

    Declaration

    Swift

    public static func `do`(_ run: @escaping () -> Void) -> AfterReducer
  • The identity of an AfterReducer is the static instance doNothing(), that contains an empty closure for no-op. When combined with any other AfterReducer changes nothing in the result, acting as a neutral element in composition.

    Declaration

    Swift

    public static func doNothing() -> AfterReducer
  • Undocumented

    Declaration

    Swift

    public func performBlock()