Files
pkurchatov 5814288fbb Added DivReporter.reportAction(context)
commit_hash:3822cd19b3496c951c913a2c4951c0d863103631
2026-01-26 12:54:24 +03:00

48 lines
1.5 KiB
Swift

import Foundation
import LayoutKit
/// The ``DivReporter`` protocol allows you to learn about actions and errors that occur in the
/// layout.
public protocol DivReporter {
func reportError(cardId: DivCardID, error: DivError)
func reportAction(cardId: DivCardID, info: DivActionInfo)
func reportAction(context: DivActionHandlingContext)
@_spi(Performance)
func reportViewWasCreated(cardId: DivCardID)
@_spi(Performance)
func reportBlockWillConfigure(path: UIElementPath)
@_spi(Performance)
func reportBlockDidConfigure(path: UIElementPath)
@_spi(Performance)
func reportViewWillLayout(path: UIElementPath)
@_spi(Performance)
func reportViewDidLayout(path: UIElementPath)
}
extension DivReporter {
public func reportViewWasCreated(cardId _: DivCardID) {}
public func reportBlockWillConfigure(path _: UIElementPath) {}
public func reportBlockDidConfigure(path _: UIElementPath) {}
public func reportViewWillLayout(path _: UIElementPath) {}
public func reportViewDidLayout(path _: UIElementPath) {}
public func reportAction(cardId _: DivCardID, info _: DivActionInfo) {}
public func reportAction(context: DivActionHandlingContext) {
reportAction(cardId: context.cardId, info: context.info)
}
func asExpressionErrorTracker(cardId: DivCardID) -> ExpressionErrorTracker {
{
reportError(
cardId: cardId,
error: DivExpressionError($0, path: UIElementPath(cardId.rawValue))
)
}
}
}
final class DefaultDivReporter: DivReporter {
func reportError(cardId _: DivCardID, error _: DivError) {}
}