BlockMiddleware
public final class BlockMiddleware: Middleware
Create a middleware inline with a block.
Example
let middleware = BlockMiddleware { action, getState, dispatch, next in
// Read the state before any reducer changes it
print("The old state is \(getState())")
// Print the action
print("The action is \(action)")
// Continue the dispatching process..until the reducer reduces the action
// Not calling `next` will prevent the action from reaching the reducer
next?(action)
// Read the state after any reducer changes it
print("The new state is \(api?.state)")
}
-
Create a middleware with an onAction callback block
Declaration
Swift
public init(actionFunction: @escaping MiddlewareFunction)
Parameters
actionFunction
block to be called with the action, a function to get the sate, a function to dispatch, and the next action callback.
-
Declaration
Swift
public func onAction(action: Action, getState: @escaping GetStateFunction, dispatch: @escaping DispatchFunction, next: @escaping NextFunction)
Parameters
action