How to export general case class properties

I am trying to split the case class between server and client. I use upickle on both ends. Objects and their data are well accessible at both ends.

general class

case class Foo(var id : Long,var title: Description) 

However, I need to export the case class fields on the client side. I could add the @ExportAll annotation, but that means pulling scalajs libraries into the server project.

Maybe the best way to expose the id and title of javascript members.

TX.

+6
source share
1 answer

The right way to export things to JavaScript is to use the @JSExportAll annotation. However, you cannot and should not pull the Scala.js libraries into the server project. For this use case, we have a dedicated JVM artifact, scalajs-stubs , which you can add to your JVM project as follows:

 libraryDependencies += "org.scala-js" %% "scalajs-stubs" % scalaJSVersion % "provided" 

As a “provided” dependency, it will not be present at run time. But this will allow you to compile the JVM project, even if it references JSExportAll .

See also ScalaDoc of cigarette butts .

+8
source

Source: https://habr.com/ru/post/982209/


All Articles