diff --git a/Sources/Grape/Contents/AnyGraphContent.swift b/Sources/Grape/Contents/AnyGraphContent.swift index 6a56b30..3e6a5b4 100644 --- a/Sources/Grape/Contents/AnyGraphContent.swift +++ b/Sources/Grape/Contents/AnyGraphContent.swift @@ -9,9 +9,10 @@ public struct AnyGraphContent: GraphContent { self.storage = storage } + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } @inlinable diff --git a/Sources/Grape/Contents/CompositedGraphContent.swift b/Sources/Grape/Contents/CompositedGraphContent.swift deleted file mode 100644 index 0209d21..0000000 --- a/Sources/Grape/Contents/CompositedGraphContent.swift +++ /dev/null @@ -1,15 +0,0 @@ -public protocol GraphComponent: GraphContent where Body: GraphContent { - - @inlinable - @GraphContentBuilder - var body: Body { get } -} - -extension GraphComponent { - - @inlinable - public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext) - { - body._attachToGraphRenderingContext(&context) - } -} diff --git a/Sources/Grape/Contents/GraphContent.swift b/Sources/Grape/Contents/GraphContent.swift index e2ab945..90e789b 100644 --- a/Sources/Grape/Contents/GraphContent.swift +++ b/Sources/Grape/Contents/GraphContent.swift @@ -9,6 +9,7 @@ public protocol GraphContent { func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext) @inlinable + @GraphContentBuilder var body: Body { get } } diff --git a/Sources/Grape/Contents/LinkMark.swift b/Sources/Grape/Contents/LinkMark.swift index af9aeda..f76f0db 100644 --- a/Sources/Grape/Contents/LinkMark.swift +++ b/Sources/Grape/Contents/LinkMark.swift @@ -5,8 +5,9 @@ public struct LinkMark: GraphContent & Identifiable { @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } + // public enum LabelDisplayStrategy { // case auto // case specified(Bool) diff --git a/Sources/Grape/Contents/ModifiedGraphContent.swift b/Sources/Grape/Contents/ModifiedGraphContent.swift index ab89931..5b970c3 100644 --- a/Sources/Grape/Contents/ModifiedGraphContent.swift +++ b/Sources/Grape/Contents/ModifiedGraphContent.swift @@ -50,8 +50,9 @@ extension ModifiedGraphContent: GraphContent { modifier._exit(&context) } - @inlinable + + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } } diff --git a/Sources/Grape/Contents/NodeMark.swift b/Sources/Grape/Contents/NodeMark.swift index b0f75f7..633e95a 100644 --- a/Sources/Grape/Contents/NodeMark.swift +++ b/Sources/Grape/Contents/NodeMark.swift @@ -15,9 +15,9 @@ public struct NodeMark: GraphContent, Identifiable, Equatable @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } - + @inlinable public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext) { context.nodeOperations.append( diff --git a/Sources/Grape/Contents/_ArrayGraphContent.swift b/Sources/Grape/Contents/_ArrayGraphContent.swift index bf18f8a..f4ef2a3 100644 --- a/Sources/Grape/Contents/_ArrayGraphContent.swift +++ b/Sources/Grape/Contents/_ArrayGraphContent.swift @@ -13,9 +13,10 @@ where C: GraphContent { self.storage = storage } + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } @inlinable diff --git a/Sources/Grape/Contents/_ConditionalGraphContent.swift b/Sources/Grape/Contents/_ConditionalGraphContent.swift index 487cb84..9dfa8f4 100644 --- a/Sources/Grape/Contents/_ConditionalGraphContent.swift +++ b/Sources/Grape/Contents/_ConditionalGraphContent.swift @@ -18,9 +18,10 @@ where C1: GraphContent, C2: GraphContent, C1.NodeID == C2.NodeID { self.storage = storage } - @inlinable + + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } @inlinable diff --git a/Sources/Grape/Contents/_EmptyGraphContent.swift b/Sources/Grape/Contents/_EmptyGraphContent.swift index 4fd35ab..3dfca86 100644 --- a/Sources/Grape/Contents/_EmptyGraphContent.swift +++ b/Sources/Grape/Contents/_EmptyGraphContent.swift @@ -2,15 +2,15 @@ struct _EmptyGraphContent: GraphContent { @inlinable public init() { - + } @inlinable public func _attachToGraphRenderingContext(_ context: inout _GraphRenderingContext) { - + } - @inlinable + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } -} \ No newline at end of file +} diff --git a/Sources/Grape/Contents/_IdentifiableNever.swift b/Sources/Grape/Contents/_IdentifiableNever.swift index 5d7ec00..5d89d2f 100644 --- a/Sources/Grape/Contents/_IdentifiableNever.swift +++ b/Sources/Grape/Contents/_IdentifiableNever.swift @@ -1,11 +1,22 @@ -public enum _IdentifiableNever { } +public enum _IdentifiableNever { + @usableFromInline + internal init() { + fatalError() + } +} + + +@inlinable +public func _fatalError(of identityType: ID) -> _IdentifiableNever where ID: Hashable { + _IdentifiableNever() +} extension _IdentifiableNever: GraphContent { public typealias NodeID = ID @inlinable public var body: Self { - fatalError() + _IdentifiableNever() } @inlinable diff --git a/Sources/Grape/Contents/_OptionalGraphContent.swift b/Sources/Grape/Contents/_OptionalGraphContent.swift index d62bfcc..0ee6bd2 100644 --- a/Sources/Grape/Contents/_OptionalGraphContent.swift +++ b/Sources/Grape/Contents/_OptionalGraphContent.swift @@ -24,8 +24,9 @@ where C: GraphContent { } } - @inlinable + + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } } \ No newline at end of file diff --git a/Sources/Grape/Contents/_PairedGraphContent.swift b/Sources/Grape/Contents/_PairedGraphContent.swift index 303be68..167ca6f 100644 --- a/Sources/Grape/Contents/_PairedGraphContent.swift +++ b/Sources/Grape/Contents/_PairedGraphContent.swift @@ -21,8 +21,9 @@ where C1: GraphContent, C2: GraphContent, NodeID: Hashable, C1.NodeID == NodeID, } + @inlinable public var body: _IdentifiableNever { - fatalError() + _IdentifiableNever<_>() } } diff --git a/Tests/GrapeTests/ContentBuilderTests.swift b/Tests/GrapeTests/ContentBuilderTests.swift index 0020cea..03185fc 100644 --- a/Tests/GrapeTests/ContentBuilderTests.swift +++ b/Tests/GrapeTests/ContentBuilderTests.swift @@ -50,16 +50,31 @@ final class ContentBuilderTests: XCTestCase { } func testForEach() { - let _ = [ + let arr = [ ID(id: 0), ID(id: 1), ID(id: 2), ] - // let _ = buildGraph { - // ForEach(data: arr) { i in - // NodeMark(id: i.id) - // } - // } + let _ = buildGraph { + Series(arr) { i in + NodeMark(id: i.id) + } + } + } + + func testComposing() { + struct MyGraphContent: GraphContent { + var body: some GraphContent { + NodeMark(id: 1) + AnnotationNodeMark(id: 3, radius: 4.0) { + EmptyView() + } + } + } + + let _ = buildGraph { + MyGraphContent() + } } } \ No newline at end of file diff --git a/Tests/GrapeTests/GraphContentBuilderTests.swift b/Tests/GrapeTests/GraphContentBuilderTests.swift index 22c9a32..8cd30a2 100644 --- a/Tests/GrapeTests/GraphContentBuilderTests.swift +++ b/Tests/GrapeTests/GraphContentBuilderTests.swift @@ -179,8 +179,7 @@ final class GraphContentBuilderTests: XCTestCase { } - struct MyGraphComponent: GraphComponent { - typealias NodeID = Int + struct MyGraphComponent: GraphContent { var body: some GraphContent { NodeMark(id: 0) // .opacity(0.6)