Skip to content

Commit

Permalink
Merge pull request #6 from SwiftRex/ActionFilter
Browse files Browse the repository at this point in the history
Action filter
  • Loading branch information
melle authored Mar 23, 2021
2 parents 6dfa59b + fb28f77 commit 133dcdc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/LoggerMiddleware/LoggerMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ extension Middleware where StateType: Equatable {
public func logger(
actionTransform: LoggerMiddleware<Self>.ActionTransform = .default(),
actionPrinter: LoggerMiddleware<Self>.ActionLogger = .osLog,
actionFilter: @escaping (InputActionType) -> Bool = { _ in true },
stateDiffTransform: LoggerMiddleware<Self>.StateDiffTransform = .diff(),
stateDiffPrinter: LoggerMiddleware<Self>.StateLogger = .osLog,
queue: DispatchQueue = .main
Expand All @@ -30,20 +31,23 @@ public final class LoggerMiddleware<M: Middleware>: Middleware where M.StateType
private var getState: GetState<StateType>?
private let actionTransform: ActionTransform
private let actionPrinter: ActionLogger
private let actionFilter: (InputActionType) -> Bool
private let stateDiffTransform: StateDiffTransform
private let stateDiffPrinter: StateLogger

init(
_ middleware: M,
actionTransform: ActionTransform,
actionPrinter: ActionLogger,
actionFilter: @escaping (InputActionType) -> Bool = { _ in true },
stateDiffTransform: StateDiffTransform,
stateDiffPrinter: StateLogger,
queue: DispatchQueue
) {
self.middleware = middleware
self.actionTransform = actionTransform
self.actionPrinter = actionPrinter
self.actionFilter = actionFilter
self.stateDiffTransform = stateDiffTransform
self.stateDiffPrinter = stateDiffPrinter
self.queue = queue
Expand All @@ -55,6 +59,7 @@ public final class LoggerMiddleware<M: Middleware>: Middleware where M.StateType
}

public func handle(action: InputActionType, from dispatcher: ActionSource, afterReducer: inout AfterReducer) {
guard actionFilter(action) else { return }
let stateBefore = getState?()
var innerAfterReducer = AfterReducer.doNothing()

Expand Down

0 comments on commit 133dcdc

Please sign in to comment.