Questions tagged [scala.js]

Scala.js is a Scala to JavaScript compiler deemed production-ready as of version 0.6.0.

Scala.js compiles Scala code to JavaScript, allowing you to write your Web application entirely in Scala!

Noteworthy features:

  • Support all of Scala, modulo a few semantic differences
  • Very good interoperability with JavaScript code. For example, use jQuery and HTML5 from your Scala.js code, either in a typed or untyped way. Or create Scala.js objects and call their methods from JavaScript.
  • Integrated with sbt (including support for dependency management and incremental compilation)
  • Can be used with your favorite IDE for Scala
  • Generates Source Maps for a smooth debugging experience (step through your Scala code from within your browser supporting source maps)
  • Integrates Google Closure Compiler for producing minimal code for production.

Find out more at scala-js.org

845 questions
0
votes
1 answer

Generate HTML files in sbt

I have a Scala.js project with an index.html file. Currently I use a structure like in Scala.js example, with two different index.html files for fullOptJS and fastOptJS builds. However I would like to DRY this somehow. I think it should be possible…
Suma
  • 33,181
  • 16
  • 123
  • 191
0
votes
1 answer

Adding scalatags to Play framework project

I have a Play framework project with client and server parts. The client part uses scala.js. I'm trying to use scalatags in the client side script. In build.sbt for the project, I added "com.lihaoyi" %% "scalatags" % "0.5.5" to the…
devx
  • 307
  • 1
  • 14
0
votes
1 answer

Google Picker using Scala.js

I'd like to use Google Picker in my Scala.js app. I need to convert this example somehow. There are two main questions: The first, how can I load and use https://apis.google.com/js/api.js in my Scala.js code to use gapi object? gapi.load('auth',…
Alex Karasev
  • 1,108
  • 2
  • 13
  • 24
0
votes
1 answer

upickle read from scalaJS - upickle.Invalid$Data: String (data: 1)

From ScalaJS. import upickle.default._ import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue case class Post(userId: Long, id: Long, title: String, body: String) @JSExport def posts() : Future[Seq[Post]] = { val txt = """[{ …
ses
  • 13,174
  • 31
  • 123
  • 226
0
votes
1 answer

Is there a clear path by which I could implement a React Component that uses context extensively in ScalaJS + React?

This component from react-sticky is one of two in the library. container, which initializes and passes down a context to its child... sticky, which uses the context and scroll position to achieve a sticky header effect. I just spent about two…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
0
votes
1 answer

Framework solution for caching relational object tree on client in client/server scala.js/scala system?

This is a pretty standard problem but I'm not sure what the standard answer is in Scala, especially a Scala / Scala.js system. Given that you have a domain consisting of: Contractor Agent Agency Invoice with the relations: Contractor…
0
votes
0 answers

Resolving ScalaJSPlugin from Build.scala and plugins.sbt

I'm trying to make "ScalaJSPlugin" work, to be resolved in: project/Build.scala object BuildProject extends Build { .. lazy val scalaRx = Project(id = "ScalaRX", base = file("scalarx")).enablePlugins(ScalaJSPlugin).settings( version …
ses
  • 13,174
  • 31
  • 123
  • 226
0
votes
1 answer

How to get the http status code of a request with scalajs-angular

I would like to get the http status code of a request made with scalajs-angular. I can get it with http.get[js.Any]("url") success and a function of type (js.Any, Int) => Unit. But I would like to return something else than Unit. For instance, I…
Simon
  • 6,025
  • 7
  • 46
  • 98
0
votes
1 answer

D3 json parsing in Scala js

I need some help with d3 in scala js please. Not sure how to go about using d3.json function. I have this: val rectXFunVpc = (d: Vpcs, i: Int) => { println(s"rectXFunVpc i:$i") i * 30 } d3.json( "json-file.json",…
Armin
  • 1,367
  • 1
  • 12
  • 17
0
votes
1 answer

scalajs-jquery jQuery get method?

I'm trying to rewrite some code from JavaScript with "jQuery" to "Scala js" with "scalajs-jquery" Here is my code: val imgWidth: Int = jQuery(".advertise-wrap img").get(0).asInstanceOf[dom.html.Image].naturalWidth This gives me error in web browser…
sergeda
  • 2,061
  • 3
  • 20
  • 43
0
votes
1 answer

compilation error on @js.native when added @js.native annotation to a trait on scalajs

It appears like @js.native is not identified by my compiler. In general scalajs compiles to me in the project. link to file (and its including project in github where it fails). source of the file that fails on @js.native package example import…
Jas
  • 14,493
  • 27
  • 97
  • 148
0
votes
1 answer

Export array for jQuery UI autocomplete

I want to export an array of names to be accessible by jQuery UI for autocompletion. I defined an array: @(JSExport @field) val possibleNames = Array("AB", "CD", "ED") and tried to use it in JavaScript: $("#NameInput").autocomplete( {…
Klaus Schulz
  • 527
  • 1
  • 5
  • 20
0
votes
1 answer

How to call a jQuery UI function?

I have a jQuery UI element and I want to write something like that $('myAccordion').accordion("refresh") However, this does not compile since I only have a facade for jQuery - not jQuery UI. How can I proceed here?
Klaus Schulz
  • 527
  • 1
  • 5
  • 20
0
votes
1 answer

Getting the case class instead of the trait in dynRenderR

I am working on a scalajs-react project, and I can't get the following to type check. The relevant documentation is here and here. My pages are: sealed trait Pages case class Product(id: String) extends Pages My routes are defined…
soote
  • 3,240
  • 1
  • 23
  • 34
0
votes
0 answers

How to use scala-js artifacts with sbt-web within a single project?

I would like to use sbt-web and scala-js to create a webjar. So far I have added the artifactPaths of the scala-js artifacts to the mappings in Assets. This does work if I call fastOptJS and the files show up in the correct webjar location.…
Martin Ring
  • 5,404
  • 24
  • 47