final class HistoryItemVisitor<Result> where Result : Sendableextension HistoryItemVisitor : SendableA visitor for history items.
Use this class to register handlers for specific event types and/or a default handler for history items. When a history item is visited, the visitor will find the matching handler and call it with the event payload and the history item.
-
The handler to be called when a history item is visited.
Declaration
Swift
typealias Handler = (HistoryItem) throws -> Result?Return Value
The result of the handling, or nil if the item should be ignored.
-
Initializes a new history item visitor.
Declaration
Swift
init() -
Registers a handler for a specific event type.
Declaration
Swift
func register<E>(_ eventType: E.Type, handler: @escaping (E, HistoryItem) throws -> Result?) where E : EventParameters
eventTypeThe type of event to register a handler for.
handlerThe handler to be called when a history item is visited.
-
Registers a default handler for history items.
This handler is used when a history item does not match any of the registered handlers.
This is useful for handling events that are not covered by the registered handlers.
Declaration
Swift
func registerDefault(_ handler: @escaping HistoryItemVisitor<Result>.Handler)Parameters
handlerThe handler to be called when a history item is visited.
-
Visits a single history item.
Throws
An error if the item cannot be visited.Declaration
Swift
func visit(_ item: HistoryItem) throws -> Result?Parameters
itemThe history item to be visited.
Return Value
The result of the visit.
-
Visits a sequence of history items.
Throws
An error if any of the items cannot be visited.Declaration
Swift
func collect(_ items: any Sequence<HistoryItem>) throws -> [Result]Parameters
itemsThe sequence of history items to be visited.
Return Value
The results of the visits, or an empty array if no results were returned.
-
Visits a sequence of history items.
Available when
ResultisVoid.Throws
An error if any of the items cannot be visited.Declaration
Swift
func visit(_ items: any Sequence<HistoryItem>) throwsParameters
itemsThe sequence of history items to be visited.