Skip to content

Commit

Permalink
Merge pull request #3 from SwiftRex/MiddlewareIO
Browse files Browse the repository at this point in the history
Update SwiftRex to use Middleware IO
  • Loading branch information
luizmb authored Nov 30, 2021
2 parents dafb6a2 + 45fe66b commit 1637b09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")]),
Expand Down
22 changes: 6 additions & 16 deletions Sources/BridgeMiddleware/BridgeMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public func >=> <A, B, C>(_ left: @escaping (A) -> B?, _ right: @escaping (B) ->
}
}

public class BridgeMiddleware<InputActionType, OutputActionType, StateType>: Middleware {
public class BridgeMiddleware<InputActionType, OutputActionType, StateType>: MiddlewareProtocol {
struct Bridge {
let actionTransformation: (InputActionType) -> OutputActionType?
let statePredicate: (GetState<StateType>, InputActionType) -> Bool
Expand Down Expand Up @@ -181,23 +181,12 @@ public class BridgeMiddleware<InputActionType, OutputActionType, StateType>: Mid
bridge(keyPathChecker >=> (ignore >>> outputAction), when: stateAfterReducerPredicate, file: file, line: line, function: function)
}

private var getState: GetState<StateType>?
private var output: AnyActionHandler<OutputActionType>?

public func receiveContext(getState: @escaping GetState<StateType>, output: AnyActionHandler<OutputActionType>) {
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<StateType>) -> IO<OutputActionType> {
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)
Expand All @@ -219,6 +208,7 @@ public class BridgeMiddleware<InputActionType, OutputActionType, StateType>: Mid
)
)
}

}
}
}

0 comments on commit 1637b09

Please sign in to comment.