LoggerMiddleware
public struct LoggerMiddleware: Middleware
LoggerMiddleware that logs the action and state when each action is received When an action is dispatched, the LoggerMiddleware will print information related to it in the console.
Example
Adding LoggerMiddleware
let store = Suas.createStore(
reducer: ...,
middleware: LoggerMiddleware()
)
When actions are dispatched, you get something similar to this printed to the console.
┌───→ Action: IncrementAction @19:15:39.419
├─ Prev state ► State(innerState: ["Counter": CounterExample.Counter(value: 0)])
├─ Action ► IncrementAction(incrementValue: 1)
├─ Next state ► State(innerState: ["Counter": CounterExample.Counter(value: 1)])
└──────────────────────────────────────────
-
init(showTimestamp:showDuration:lineLength:predicate:debugOnly:titleFormatter:stateTransformer:actionTransformer:logger:)Create a LoggerMiddleware
Declaration
Swift
public init( showTimestamp: Bool = true, showDuration: Bool = false, lineLength: Int? = nil, predicate: ((State, Action) -> Bool)? = nil, debugOnly: Bool = true, titleFormatter: ((Action, Date, UInt64) -> String)? = nil, stateTransformer: ((State) -> Any)? = nil, actionTransformer: ((Action) -> Any)? = nil, logger: @escaping (String) -> Void = defaultLogger )Parameters
showTimestampshow or hide the timestamp when receiving the action (optional, defaults to true)
showDurationshow or hide the duration of reducing the action (optional, defaults to false)
lineLengthspecifies the maximum length of the printed lines (optional no max length)
predicatecallback that decides if the logger should print or not (optional, defaults always print)
debugOnlyprint the debug message in Debug only or Debug and Release configurations (optional, defaults print in debug only configuration)
titleFormattercallback that defines the format of the log title (optional)
stateTransformercallback that allow converting the state to a differnt type before printing it (optional)
actionTransformercallback that allow converting the action to a differnt type before printing it (optional)
loggercallback that receives the final string to print to console (optional, print to console)
-
Declaration
Swift
public func onAction(action: Action, getState: @escaping GetStateFunction, dispatch: @escaping DispatchFunction, next: @escaping NextFunction)Parameters
action
View on GitHub
LoggerMiddleware Struct Reference