|
1 | 1 | import SwiftUI
|
2 | 2 |
|
3 | 3 | @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
|
| 4 | +@MainActor |
4 | 5 | final class LogStore: ObservableObject {
|
5 | 6 | @Published var log: [LogEntry]
|
6 | 7 | var viewLabels: Set<String> = []
|
@@ -34,49 +35,47 @@ final class LogStore: ObservableObject {
|
34 | 35 | }
|
35 | 36 |
|
36 | 37 | func logLayoutStep(_ label: String, step: LogEntry.Step) {
|
37 |
| - DispatchQueue.main.async { [self] in |
38 |
| - guard let prevEntry = log.last else { |
39 |
| - // First log entry → start at indent 0. |
40 |
| - log.append(LogEntry(label: label, step: step, indent: 0)) |
41 |
| - return |
42 |
| - } |
| 38 | + guard let prevEntry = log.last else { |
| 39 | + // First log entry → start at indent 0. |
| 40 | + log.append(LogEntry(label: label, step: step, indent: 0)) |
| 41 | + return |
| 42 | + } |
43 | 43 |
|
44 |
| - var newEntry = LogEntry(label: label, step: step, indent: prevEntry.indent) |
45 |
| - let isSameView = prevEntry.label == label |
46 |
| - switch (isSameView, prevEntry.step, step) { |
47 |
| - case (true, .proposal(let prop), .response(let resp)): |
48 |
| - // Response follows immediately after proposal for the same view. |
49 |
| - // → We want to display them in a single row. |
50 |
| - // → Coalesce both layout steps. |
51 |
| - log.removeLast() |
52 |
| - newEntry = prevEntry |
53 |
| - newEntry.step = .proposalAndResponse(proposal: prop, response: resp) |
54 |
| - log.append(newEntry) |
| 44 | + var newEntry = LogEntry(label: label, step: step, indent: prevEntry.indent) |
| 45 | + let isSameView = prevEntry.label == label |
| 46 | + switch (isSameView, prevEntry.step, step) { |
| 47 | + case (true, .proposal(let prop), .response(let resp)): |
| 48 | + // Response follows immediately after proposal for the same view. |
| 49 | + // → We want to display them in a single row. |
| 50 | + // → Coalesce both layout steps. |
| 51 | + log.removeLast() |
| 52 | + newEntry = prevEntry |
| 53 | + newEntry.step = .proposalAndResponse(proposal: prop, response: resp) |
| 54 | + log.append(newEntry) |
55 | 55 |
|
56 |
| - case (_, .proposal, .proposal): |
57 |
| - // A proposal follows a proposal → nested view → increment indent. |
58 |
| - newEntry.indent += 1 |
59 |
| - log.append(newEntry) |
| 56 | + case (_, .proposal, .proposal): |
| 57 | + // A proposal follows a proposal → nested view → increment indent. |
| 58 | + newEntry.indent += 1 |
| 59 | + log.append(newEntry) |
60 | 60 |
|
61 |
| - case (_, .response, .response), |
62 |
| - (_, .proposalAndResponse, .response): |
63 |
| - // A response follows a response → last child returns to parent → decrement indent. |
64 |
| - newEntry.indent -= 1 |
65 |
| - log.append(newEntry) |
| 61 | + case (_, .response, .response), |
| 62 | + (_, .proposalAndResponse, .response): |
| 63 | + // A response follows a response → last child returns to parent → decrement indent. |
| 64 | + newEntry.indent -= 1 |
| 65 | + log.append(newEntry) |
66 | 66 |
|
67 |
| - default: |
68 |
| - // Keep current indentation. |
69 |
| - log.append(newEntry) |
70 |
| - } |
| 67 | + default: |
| 68 | + // Keep current indentation. |
| 69 | + log.append(newEntry) |
71 | 70 | }
|
72 | 71 | }
|
73 | 72 | }
|
74 | 73 |
|
75 | 74 | @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
|
76 | 75 | struct DebugLayoutActions {
|
77 |
| - var clearLog: () -> Void |
78 |
| - var registerViewLabelAndWarnIfNotUnique: (_ label: String, _ file: StaticString, _ line: UInt) -> Void |
79 |
| - var logLayoutStep: (_ label: String, _ step: LogEntry.Step) -> Void |
| 76 | + var clearLog: @MainActor () -> Void |
| 77 | + var registerViewLabelAndWarnIfNotUnique: @MainActor (_ label: String, _ file: StaticString, _ line: UInt) -> Void |
| 78 | + var logLayoutStep: @MainActor (_ label: String, _ step: LogEntry.Step) -> Void |
80 | 79 | }
|
81 | 80 |
|
82 | 81 | @available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
|
|
0 commit comments