scala.js

Scala JS extending an HTMLElement to make a CustomElement

只愿长相守 提交于 2019-12-11 08:18:48
问题 Fiddling with ScalaJS, I am trying to achieve the following, ie. create a custom web component skeleton: class DocumentPreview extends HTMLElement { static get observedAttributes() { return []; } constructor() { super(); this.root = this.attachShadow({ mode: "open"}); } connectedCallback() { let x = document.querySelector('link[rel="import"]#templates').import; this.root.appendChild(x.querySelector("#document-preview").content.cloneNode(true)); } disconnectedCallback() { }

How to wrap Web Worker response messages in futures?

♀尐吖头ヾ 提交于 2019-12-11 06:19:46
问题 Please consider a scala.js application which runs in the browser and consists of a main program and a web worker. The main thread delegates long running operations to the web worker by passing messages that contain the names of methods and the parameters required to invoke them. The worker passes method return values back to the main thread in the form of response messages. In simpler terms, this program abstracts web worker messaging so that code in the main thread can call methods in the

Linker error in ScalaJS: “Referring to non-existent class”

允我心安 提交于 2019-12-11 05:07:26
问题 I am getting a bunch of linker errors when trying to link to FastParse in a Scala project which I've just tried to build a ScalaJS web app in. I added the ScalaJS dependency for FastParse into my build.sbt: here's approximately the relevant line (full file here): libraryDependencies ++= Seq( "com.lihaoyi" %%% "fastparse" % "0.4.1" ) My errors are voluminous, but here's a representative one: [error] Referring to non-existent class fastparse.Implicits$Repeater$ [error] called from parsers

How to troubleshoot JS dependencies between webjars and scala-js jars in an SBT project?

故事扮演 提交于 2019-12-11 03:47:00
问题 I've been using scalajs-dom v 0.8.1 and trying to mix webjars within my SBT project. When I do this, I'm getting one final ambiguous JS reference that I can't figure out. I think it is between the webjars I want to use (that include jquery v 2.1.4) and scala-js. I tried using the ManifestFilters SBT filter but it does not seem to help (or I don't know the correct syntax). Does anyone have a useful way to debug these kinds of errors? (see below for SBT output when issuing the 'fastOptJS' task)

How to import `%%%` in `Build.scala` in a scalajs project?

和自甴很熟 提交于 2019-12-11 02:53:14
问题 We can easily use %%% in a build.sbt in a scalajs project, like: libraryDependencies += "com.lihaoyi" %%% "utest" % "0.3.0" % "test" (live demo: https://github.com/scala-js/scala-js-pickling/blob/master/build.sbt#L92) But when I try to use project/Build.scala to write the same build file, it can't compile, and I've no idea how to import the %%% : import org.scalajs.sbtplugin.cross.{CrossType, CrossProject} import sbt._ import Keys._ object Build extends sbt.Build { lazy val crossProject =

How to resolve “Ambiguous reference to a JS library”?

╄→尐↘猪︶ㄣ 提交于 2019-12-11 00:49:30
问题 I'm struggling resolving some Javascript library dependency clashes in the following build.sbt file: lazy val root = project.in(file(".")).enablePlugins(ScalaJSPlugin) scalaVersion := "2.11.7" libraryDependencies ++= Seq( "org.scala-js" %%% "scalajs-java-time" % "0.1.0", "org.querki" %%% "jquery-facade" % "0.10" ) jsDependencies ++= Seq( "org.webjars.bower" % "jquery" % "3.0.0-beta1" / "jquery.js" ) When running the fastOptJS task I'm getting the following error message: [trace] Stack trace

Can JSweet viably port Java libraries for use in cross-built Scala.js projects?

你说的曾经没有我的故事 提交于 2019-12-11 00:31:43
问题 In the search for ways to make Java libraries accessible to both the JavaScript and JVM sides of Scala.js cross-built projects, please consider the following experiment: Imagine that a Scala.js project needs advanced matrix math capabilities such as Singular Value Decomposition. Although the JavaScript world has Numeric.js and the JVM world has many options, JAMA not least among them, no cross building Scala.js solution exists at the time of this question's formulation. What options do we

How to parse a json string to a case class in scaja.js and vice versa

[亡魂溺海] 提交于 2019-12-10 12:48:18
问题 A JSON string: { "name": "Mike", "age": 111 } A case class: case class User(name:String, age:Int) If I use scala, there are many libraries can let me convert the JSON to the case class and vice versa, but they can't be used in scala.js. How to do this work in scala.js? 回答1: Use one of the pickling libraries that work with Scala.js. The following two produce well-behaved and predictable JSON: uPickle Prickle 回答2: Circe has more than 1000 stars: https://github.com/circe/circe 来源: https:/

How to set up a dependency between two Scala.js cross-projects in a multi-module build?

我的梦境 提交于 2019-12-08 10:10:17
问题 Say I have two sub-projects, lib1 and lib2 with build.sbt s that look like this: lazy val libX = crossProject.in(file(".")).settings( ... // a bunch of settings ).jvmSettings( ... // a bunch of settings ).jsSettings( ... // a bunch of settings ) lazy val libXJVM = apiClient.jvm lazy val libXJS = apiClient.js I need to use them in another large multi-module project so that lib2 depends on lib1 . If I try this in the main build.sbt : lazy val lib1 = crossProject.in(file("lib1")) lazy val lib2 =

Build JS from SJSIR `manually`

人走茶凉 提交于 2019-12-08 02:03:35
问题 I need to build a js file from sjsir files at runtime to implement a system of plugins, so that it can't be done at compile time with the rest of my compilation. I used to implement the same process in 0.6.3 with the following code, but it seems to be deprecated. What algorithm do you recommand to achieve the same action with 0.6.13 ? Thanks val scalajsLib = copyJar("scalajs-library_2.11-0.6.3") val semantics = org.scalajs.core.tools.sem.Semantics.Defaults val partialClasspath =