slinky-native scala 3 support?
evelant opened this issue · 7 comments
I'm just dipping my toes into Scala(js) and I'm interested in using slinky since I have an existing large react-native app and Typescript is torturous to write and maintain. It looks like there are no artifacts available for slinky-native on scala 3 however. Is this intended?
Ah, this is due to the React Native bindings using the @react
annotation, which isn't supported on Scala 3. You may have better luck with the ScalablyTyped bindings, there's a good chance those will become the recommended approach soon anyways.
This is the only Scala 3 issue I've found open and I'd like to clarify: is this the minimal example on how to compile a component with Slinky in Scala 3 and react (native)?:
package example
import example.app.App
import org.scalajs.dom
import org.scalajs.dom.document
import slinky.core.FunctionalComponent
import slinky.core.facade.{React, ReactElement}
import slinky.web.ReactDOM
import slinky.web.html.{div, h1}
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport
@main
def Example(): Unit = {
ReactDOM.render(App.component(App.Props()), dom.document.getElementById("root"))
}
where App is:
package example.app
import slinky.core.FunctionalComponent
import slinky.web.html.h1
object App {
case class Props()
val component = FunctionalComponent[Props] { props =>
h1(s"Hello, slinky!")
}
}
Would be great if there's a more succinct approach, like still being able to achieve @react
's fancy .apply
look and feel!
Yep, unfortunately for now there's no way to get the nice apply
implementations since there is no support for macros that introduce new APIs.
How should ExternalComponent
be handled in Scala 3?
Update
Super simple! So instead of MyComp.component(MyComp.Props(..))
it's just calling the apply
method: MyComp(MyComp.Props(..))
This is a good point. For now we could just make @react
a no-op on Scala 3.
Then again, I've been considering deprecating the React Native bindings entirely in favor of ScalablyTyped ones, which are more up to date and work across Scala 2/3.
Another big Scala3 feature yet to be supported: Reader
and Writer
Currently if you try to Read
or Write
using case classes, the macro will fail to capture the js.Object
, failing in some way like:
TypeError: null is not an object (evaluating '$thiz.forceRead__sjs_js_Object__O')
As a best effort, I still use Reader
and Writer
but only with js.Object
, not case classes. It defeats the purpose but maintains a consistent API for when these are eventually supported for Scala 3
ouch! Just hit a very hard to catch incompatibility with Scala3:
the children: ReactElement*
Prop does not correctly produce a Seq[ReactElement]
if you pass a Seq[ReactElement]
for that argument. What happens is it produces something like Seq(Fragment(children))
, so a Seq
but always of length 1!!
So be sure to always define children: Seq[ReactElement]
for all elements to be properly passed. Both compile, but only that approach correctly preserves the list structure.