|
11 | 11 | public struct ForEach<Data, Content>: HTML |
12 | 12 | where Data: Sequence, Content: HTML |
13 | 13 | { |
14 | | - @usableFromInline |
15 | | - var sequence: Data |
| 14 | + public var _data: Data |
16 | 15 | // TODO: Swift 6 - @Sendable is not ideal here, but currently the response generators for hummingbird/vapor require sendable HTML types |
17 | 16 | // also, currently there is no good way to conditionally apply Sendable conformance based on closure type |
18 | | - @usableFromInline |
19 | | - var contentBuilder: @Sendable (Data.Element) -> Content |
| 17 | + |
| 18 | + public var _contentBuilder: @Sendable (Data.Element) -> Content |
20 | 19 |
|
21 | 20 | /// Creates a new `ForEach` element with the given sequence and content builder closure. |
22 | 21 | /// |
23 | 22 | /// - Parameters: |
24 | 23 | /// - sequence: A sequence of data to render. |
25 | 24 | /// - contentBuilder: A closure that builds the HTML content for each element in the sequence. |
26 | | - public init(_ sequence: Data, @HTMLBuilder content contentBuilder: @escaping @Sendable (Data.Element) -> Content) { |
27 | | - self.sequence = sequence |
28 | | - self.contentBuilder = contentBuilder |
| 25 | + public init(_ data: Data, @HTMLBuilder content contentBuilder: @escaping @Sendable (Data.Element) -> Content) { |
| 26 | + _data = data |
| 27 | + _contentBuilder = contentBuilder |
29 | 28 | } |
30 | 29 |
|
31 | 30 | @inlinable @inline(__always) |
32 | 31 | public static func _render<Renderer: _HTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) { |
33 | 32 | context.assertNoAttributes(self) |
34 | 33 |
|
35 | | - for element in html.sequence { |
36 | | - Content._render(html.contentBuilder(element), into: &renderer, with: copy context) |
| 34 | + for element in html._data { |
| 35 | + Content._render(html._contentBuilder(element), into: &renderer, with: copy context) |
37 | 36 | } |
38 | 37 | } |
39 | 38 |
|
40 | 39 | @inlinable @inline(__always) |
41 | 40 | public static func _render<Renderer: _AsyncHTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) async throws { |
42 | 41 | context.assertNoAttributes(self) |
43 | 42 |
|
44 | | - for element in html.sequence { |
45 | | - try await Content._render(html.contentBuilder(element), into: &renderer, with: copy context) |
| 43 | + for element in html._data { |
| 44 | + try await Content._render(html._contentBuilder(element), into: &renderer, with: copy context) |
46 | 45 | } |
47 | 46 | } |
48 | 47 | } |
|
0 commit comments