Skip to content

Commit 1b8799e

Browse files
committed
Add @GraphContentBuilder<NodeID> to graph content body
1 parent 962016a commit 1b8799e

14 files changed

+60
-42
lines changed

Sources/Grape/Contents/AnyGraphContent.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ public struct AnyGraphContent<NodeID: Hashable>: GraphContent {
99
self.storage = storage
1010
}
1111

12+
1213
@inlinable
1314
public var body: _IdentifiableNever<NodeID> {
14-
fatalError()
15+
_IdentifiableNever<_>()
1516
}
1617

1718
@inlinable

Sources/Grape/Contents/CompositedGraphContent.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

Sources/Grape/Contents/GraphContent.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public protocol GraphContent<NodeID> {
99
func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>)
1010

1111
@inlinable
12+
@GraphContentBuilder<NodeID>
1213
var body: Body { get }
1314
}
1415

Sources/Grape/Contents/LinkMark.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ public struct LinkMark<NodeID: Hashable>: GraphContent & Identifiable {
55

66
@inlinable
77
public var body: _IdentifiableNever<NodeID> {
8-
fatalError()
8+
_IdentifiableNever<_>()
99
}
10+
1011
// public enum LabelDisplayStrategy {
1112
// case auto
1213
// case specified(Bool)

Sources/Grape/Contents/ModifiedGraphContent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ extension ModifiedGraphContent: GraphContent {
5050
modifier._exit(&context)
5151
}
5252

53-
@inlinable
53+
54+
@inlinable
5455
public var body: _IdentifiableNever<NodeID> {
55-
fatalError()
56+
_IdentifiableNever<_>()
5657
}
5758
}

Sources/Grape/Contents/NodeMark.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ public struct NodeMark<NodeID: Hashable>: GraphContent, Identifiable, Equatable
1515

1616
@inlinable
1717
public var body: _IdentifiableNever<NodeID> {
18-
fatalError()
18+
_IdentifiableNever<_>()
1919
}
20-
20+
2121
@inlinable
2222
public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) {
2323
context.nodeOperations.append(

Sources/Grape/Contents/_ArrayGraphContent.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ where C: GraphContent {
1313
self.storage = storage
1414
}
1515

16+
1617
@inlinable
1718
public var body: _IdentifiableNever<NodeID> {
18-
fatalError()
19+
_IdentifiableNever<_>()
1920
}
2021

2122
@inlinable

Sources/Grape/Contents/_ConditionalGraphContent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ where C1: GraphContent, C2: GraphContent, C1.NodeID == C2.NodeID {
1818
self.storage = storage
1919
}
2020

21-
@inlinable
21+
22+
@inlinable
2223
public var body: _IdentifiableNever<NodeID> {
23-
fatalError()
24+
_IdentifiableNever<_>()
2425
}
2526

2627
@inlinable

Sources/Grape/Contents/_EmptyGraphContent.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
struct _EmptyGraphContent<NodeID: Hashable>: GraphContent {
33
@inlinable
44
public init() {
5-
5+
66
}
77
@inlinable
88
public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext<NodeID>) {
9-
9+
1010
}
1111

12-
@inlinable
12+
@inlinable
1313
public var body: _IdentifiableNever<NodeID> {
14-
fatalError()
14+
_IdentifiableNever<_>()
1515
}
16-
}
16+
}

Sources/Grape/Contents/_IdentifiableNever.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
public enum _IdentifiableNever<ID: Hashable> { }
1+
public enum _IdentifiableNever<ID: Hashable> {
2+
@usableFromInline
3+
internal init() {
4+
fatalError()
5+
}
6+
}
7+
8+
9+
@inlinable
10+
public func _fatalError<ID>(of identityType: ID) -> _IdentifiableNever<ID> where ID: Hashable {
11+
_IdentifiableNever<ID>()
12+
}
213

314
extension _IdentifiableNever: GraphContent {
415
public typealias NodeID = ID
516

617
@inlinable
718
public var body: Self {
8-
fatalError()
19+
_IdentifiableNever<ID>()
920
}
1021

1122
@inlinable

Sources/Grape/Contents/_OptionalGraphContent.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ where C: GraphContent {
2424
}
2525
}
2626

27-
@inlinable
27+
28+
@inlinable
2829
public var body: _IdentifiableNever<NodeID> {
29-
fatalError()
30+
_IdentifiableNever<_>()
3031
}
3132
}

Sources/Grape/Contents/_PairedGraphContent.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ where C1: GraphContent, C2: GraphContent, NodeID: Hashable, C1.NodeID == NodeID,
2121
}
2222

2323

24+
2425
@inlinable
2526
public var body: _IdentifiableNever<NodeID> {
26-
fatalError()
27+
_IdentifiableNever<_>()
2728
}
2829
}

Tests/GrapeTests/ContentBuilderTests.swift

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,31 @@ final class ContentBuilderTests: XCTestCase {
5050
}
5151

5252
func testForEach() {
53-
let _ = [
53+
let arr = [
5454
ID(id: 0),
5555
ID(id: 1),
5656
ID(id: 2),
5757
]
5858

59-
// let _ = buildGraph {
60-
// ForEach(data: arr) { i in
61-
// NodeMark(id: i.id)
62-
// }
63-
// }
59+
let _ = buildGraph {
60+
Series(arr) { i in
61+
NodeMark(id: i.id)
62+
}
63+
}
64+
}
65+
66+
func testComposing() {
67+
struct MyGraphContent: GraphContent {
68+
var body: some GraphContent<Int> {
69+
NodeMark(id: 1)
70+
AnnotationNodeMark(id: 3, radius: 4.0) {
71+
EmptyView()
72+
}
73+
}
74+
}
75+
76+
let _ = buildGraph {
77+
MyGraphContent()
78+
}
6479
}
6580
}

Tests/GrapeTests/GraphContentBuilderTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,7 @@ final class GraphContentBuilderTests: XCTestCase {
179179

180180
}
181181

182-
struct MyGraphComponent: GraphComponent {
183-
typealias NodeID = Int
182+
struct MyGraphComponent: GraphContent {
184183
var body: some GraphContent<Int> {
185184
NodeMark(id: 0)
186185
// .opacity(0.6)

0 commit comments

Comments
 (0)