Skip to content

Commit 97f7685

Browse files
authored
rename var content to var body (#31)
* rename var content to var body * use tagged version
1 parent 3afbcc4 commit 97f7685

File tree

18 files changed

+47
-53
lines changed

18 files changed

+47
-53
lines changed

Examples/Basic/Sources/App/AnimationsView.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ struct AnimationsView {
88
@State var isOffset: Bool = false
99
@State var isRotated: Bool = false
1010

11-
var content: some View {
11+
var body: some View {
1212

1313
div {
1414
AnimatedView(angle: angle, isBallFading: isBallFading)
@@ -48,7 +48,7 @@ struct AnimatedView {
4848
var x: Double { size * (1 - cos(angle)) }
4949
var y: Double { size * (1 - sin(angle)) }
5050

51-
var content: some View {
51+
var body: some View {
5252
p { "Angle: \(angle) x: \(x) y: \(y)" }
5353
div {
5454
Ball()
@@ -73,7 +73,7 @@ struct AnimatedView {
7373
struct Square {
7474
var color: String
7575

76-
var content: some View {
76+
var body: some View {
7777
span {}
7878
.attributes(
7979
.style([
@@ -94,7 +94,7 @@ extension AnimatedView: Animatable {
9494

9595
@View
9696
struct Ball {
97-
var content: some HTML<HTMLTag.span> & View {
97+
var body: some HTML<HTMLTag.span> & View {
9898
span {}
9999
.attributes(
100100
.style([

Examples/Basic/Sources/App/BindingsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct BindingsView {
66
@State var checked: Bool = false
77
@State var text: String = ""
88

9-
var content: some View {
9+
var body: some View {
1010
div {
1111
p {
1212
"Text: "

Examples/Basic/Sources/App/Views.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct App {
1111
@State var data = SomeData()
1212
@State var bindingViewCount = 1
1313

14-
var content: some View {
14+
var body: some View {
1515
div {
1616
AnimationsView()
1717
hr()
@@ -93,7 +93,7 @@ struct App {
9393
struct Counter {
9494
@State var count: Int = 0
9595

96-
var content: some View {
96+
var body: some View {
9797
div {
9898
button { "-" }
9999
.onClick { _ in count -= 1 }
@@ -115,7 +115,7 @@ struct Counter {
115115
struct TextField {
116116
@Binding<String> var value: String
117117

118-
var content: some View {
118+
var body: some View {
119119
input(.type(.text))
120120
.bindValue($value)
121121
}
@@ -131,7 +131,7 @@ final class SomeData {
131131
struct TestValueView {
132132
@Environment(#Key(\.myText)) var key
133133

134-
var content: some View {
134+
var body: some View {
135135
span { "Via environment value: \(key)" }
136136
}
137137
}
@@ -141,7 +141,7 @@ struct TestObjectView {
141141
@Environment(SomeData.self) var data: SomeData
142142
@Environment(SomeData.self) var optionalData: SomeData?
143143

144-
var content: some View {
144+
var body: some View {
145145
span { "Via environment object: \(data.name)" }
146146
br()
147147
span { "Via optional environment object: \(optionalData?.name ?? "")" }

Examples/Swiftle/Sources/Swiftle/Views.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct GameView {
99
game.handleKey(key)
1010
}
1111

12-
var content: some View {
12+
var body: some View {
1313
FlexColumn(align: .center, gap: 5) {
1414

1515
FlexRow(align: .center, gap: 4) {
@@ -60,7 +60,7 @@ struct GameView {
6060

6161
@View
6262
struct SwiftLogo {
63-
var content: some View {
63+
var body: some View {
6464
img(.src("swift-bird.svg"))
6565
.style(.height(10))
6666
}
@@ -70,7 +70,7 @@ struct SwiftLogo {
7070
struct GuessView {
7171
var guess: Guess
7272

73-
var content: some View {
73+
var body: some View {
7474
FlexRow(gap: 1) {
7575
for letter in guess.letters {
7676
LetterView(guess: letter)
@@ -83,7 +83,7 @@ struct GuessView {
8383
struct LetterView {
8484
var guess: LetterGuess?
8585

86-
var content: some View {
86+
var body: some View {
8787
Block(.width(10), .height(10), .display(.flex)) {
8888
Paragraph(.margin(.auto)) {
8989
guess?.letter.value ?? ""
@@ -103,7 +103,7 @@ struct KeyboardView {
103103
var keyboard: Keyboard
104104
var onKeyPressed: (EnteredKey) -> Void
105105

106-
var content: some View {
106+
var body: some View {
107107
FlexColumn(align: .center, gap: 1.5) {
108108
FlexRow(gap: 1) {
109109
for letter in keyboard.topRow {
@@ -131,7 +131,7 @@ struct KeyboardLetterView {
131131
var guess: LetterGuess
132132
var onKeyPressed: (EnteredKey) -> Void
133133

134-
var content: some View {
134+
var body: some View {
135135
button {
136136
Text(guess.letter.value)
137137
.style(.margin(.auto), .fontSize(.lg), .fontWeight(.semiBold))
@@ -150,7 +150,7 @@ struct KeyboardLetterView {
150150
struct EnterKeyView {
151151
var onKeyPressed: (EnteredKey) -> Void
152152

153-
var content: some View {
153+
var body: some View {
154154
button {
155155
img(.src("enter.svg")).style(
156156
.maxWidth("100%")
@@ -177,7 +177,7 @@ struct EnterKeyView {
177177
struct BackspaceKeyView {
178178
var onKeyPressed: (EnteredKey) -> Void
179179

180-
var content: some View {
180+
var body: some View {
181181
button {
182182
img(.src("backspace.svg")).style(
183183
.maxWidth("100%")
@@ -204,7 +204,7 @@ struct BackspaceKeyView {
204204
struct GameEndOverlay {
205205
@Binding var game: Game
206206

207-
var content: some View {
207+
var body: some View {
208208
if game.state != .playing {
209209
Block(
210210
.position(.absolute),

Examples/Swiftle/Sources/Swiftle/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ElementaryDOM
22

33
@View
44
struct App {
5-
var content: some View {
5+
var body: some View {
66
GameView()
77
}
88
}

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let package = Package(
1010
],
1111
dependencies: [
1212
.package(url: "https://github.com/swiftwasm/JavaScriptKit", .upToNextMinor(from: "0.36.0")),
13-
.package(url: "https://github.com/sliemeobn/elementary", from: "0.5.4"),
13+
.package(url: "https://github.com/sliemeobn/elementary", from: "0.6.0"),
1414
.package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"603.0.0"),
1515
],
1616
targets: [

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ For embedded builds, a recent main or 6.2 snapshot with matching *Swift SDKs for
3333
- ~~transitions and animations (ideally CSS-based, probably svelte-like custom easing functions applied through WAAPI)~~
3434
- better control over animations and basic phaseAnimator
3535
- support for combined and reversible transitions
36-
- somehow migrate over to "var body" instead of "var content" (what was I thinking....)
36+
- ~~somehow migrate over to "var body" instead of "var content" (what was I thinking....)~~
3737
- proper unit testing (once APIs firm up a bit more, partially started)
3838
- implement @ViewEquatableIgnored
3939
- split out JavaScriptKit stuff in separate module to contain spread, maybe one day we can switch to faster interop somehow

Sources/ElementaryDOM/Views/Function/_FunctionNode.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// NOTE: ChildNode must be specified as extra argument to avoid a compiler error in embedded
44
// FIXME: embedded - try with embedded main-snapshot build, revert extra argument if it works
55
public final class _FunctionNode<Value, ChildNode>
6-
where Value: __FunctionView, ChildNode: _Reconcilable, ChildNode == Value.Content._MountedNode {
6+
where Value: __FunctionView, ChildNode: _Reconcilable, ChildNode == Value.Body._MountedNode {
77
private var state: Value.__ViewState?
88
private var value: Value?
99
private var context: _ViewContext?
@@ -18,7 +18,7 @@ where Value: __FunctionView, ChildNode: _Reconcilable, ChildNode == Value.Conten
1818
"\(depthInTree):\(ObjectIdentifier(self).hashValue)"
1919
}
2020

21-
var child: Value.Content._MountedNode?
21+
var child: Value.Body._MountedNode?
2222

2323
init(
2424
value: consuming Value,
@@ -96,17 +96,17 @@ where Value: __FunctionView, ChildNode: _Reconcilable, ChildNode == Value.Conten
9696
self.trackingSession.take()?.cancel()
9797

9898
let (newContent, session) = withReactiveTrackingSession {
99-
value.content
99+
value.body
100100
} onWillSet: { [scheduler = reconciler.scheduler, asFunctionNode = asFunctionNode!] in
101101
scheduler.scheduleFunction(asFunctionNode)
102102
}
103103

104104
self.trackingSession = session
105105

106106
if child == nil {
107-
self.child = Value.Content._makeNode(newContent, context: context!, reconciler: &reconciler)
107+
self.child = Value.Body._makeNode(newContent, context: context!, reconciler: &reconciler)
108108
} else {
109-
Value.Content._patchNode(newContent, node: child!, reconciler: &reconciler)
109+
Value.Body._patchNode(newContent, node: child!, reconciler: &reconciler)
110110
}
111111
}
112112
}

Sources/ElementaryDOM/Views/Function/_FunctionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public protocol __FunctionView: View where _MountedNode == _FunctionNode<Self, Self.Content._MountedNode> {
1+
public protocol __FunctionView: View where _MountedNode == _FunctionNode<Self, Self.Body._MountedNode> {
22
associatedtype __ViewState
33

44
static func __initializeState(from view: borrowing Self) -> __ViewState

Sources/ElementaryDOM/Views/View+Mountable.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Elementary
22

33
// TODO: maybe this should not derive from HTML at all, or maybe HTML should already be "View" and _Mountable is an extra requirement for mounting?
44
// TODO: think about how the square MainActor-isolation with server side usage
5-
public protocol View<Tag>: HTML & _Mountable where Content: HTML & _Mountable {
5+
public protocol View<Tag>: HTML & _Mountable where Body: HTML & _Mountable {
66
}
77

88
public protocol _Mountable {
@@ -21,12 +21,6 @@ public protocol _Mountable {
2121
)
2222
}
2323

24-
public extension View where Content == Never {
25-
var content: Content {
26-
fatalError("This should never be called")
27-
}
28-
}
29-
3024
extension Never: _Mountable {
3125
public typealias _MountedNode = _EmptyNode
3226

0 commit comments

Comments
 (0)