Remove debug tree
This commit is contained in:
parent
0702207d22
commit
83a03441b5
@ -12,27 +12,6 @@ extension Array: AnyView where Element == AnyView {
|
||||
/// The array's view body is the array itself.
|
||||
public var viewContent: Body { self }
|
||||
|
||||
/// Get the debug tree for an array of views.
|
||||
/// - Parameter parameters: Whether the widget parameters should be visible in the tree.
|
||||
/// - Returns: The tree.
|
||||
public func getBodyDebugTree<WidgetType>(
|
||||
parameters: Bool,
|
||||
type: WidgetType.Type,
|
||||
modifiers: [(AnyView) -> AnyView] = []
|
||||
) -> String {
|
||||
let oldValue = StateManager.saveState
|
||||
StateManager.saveState = false
|
||||
var description = ""
|
||||
for view in self where view.renderable(type: type, modifiers: modifiers) {
|
||||
description += view.getDebugTree(parameters: parameters, type: type, modifiers: modifiers) + "\n"
|
||||
}
|
||||
if !description.isEmpty {
|
||||
description.removeLast()
|
||||
}
|
||||
StateManager.saveState = oldValue
|
||||
return description
|
||||
}
|
||||
|
||||
/// Get a widget from a collection of views.
|
||||
/// - Parameter modifiers: Modify views before being updated.
|
||||
/// - Returns: A widget.
|
||||
|
||||
@ -15,39 +15,6 @@ public protocol AnyView {
|
||||
|
||||
extension AnyView {
|
||||
|
||||
/// Get the view's debug tree.
|
||||
/// - Parameters:
|
||||
/// - parameters: Whether the widget parameters should be included in the debug tree.
|
||||
/// - type: The widget type.
|
||||
/// - modifiers: Modify the view before getting the debug tree.
|
||||
/// - Returns: A textual description.
|
||||
public func getDebugTree<WidgetType>(
|
||||
parameters: Bool,
|
||||
type: WidgetType.Type,
|
||||
modifiers: [(AnyView) -> AnyView] = []
|
||||
) -> String {
|
||||
let oldValue = StateManager.saveState
|
||||
StateManager.saveState = false
|
||||
defer {
|
||||
StateManager.saveState = oldValue
|
||||
}
|
||||
if let body = getModified(modifiers: modifiers) as? Body {
|
||||
return body.getBodyDebugTree(parameters: parameters, type: type, modifiers: modifiers)
|
||||
} else if let widget = getModified(modifiers: modifiers) as? Widget {
|
||||
return widget.getViewDescription(parameters: parameters, type: type, modifiers: modifiers)
|
||||
}
|
||||
let string = """
|
||||
\(Self.self) {
|
||||
\(indented: viewContent
|
||||
.map { view in
|
||||
view.getModified(modifiers: modifiers)
|
||||
}
|
||||
.getBodyDebugTree(parameters: parameters, type: type, modifiers: modifiers))
|
||||
}
|
||||
"""
|
||||
return string
|
||||
}
|
||||
|
||||
func getModified(modifiers: [(AnyView) -> AnyView]) -> AnyView {
|
||||
var modified: AnyView = self
|
||||
for modifier in modifiers {
|
||||
|
||||
@ -8,10 +8,6 @@
|
||||
/// A widget is a view that know about its GTUI widget.
|
||||
public protocol Widget: AnyView {
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] { get }
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] { get }
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
@ -37,38 +33,4 @@ extension Widget {
|
||||
/// A widget's view is empty.
|
||||
public var viewContent: Body { [] }
|
||||
|
||||
/// A description of the view.
|
||||
public func getViewDescription<WidgetType>(
|
||||
parameters: Bool,
|
||||
type: WidgetType.Type,
|
||||
modifiers: [(AnyView) -> AnyView]
|
||||
) -> String {
|
||||
let oldValue = StateManager.saveState
|
||||
StateManager.saveState = false
|
||||
defer {
|
||||
StateManager.saveState = oldValue
|
||||
}
|
||||
var content = ""
|
||||
for element in debugTreeContent {
|
||||
if content.isEmpty {
|
||||
content += """
|
||||
{
|
||||
\(indented: element.body.getDebugTree(parameters: parameters, type: type, modifiers: modifiers))
|
||||
}
|
||||
"""
|
||||
} else {
|
||||
content += """
|
||||
\(element.0): {
|
||||
\(indented: element.body.getDebugTree(parameters: parameters, type: type, modifiers: modifiers))
|
||||
}
|
||||
"""
|
||||
}
|
||||
}
|
||||
if parameters {
|
||||
let parametersString = debugTreeParameters.map { "\($0.0): \($0.value)" }.joined(separator: ", ")
|
||||
return "\(Self.self)(\(parametersString))\(content)"
|
||||
}
|
||||
return "\(Self.self)\(content)"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -13,18 +13,6 @@ struct AppearObserver: ConvenienceWidget {
|
||||
/// The wrapped view.
|
||||
var content: AnyView
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[
|
||||
("modify", value: "(ViewStorage) -> Void")
|
||||
]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: [content])]
|
||||
}
|
||||
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
|
||||
@ -13,16 +13,6 @@ struct ContentModifier<Content>: ConvenienceWidget where Content: AnyView {
|
||||
/// The closure for the modification.
|
||||
var modify: (Content) -> AnyView
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[("modify", value: "(Content) -> AnyView")]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: [content])]
|
||||
}
|
||||
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
|
||||
@ -13,18 +13,6 @@ struct Freeze: ConvenienceWidget {
|
||||
/// The wrapped view.
|
||||
var content: AnyView
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[
|
||||
("freeze", value: freeze)
|
||||
]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: [content])]
|
||||
}
|
||||
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
|
||||
@ -13,18 +13,6 @@ struct InspectorWrapper: ConvenienceWidget {
|
||||
/// The wrapped view.
|
||||
var content: AnyView
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[
|
||||
("modify", value: "(ViewStorage) -> Void")
|
||||
]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: [content])]
|
||||
}
|
||||
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
|
||||
@ -11,16 +11,6 @@ struct ModifierStopper: ConvenienceWidget {
|
||||
/// The wrapped view.
|
||||
var content: AnyView
|
||||
|
||||
/// The debug tree parameters.
|
||||
var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: [content])]
|
||||
}
|
||||
|
||||
/// The view storage.
|
||||
/// - Parameters:
|
||||
/// - modifiers: Modify views before being updated.
|
||||
|
||||
@ -15,18 +15,6 @@ public struct StateWrapper: ConvenienceWidget {
|
||||
/// The state information (from properties with the `State` wrapper).
|
||||
var state: [String: StateProtocol] = [:]
|
||||
|
||||
/// The debug tree parameters.
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[
|
||||
("state", value: state.map { $0.key.dropFirst() }.joined(separator: ", "))
|
||||
]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: content())]
|
||||
}
|
||||
|
||||
/// The identifier of the field storing whether to update the wrapper's content.
|
||||
private var updateID: String { "update" }
|
||||
|
||||
@ -96,7 +84,7 @@ public struct StateWrapper: ConvenienceWidget {
|
||||
@available(iOS, introduced: 17)
|
||||
func observe(storage: ViewStorage) {
|
||||
withObservationTracking {
|
||||
_ = content().getDebugTree(parameters: true, type: AnyView.self)
|
||||
_ = content()
|
||||
} onChange: {
|
||||
Task {
|
||||
StateManager.updateState(id: storage.state.first?.value.id ?? .init())
|
||||
|
||||
@ -11,16 +11,6 @@ public struct Wrapper: ConvenienceWidget {
|
||||
/// The content.
|
||||
var content: Body
|
||||
|
||||
/// The debug tree parameters.
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
/// The debug tree's content.
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[("content", body: content)]
|
||||
}
|
||||
|
||||
/// Initialize a `Wrapper`.
|
||||
/// - Parameter content: The view content.
|
||||
public init(@ViewBuilder content: @escaping () -> Body) {
|
||||
|
||||
@ -59,7 +59,6 @@ struct DemoApp {
|
||||
static func main() {
|
||||
let backendType = Backend1.BackendWidget.self
|
||||
|
||||
print(DemoView().getDebugTree(parameters: true, type: backendType, modifiers: []))
|
||||
let storage = DemoView().storage(modifiers: [], type: backendType)
|
||||
for round in 0...2 {
|
||||
print("#\(round)")
|
||||
|
||||
@ -6,14 +6,6 @@ public enum Backend1 {
|
||||
|
||||
public init() { }
|
||||
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public func container<WidgetType>(modifiers: [(AnyView) -> AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||
print("Init test widget 1")
|
||||
let storage = ViewStorage(nil)
|
||||
@ -32,14 +24,6 @@ public enum Backend1 {
|
||||
|
||||
public init() { }
|
||||
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public func container<WidgetType>(modifiers: [(AnyView) -> AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||
print("Init test widget 3")
|
||||
let storage = ViewStorage(nil)
|
||||
@ -64,15 +48,6 @@ public enum Backend1 {
|
||||
self.action = action
|
||||
}
|
||||
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public var debugTreeParameters: [(String, value: any CustomStringConvertible)] {
|
||||
_ = action
|
||||
return [("label", value: label), ("action", value: "() -> Void")]
|
||||
}
|
||||
|
||||
public func container<WidgetType>(modifiers: [(any AnyView) -> any AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||
print("Init button")
|
||||
Task {
|
||||
|
||||
@ -6,14 +6,6 @@ public enum Backend2 {
|
||||
|
||||
public init() { }
|
||||
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public func container<WidgetType>(modifiers: [(AnyView) -> AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||
print("Init test widget 2")
|
||||
let storage = ViewStorage(nil)
|
||||
@ -32,14 +24,6 @@ public enum Backend2 {
|
||||
|
||||
public init() { }
|
||||
|
||||
public var debugTreeContent: [(String, body: Body)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public var debugTreeParameters: [(String, value: CustomStringConvertible)] {
|
||||
[]
|
||||
}
|
||||
|
||||
public func container<WidgetType>(modifiers: [(AnyView) -> AnyView], type: WidgetType.Type) -> ViewStorage {
|
||||
print("Init test widget 4")
|
||||
let storage = ViewStorage(nil)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user