Giter Site home page Giter Site logo

slinky-native scala 3 support? about slinky HOT 7 OPEN

evelant avatar evelant commented on August 21, 2024
slinky-native scala 3 support?

from slinky.

Comments (7)

shadaj avatar shadaj commented on August 21, 2024

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.

from slinky.

evbo avatar evbo commented on August 21, 2024

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!

from slinky.

shadaj avatar shadaj commented on August 21, 2024

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.

from slinky.

evbo avatar evbo commented on August 21, 2024

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(..))

from slinky.

shadaj avatar shadaj commented on August 21, 2024

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.

from slinky.

evbo avatar evbo commented on August 21, 2024

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

from slinky.

evbo avatar evbo commented on August 21, 2024

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.

from slinky.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.