Skip to content

Commit c35d25e

Browse files
committed
renamed AsyncHTML to AsyncContent
1 parent 03d86a0 commit c35d25e

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

Sources/Elementary/Core/AsyncHTML.swift renamed to Sources/Elementary/Core/AsyncContent.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///
33
/// The this element can only be rendered in an async context (ie: by calling ``HTML/render(into:chunkSize:)`` or ``HTML/renderAsync()``).
44
/// All HTML tag types (``HTMLElement``) support async content closures in their initializers, so you don't need to use this element directly in most cases.
5-
public struct AsyncHTML<Content: HTML>: HTML, Sendable {
5+
public struct AsyncContent<Content: HTML>: HTML, Sendable {
66
var content: @Sendable () async throws -> Content
77
public typealias Tag = Content.Tag
88

@@ -12,7 +12,7 @@ public struct AsyncHTML<Content: HTML>: HTML, Sendable {
1212
/// - content: The future content of the element.
1313
///
1414
/// ```swift
15-
/// AsyncHTML {
15+
/// AsyncContent {
1616
/// let value = await fetchValue()
1717
/// "Waiting for "
1818
/// span { value }
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
public extension HTMLElement {
22
/// Creates a new HTML element with the specified tag and async content.
33
///
4-
/// The async content closure is automatically wrapped in an ``AsyncHTML`` element and can only be rendered in an async context.
4+
/// The async content closure is automatically wrapped in an ``AsyncContent`` element and can only be rendered in an async context.
55
///
66
/// - Parameters:
77
/// - attributes: The attributes to apply to the element.
88
/// - content: The future content of the element.
99
init<AwaitedContent: HTML>(_ attributes: HTMLAttribute<Tag>..., @HTMLBuilder content: @escaping @Sendable () async throws -> AwaitedContent)
10-
where Self.Content == AsyncHTML<AwaitedContent>
10+
where Self.Content == AsyncContent<AwaitedContent>
1111
{
1212
self.attributes = .init(attributes)
13-
self.content = AsyncHTML(content: content)
13+
self.content = AsyncContent(content: content)
1414
}
1515

1616
/// Creates a new HTML element with the specified tag and async content.
1717
///
18-
/// The async content closure is automatically wrapped in an ``AsyncHTML`` element and can only be rendered in an async context.
18+
/// The async content closure is automatically wrapped in an ``AsyncContent`` element and can only be rendered in an async context.
1919
///
2020
/// - Parameters:
2121
/// - attributes: The attributes to apply to the element.
2222
/// - content: The future content of the element.
2323
init<AwaitedContent: HTML>(attributes: [HTMLAttribute<Tag>], @HTMLBuilder content: @escaping @Sendable () async throws -> AwaitedContent)
24-
where Self.Content == AsyncHTML<AwaitedContent>
24+
where Self.Content == AsyncContent<AwaitedContent>
2525
{
2626
self.attributes = .init(attributes)
27-
self.content = AsyncHTML(content: content)
27+
self.content = AsyncContent(content: content)
2828
}
2929
}

Tests/ElementaryTests/AsyncRenderingTests.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import Elementary
22
import XCTest
33

44
final class AsyncRenderingTests: XCTestCase {
5-
func testRendersAwaitedHTML() async throws {
5+
func testRendersAsyncContent() async throws {
66
try await HTMLAssertEqualAsyncOnly(
7-
p {
8-
AsyncHTML {
9-
let text = await getValue()
10-
"Waiting for "
11-
span { text }
12-
}
7+
AsyncContent {
8+
let text = await getValue()
9+
"Waiting for "
10+
span { text }
1311
},
14-
"<p>Waiting for <span>late response</span></p>"
12+
"Waiting for <span>late response</span>"
1513
)
1614
}
1715

@@ -26,7 +24,7 @@ final class AsyncRenderingTests: XCTestCase {
2624
)
2725
}
2826

29-
func testImplicitAsyncContent() async throws {
27+
func testImplicitlyAsyncContent() async throws {
3028
try await HTMLAssertEqualAsyncOnly(
3129
p(.id("hello")) {
3230
let text = await getValue()
@@ -39,23 +37,23 @@ final class AsyncRenderingTests: XCTestCase {
3937
func testNestedImplicitAsyncContent() async throws {
4038
try await HTMLAssertEqualAsyncOnly(
4139
div(attributes: [.class("c1")]) {
42-
await getValue()
4340
p {
44-
"again \(await getValue())"
41+
await getValue()
4542
}
43+
"again \(await getValue())"
4644
p(.class("c2")) {
4745
"and again \(await getValue())"
4846
}
4947
},
50-
#"<div class="c1">late response<p>again late response</p><p class="c2">and again late response</p></div>"#
48+
#"<div class="c1"><p>late response</p>again late response<p class="c2">and again late response</p></div>"#
5149
)
5250
}
5351
}
5452

5553
private struct AwaitedP: HTML {
5654
var number: Int
5755
var content: some HTML {
58-
AsyncHTML {
56+
AsyncContent {
5957
let _ = try await Task.sleep(for: .milliseconds(1))
6058
p { "\(number)" }
6159
}

0 commit comments

Comments
 (0)