From 20fa5edd82d2acba85eabe03116681f1584e7414 Mon Sep 17 00:00:00 2001 From: Philip Wedemann <22521688+hfhbd@users.noreply.github.com> Date: Mon, 7 Jun 2021 09:24:57 +0200 Subject: [PATCH] Web: Remove content builder for empty elements (#745) * Remove content builder for empty elements * Remove content builder for empty elements Co-authored-by: hfhbd --- .../kotlin/com/sample/content/Header.kt | 2 +- .../kotlin/com/sample/content/IntroSection.kt | 4 ++-- .../androidx/compose/web/elements/Elements.kt | 23 ++++++++----------- .../src/jsTest/kotlin/elements/TableTests.kt | 14 +++++------ .../src/jsMain/kotlin/layouts/slider.kt | 2 +- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/Header.kt b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/Header.kt index a6b4ca8676..7513215e56 100644 --- a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/Header.kt +++ b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/Header.kt @@ -62,7 +62,7 @@ private fun LanguageButton() { property("padding-left", value(8.px)) property("padding-right", value(8.px)) } - }) {} + }) Text("English") } } diff --git a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/IntroSection.kt b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/IntroSection.kt index 9bd666519f..2a0670c61e 100644 --- a/web/benchmark-core/src/jsMain/kotlin/com/sample/content/IntroSection.kt +++ b/web/benchmark-core/src/jsMain/kotlin/com/sample/content/IntroSection.kt @@ -21,7 +21,7 @@ fun Intro() { classes(WtCols.wtCol2, WtCols.wtColMd3) styleBuilder.alignSelf(AlignSelf.Start) }) { - Img(src = "i1.svg", attrs = { classes(AppStylesheet.composeLogo) }) {} + Img(src = "i1.svg", attrs = { classes(AppStylesheet.composeLogo) }) } Div(attrs = { @@ -202,7 +202,7 @@ private fun ComposeWebStatusMessage() { width(24.px) height(24.px) } - }) {} + }) } Div(attrs = { diff --git a/web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt b/web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt index a3557a0ddb..362433fb7e 100644 --- a/web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt +++ b/web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt @@ -88,8 +88,7 @@ fun A( fun Input( type: InputType = InputType.Text, value: String = "", - attrs: AttrBuilderContext = {}, - content: ContentBuilder? = null + attrs: AttrBuilderContext = {} ) { TagElement( tagName = "input", @@ -98,7 +97,7 @@ fun Input( value(value) attrs() }, - content = content + content = null ) } @@ -181,10 +180,8 @@ fun Span( ) = TagElement("span", applyAttrs = attrs, content = content) @Composable -fun Br( - attrs: AttrBuilderContext = {}, - content: ContentBuilder? = null -) = TagElement("br", applyAttrs = attrs, content = content) +fun Br(attrs: AttrBuilderContext = {}) = + TagElement("br", applyAttrs = attrs, content = null) @Composable fun Ul( @@ -214,15 +211,14 @@ fun DOMScope.Li( fun Img( src: String, alt: String = "", - attrs: AttrBuilderContext = {}, - content: ContentBuilder? = null + attrs: AttrBuilderContext = {} ) = TagElement( tagName = "img", applyAttrs = { src(src).alt(alt) attrs() }, - content = content + content = null ) @Composable @@ -412,13 +408,12 @@ fun Caption( @Composable fun Col( - attrs: AttrBuilderContext = {}, - content: ContentBuilder? = null + attrs: AttrBuilderContext = {} ) { - TagElement( + TagElement( tagName = "col", applyAttrs = attrs, - content = content + content = null ) } diff --git a/web/core/src/jsTest/kotlin/elements/TableTests.kt b/web/core/src/jsTest/kotlin/elements/TableTests.kt index 43afa09f23..edcc3ad4db 100644 --- a/web/core/src/jsTest/kotlin/elements/TableTests.kt +++ b/web/core/src/jsTest/kotlin/elements/TableTests.kt @@ -25,11 +25,9 @@ class TableTests { @Test fun colAttributes() = runTest { composition { - Col( - { - span(2) - } - ) { } + Col { + span(2) + } } assertEquals( @@ -46,9 +44,9 @@ class TableTests { Text("CaptionText") } Colgroup { - Col { } - Col { } - Col { } + Col() + Col() + Col() } Thead { Tr { diff --git a/web/widgets/src/jsMain/kotlin/layouts/slider.kt b/web/widgets/src/jsMain/kotlin/layouts/slider.kt index 13b782afec..c5d88ea5f6 100644 --- a/web/widgets/src/jsMain/kotlin/layouts/slider.kt +++ b/web/widgets/src/jsMain/kotlin/layouts/slider.kt @@ -28,5 +28,5 @@ actual fun SliderActual( onValueChange(value.toFloat()) } } - ) {} + ) }