From 45fe66b8ce695313d3d61c96dd66c38daab75f70 Mon Sep 17 00:00:00 2001 From: Luiz Rodrigo Martins Barbosa Date: Tue, 23 Nov 2021 14:14:26 +0100 Subject: [PATCH] Update SwiftRex to use Middleware IO --- Package.resolved | 4 ++-- Package.swift | 2 +- .../BridgeMiddleware/BridgeMiddleware.swift | 22 +++++-------------- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/Package.resolved b/Package.resolved index a6cadc4..33f3937 100644 --- a/Package.resolved +++ b/Package.resolved @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/SwiftRex/SwiftRex.git", "state": { "branch": null, - "revision": "660ba8ec5a79bc30f152955f9d8ea0b69ba6b466", - "version": "0.8.6" + "revision": "c51328031f943d8f055dbcb738bc66915825b8cc", + "version": "0.8.8" } } ] diff --git a/Package.swift b/Package.swift index 82ef533..8492dfe 100644 --- a/Package.swift +++ b/Package.swift @@ -10,7 +10,7 @@ let package = Package( .library(name: "BridgeMiddlewareReactiveSwift", targets: ["BridgeMiddlewareReactiveSwift"]) ], dependencies: [ - .package(url: "https://github.com/SwiftRex/SwiftRex.git", from: "0.8.6") + .package(url: "https://github.com/SwiftRex/SwiftRex.git", from: "0.8.8") ], targets: [ .target(name: "BridgeMiddlewareCombine", dependencies: [.product(name: "CombineRex", package: "SwiftRex")]), diff --git a/Sources/BridgeMiddleware/BridgeMiddleware.swift b/Sources/BridgeMiddleware/BridgeMiddleware.swift index 6304d36..017c668 100644 --- a/Sources/BridgeMiddleware/BridgeMiddleware.swift +++ b/Sources/BridgeMiddleware/BridgeMiddleware.swift @@ -77,7 +77,7 @@ public func >=> (_ left: @escaping (A) -> B?, _ right: @escaping (B) -> } } -public class BridgeMiddleware: Middleware { +public class BridgeMiddleware: MiddlewareProtocol { struct Bridge { let actionTransformation: (InputActionType) -> OutputActionType? let statePredicate: (GetState, InputActionType) -> Bool @@ -181,23 +181,12 @@ public class BridgeMiddleware: Mid bridge(keyPathChecker >=> (ignore >>> outputAction), when: stateAfterReducerPredicate, file: file, line: line, function: function) } - private var getState: GetState? - private var output: AnyActionHandler? - - public func receiveContext(getState: @escaping GetState, output: AnyActionHandler) { - self.getState = getState - self.output = output - } - - public func handle(action: InputActionType, from dispatcher: ActionSource, afterReducer: inout AfterReducer) { - afterReducer = .do { [weak self] in - guard let self = self, - let output = self.output, - let getState = self.getState - else { return } + public func handle(action: InputActionType, from dispatcher: ActionSource, state: @escaping GetState) -> IO { + IO { [weak self] output in + guard let self = self else { return } self.bridges - .filter { actionBridge in actionBridge.statePredicate(getState, action) } + .filter { actionBridge in actionBridge.statePredicate(state, action) } .compactMap { actionBridge in actionBridge .actionTransformation(action) @@ -219,6 +208,7 @@ public class BridgeMiddleware: Mid ) ) } + } } }