scala.js

How can scala-js integrate with sbt-web?

时间秒杀一切 提交于 2020-01-01 05:33:07
问题 I would like to use scala-js with sbt-web in such a way that it can be compiled to produce javascript assets that are added to the asset pipeline (e.g. gzip, digest). I am aware of lihaoyi's workbench project but I do not believe this affects the asset pipeline. How can these two projects be integrated as an sbt-web plugin? 回答1: Scala-js produces js files from Scala files. The sbt-web documentation calls this a Source file task. The result would look something like this: val

Parsing the JSON representation of database rows in Scala.js

二次信任 提交于 2019-12-24 16:24:21
问题 I am trying out scala.js, and would like to use simple extracted row data in json format from my Postgres database. Here is an contrived example of the type of json I would like to parse into some strongly typed scala collection, features to note are that there are n rows, various column types including an array just to cover likely real life scenarios, don't worry about the SQL which creates an inline table to extract the JSON from, I've included it for completeness, its the parsing of the

Ambiguous reference to a JS library: jquery.js

家住魔仙堡 提交于 2019-12-24 15:25:57
问题 ScalaJS addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.9") with (after included jquery-ui dep): libraryDependencies += "be.doeraene" %%% "scalajs-jquery" % "0.9.0", jsDependencies += "org.webjars" % "jquery" % 2.2.3 / "jquery.js", jsDependencies += "org.webjars.bower" % "jquery-ui" % "1.11.4" / "draggable.js" error on compile with fastOptJS: [error] - Ambiguous reference to a JS library: jquery.js [error] Possible paths found on the classpath: [error] - META-INF/resources/webjars/jquery/2

How to use '%%%' in a Build.scala file

二次信任 提交于 2019-12-24 12:13:40
问题 I'm getting familiar with using the '%%%' operator in a build.sbt file, but I don't understand how to use it in a build.scala file. I'm getting the following error: value %%% is not a member of String I'm guessing that I have to import the %%% somehow but I don't see how. I tried the following: import org.scalajs.sbtplugin.ScalaJSPlugin._ import ScalaJSKeys._ 回答1: Edit: Since Scala.js 0.6.23, you need the following import: import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport

Why is the Binding.scala router not reevaluated?

99封情书 提交于 2019-12-24 04:43:12
问题 I'm trying to build a generic router for a personal project by Binding.scala. I've defined a PageState trait sealed trait WhistState { def text: String def hash: String def render: Binding[Node] } with a number of subclasses for each route type. I've then trying to create a router, which based on the hash chooses the correct class. object Router { val defaultState: WhistState = DefaultState("Games") val allStates: Vector[WhistState] = Vector(defaultState) val route: Route.Hash[WhistState] =

Getting a scala stacktrace

痴心易碎 提交于 2019-12-23 16:17:58
问题 When my scala-js code throws an error, I'd like to send a sensible stacktrace back to my server to put in the logs. By "sensible stacktrace" I mean something that gives the Scala methods, filenames, and line numbers rather than the transpiled javascript code. I've made good progress by getting the source map and using the Javascript source-map library (https://github.com/mozilla/source-map) to translate each element of the stacktrace from javascript to the corresponding Scala code. My issue:

Scala.js does not see a JS *class* in the global scope, but sees a constructor function

妖精的绣舞 提交于 2019-12-23 16:13:58
问题 While trying to write scalajs facade for javascript class, i am getting the following error: "error Uncaught TypeError: $g.MyRect2 is not a constructor" in chrome console. My javascript class defination is as follows: class MyRect2 { constructor(height, width) { this.height = height; this.width = width; } area() { return this.height * this.width } } Then I imported it as follows in scala @js.native class MyRect2(h:Int,w:Int) extends js.Object { val height:Int = js.native val width:Int = js

Interop between js and scala functions in Scala.js

懵懂的女人 提交于 2019-12-23 15:51:46
问题 I am trying to write a typed façade for my library Paths.js, following the official guide. Following advice from Sebastien in Typed façade for JS library in Scala.js, I was able to flesh out part of the API. What I am now missing is a way to deal with a conversion function which is exposed in the API. Basically, the library lets you write something like var pie = Pie({ data: [ { name: 'Italy', population: 59859996 }, { name: 'Mexico', population: 118395054 }, { name: 'France', population:

How to add lib with jars to shared folder?

谁说我不能喝 提交于 2019-12-23 04:28:18
问题 I have a cross building scala-js project with a client , server and shared folder. If I add a lib folder with some jars in the server project folder I can reference the classes in the jars in my server code. But if add the lib folder in the shared project folder I can't reference the classes in my shared code. Can I add some command in my sbt build file to get my jars visible in my shared project or what should I do? 回答1: .jars should never be shared, since it is not the same .jar for Scala

How can I read a text file with scala.js?

£可爱£侵袭症+ 提交于 2019-12-23 00:28:46
问题 Basically I'm trying to figure out what I need to pass to the onload() method def selectedFile(e: ReactEventI) = { val reader = new dom.FileReader() reader.readAsText(e.currentTarget.files.item(0)) reader.onload( ) } 回答1: You can assign a lambda to the onload handler: reader.onload = (e: UIEvent) => { // Cast is OK, since we are calling readAsText val contents = reader.result.asInstanceOf[String] println(contents) } 回答2: Idiomatic Scala, with error handling Instead of using callbacks, I