How do I import side-effects in kotlin? Something ...
# javascript
b
How do I import side-effects in kotlin? Something like
import "some/side/effect.js
in javascript?
t
Is it local or global sideeffect?
b
Global (css import)
t
What about shimming? Or you want write imports in code only?
b
Well I cannot do
require("some/style.css")
on top-level kotlin code. And yes, ideally everything should be drivven by code.
t
Do you want to “embed” CSS inside library?
In web components I add
style
in shadow root. If you create root component in library you can use same practice.
Also in legacy you can use file level constant
b
No, not embed. See here how I've managed to do it already, however that's suboptimal, because it's referenced each time that function is invoked. I'd like to import it just once at top level.
t
It can be realized as “HOC”
Copy code
Style("button.css") {
    Button {}
}
require
will be called inside
Style
In common case looks container required (web component), because in case of local styles shadow root required:
Copy code
@Component
@Composable
fun MyButton(
    val name: String,
) {
    Style("button.css")

    Button {}
}
👍 1