ActionHandler
public protocol ActionHandler
ActionHandler
defines a protocol for entities able to handle actions - defined by the associated type ActionType
.
The only protocol requirement is a function that allows other entities to dispatch actions, so Views (or Presenters, ViewModels) in your UI layer, or even Middlewares can create actions of a certain type and send to your store, that is generalized by this protocol.
-
Undocumented
Declaration
Swift
associatedtype ActionType
-
The function that allows Views, ViewControllers, Presenters to dispatch actions to the store. Also way for a
Middleware
to trigger their own actions, usually in response to events or async operations.Declaration
Swift
func dispatch(_ dispatchedAction: DispatchedAction<ActionType>)
Parameters
dispatchedAction
container for action (the action to be dispatched) + dispatcher (information about the action source, containing file/line, function and additional information for debugging and logging purposes)/
-
eraseToAnyActionHandler()
Extension methodErases the provided
ActionHandler
by using its inner methods from a newly created wrapper of typeAnyActionHandler
Declaration
Swift
public func eraseToAnyActionHandler() -> AnyActionHandler<ActionType>
-
dispatch(_:
Extension methodfile: function: line: info: ) The function that allows Views, ViewControllers, Presenters to dispatch actions to the store. Also way for a
Middleware
to trigger their own actions, usually in response to events or async operations.Declaration
Swift
public func dispatch(_ action: ActionType, file: String = #file, function: String = #function, line: UInt = #line, info: String? = nil)
Parameters
action
the action to be dispatched
file
File that created and dispatched the action, by default this is the file calling the
dispatch
functionfunction
Function that created and dispatched the action, by default this is the function calling the
dispatch
functionline
Line in the file where the action was created and dispatched, by default this is the line from where the
dispatch
function was calledinfo
Additional information about the moment where the action was dispatched. This is an optional String that can hold information useful for debugging, logging, monitoring or analytics. By default this is nil but you can add any information useful to trace the journey of this action.
-
dispatch(_:
Extension methodfrom: ) The function that allows Views, ViewControllers, Presenters to dispatch actions to the store. Also way for a
Middleware
to trigger their own actions, usually in response to events or async operations.Declaration
Swift
public func dispatch(_ action: ActionType, from dispatcher: ActionSource)
Parameters
action
the action to be dispatched
dispatcher
information about the action source, containing file/line, function and additional information for debugging and logging purposes
-
contramap(_:
Extension method) Pullback an
ActionHandler
working in a local action context, into a newActionHandler
working in a more global action context.Declaration
Swift
public func contramap<NewActionType>(_ transform: @escaping (NewActionType) -> ActionType) -> AnyActionHandler<NewActionType>
Parameters
transform
a function that allows to go from a global action to a local action
Return Value
a new
ActionHandler
that knows how to handle the new action type