Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export properties of shared case classes

Tags:

scala.js

I am trying to share a case class between server and client. I am using upickle on both ends. The objects and their data are nicely available on both ends.

shared class

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

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

Is there perhaps a better way of exposing the members id and title to the javascript.

tx.,

like image 840
raphaëλ Avatar asked Feb 09 '15 15:02

raphaëλ


1 Answers

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

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

As a "provided" dependency, it will not be present at runtime. But it will allow you to compile the JVM project even though it references JSExportAll.

See also the ScalaDoc of scalajs-stubs.

like image 134
sjrd Avatar answered Sep 24 '22 00:09

sjrd