Hello all, Using legacy backend, I used to create ...
# javascript
a
Hello all, Using legacy backend, I used to create private react components and provide a public wrapper, something in the lines of
Copy code
private class Counter(props: Counter.Props) : RComponent<Counter.Props,Counter.State>(props) {
  class Props(val initialValue: Int):RProps
  class State(val value: Int) : RState
  // . . .
}

fun RBuilder.Counter(initialValue: Int = 0) = child(Counter::class.js,Counter.Props(initialValue)){}
This made only
RBuiler.Counter()
available to consumers. However, with IR backend we need to mark our components with
@JsExport
. Sadly, IR backend won't export a private class/function it results in error upon minification similar to when you don't mark the component with
@JsExport
Currently, I have resorted to leaving them public. This works but again it exposes code that wasn't meant to be public. Also pollutes the namespace as every tiny component is available on the entire project. Which is really huge. Is there a workaround I can use, so that I may use the
IR
backend, export my components but still make them
private/internal
?
a
Could you mark the Counter's constructor as private, but keep the Counter class public?
a
Not sure, let me try. Thanks for the advice
Making the constructor private worked. But only made the components not instantiable which is great. However, I would love to totally hide (make private) the
Components
a
Could you make the builder's return type
Component
instead of the
Counter
subclass? that might let you make the entire
Counter
class private