Skip to content

Commit ee23a6c

Browse files
authored
expose ForEach internals for wasm rendering (#69)
1 parent 01a848a commit ee23a6c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
timeout-minutes: 15
1717
strategy:
1818
matrix:
19-
image: ["swift:5.10", "swift:6.0"]
19+
image: ["swift:5.10", "swift:6.0", "swift:6.1"]
2020

2121
container:
2222
image: ${{ matrix.image }}

Sources/Elementary/Core/ForEach.swift

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,37 @@
1111
public struct ForEach<Data, Content>: HTML
1212
where Data: Sequence, Content: HTML
1313
{
14-
@usableFromInline
15-
var sequence: Data
14+
public var _data: Data
1615
// TODO: Swift 6 - @Sendable is not ideal here, but currently the response generators for hummingbird/vapor require sendable HTML types
1716
// 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
2019

2120
/// Creates a new `ForEach` element with the given sequence and content builder closure.
2221
///
2322
/// - Parameters:
2423
/// - sequence: A sequence of data to render.
2524
/// - 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
2928
}
3029

3130
@inlinable @inline(__always)
3231
public static func _render<Renderer: _HTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) {
3332
context.assertNoAttributes(self)
3433

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)
3736
}
3837
}
3938

4039
@inlinable @inline(__always)
4140
public static func _render<Renderer: _AsyncHTMLRendering>(_ html: consuming Self, into renderer: inout Renderer, with context: consuming _RenderingContext) async throws {
4241
context.assertNoAttributes(self)
4342

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)
4645
}
4746
}
4847
}

0 commit comments

Comments
 (0)