Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slinky-native scala 3 support? #569

Open
evelant opened this issue May 11, 2022 · 7 comments
Open

slinky-native scala 3 support? #569

evelant opened this issue May 11, 2022 · 7 comments

Comments

@evelant
Copy link

evelant commented May 11, 2022

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?

@shadaj
Copy link
Owner

shadaj commented Jun 4, 2022

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.

@evbo
Copy link

evbo commented Jul 20, 2022

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!

@shadaj
Copy link
Owner

shadaj commented Jul 22, 2022

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.

@evbo
Copy link

evbo commented Sep 16, 2022

How should ExternalComponent be handled in Scala 3?

Update

def apply(p: Props): BuildingComponent[E, R] =

Super simple! So instead of MyComp.component(MyComp.Props(..)) it's just calling the apply method: MyComp(MyComp.Props(..))

@shadaj
Copy link
Owner

shadaj commented Oct 5, 2022

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.

@evbo
Copy link

evbo commented Jan 24, 2023

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

@evbo
Copy link

evbo commented Jan 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants