Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Protocol for common ReSwift middleware usecase
import ReSwift
public protocol MiddlewareProcessor {
typealias GetStateFunction = () -> Any?
func preprocess(dispatch: DispatchFunction, action: Action, getState: GetStateFunction)
func postprocess(dispatch: DispatchFunction, action: Action, getState: GetStateFunction)
}
public extension MiddlewareProcessor {
func preprocess(dispatch: DispatchFunction, action: Action, getState: GetStateFunction) {}
func postprocess(dispatch: DispatchFunction, action: Action, getState: GetStateFunction) {}
func middleware() -> Middleware<Any> {
return { dispatch, getState in
return { next in
return { action in
self.preprocess(dispatch: dispatch, action: action, getState: getState)
next(action)
self.postprocess(dispatch: dispatch, action: action, getState: getState)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment