Browse Source

Use typed Element in ref to remove cast in usage (#828)

pull/857/head
Philip Wedemann 3 years ago committed by GitHub
parent
commit
67952b4b40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt
  2. 6
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt

4
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt

@ -12,7 +12,7 @@ open class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
val styleBuilder = StyleBuilderImpl()
val propertyUpdates = mutableListOf<Pair<(Element, Any) -> Unit, Any>>()
var refEffect: (DisposableEffectScope.(Element) -> DisposableEffectResult)? = null
var refEffect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null
fun style(builder: StyleBuilder.() -> Unit) {
styleBuilder.apply(builder)
@ -30,7 +30,7 @@ open class AttrsBuilder<TElement : Element> : EventsListenerBuilder() {
fun tabIndex(value: Int) = attr(TAB_INDEX, value.toString())
fun spellCheck(value: Boolean) = attr(SPELLCHECK, value.toString())
fun ref(effect: DisposableEffectScope.(Element) -> DisposableEffectResult) {
fun ref(effect: DisposableEffectScope.(TElement) -> DisposableEffectResult) {
this.refEffect = effect
}

6
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt

@ -89,8 +89,8 @@ inline fun <TScope, T, reified E : Applier<*>> ComposeDomNode(
currentComposer.endNode()
}
class DisposableEffectHolder(
var effect: (DisposableEffectScope.(Element) -> DisposableEffectResult)? = null
class DisposableEffectHolder<TElement: Element>(
var effect: (DisposableEffectScope.(TElement) -> DisposableEffectResult)? = null
)
@Composable
@ -100,7 +100,7 @@ fun <TElement : Element> TagElement(
content: (@Composable ElementScope<TElement>.() -> Unit)?
) {
val scope = remember { ElementScopeImpl<TElement>() }
val refEffect = remember { DisposableEffectHolder() }
val refEffect = remember { DisposableEffectHolder<TElement>() }
ComposeDomNode<ElementScope<TElement>, DomElementWrapper, DomApplier>(
factory = {

Loading…
Cancel
Save