Big Chungus
12/26/2021, 10:23 PMElementScope<T>
is an interface, but AttrsBuilder<T>
is a class? It'd be great if you could make AttrsBuilder<T>
an interface as well as this would allow injecting some custom DSL for attrs builder (without polluting global namespace as those DSLs are usually only meant for that particular component based on HTMLDivElement and not all HTMLDivElements) when using compose-web to wrap custom components. Here's how I'm utilising the fact that ElementScope<T>
is an interface already (although it only works for lower-level components and is kinda hacky).Big Chungus
12/26/2021, 10:28 PMclass MyCustomBuilder(base: Builder): Builder by base {
// My custom scoped extensions
}
Big Chungus
12/26/2021, 11:04 PMOleksandr Karpovich [JB]
12/29/2021, 12:48 PMBig Chungus
12/29/2021, 12:51 PMBig Chungus
12/29/2021, 12:54 PMclass MyCustomAttrsBuilder: AttrsBuilder<HTMLButton>() {
fun onCustomEvent(listener: () -> Unit) {
addEventListener("MyCustomEventName") { listener() }
}
}
@Composable
fun MyCustomComponent(attrs: MyCustomAttrsBuilder.() -> Unit) {
Button(
attrs = {
val custom = MyCustomAttrsBuilder().apply(attrs)
this.copyFrom(custom) // <------- my missing piece at the moment
}
)
}
Big Chungus
12/29/2021, 12:58 PMclass MyCustomElementScope(originalScope: ElementScope<HTMLButton>): ElementScope<HTMLButton> by originalScope {
@Composable
fun CustomSubComponent() {
Div()
}
}
@Composable
fun MyCustomComponent(content: @Composable MyCustomElementScope.() -> Unit) {
Button(
content = {
MyCustomElementScope(this).content() // Works just fine, because all base methods will be delegated to `this`
}
)
}
Big Chungus
12/29/2021, 1:36 PMOleksandr Karpovich [JB]
12/29/2021, 1:52 PMBig Chungus
12/29/2021, 2:04 PMBig Chungus
12/29/2021, 2:08 PM