851 questions
0
votes
1
answer
51
views
Generic way of array creation in Scala.js
I'm looking for a generic way of array creation in Scala.js.
The following code works fine in JVM and Scala Native platforms:
def newArray[A](fqcn: String, size: Int): Array[A] = {
val clazz = Class....
0
votes
0
answers
35
views
How can I share a resource file in a cross project
I am using the gRPC library in a cross project. My server implementation will be in the js part on nodejs and my client in the jvm
So my question is how can I best share the .proto file between them. ...
0
votes
0
answers
37
views
Is there a mechanism to access a NodeJS app remotely
I have a third party TypeScript library that I would like to access from my Scala application. The library I want to use is dydx-v4-clients
I have been able to access the library by creating a facade. ...
0
votes
1
answer
158
views
Hot Reloading Scala.js
How to hot reload in scala.js application while in development
I am manually reloading the Scala.js application during development. However, I need the ability to reload and immediately reflect the ...
0
votes
0
answers
53
views
Use a SBT task with different settings from one module
When testing locally, I do not care about code size, therefore I switch GCC off by using following line in my frontend and worker modules settings:
Compile / fullLinkJS / scalaJSLinkerConfig ~= { _....
1
vote
1
answer
74
views
Why does Scala multi platform build fails with `Toplevel definition X is defined in ...`?
My multi platform build is failing with an error, that indicates that both JVM and JS dependencies are in the class path. How can this be?
[error] |Toplevel definition EnableReflectiveInstantiation ...
1
vote
2
answers
385
views
Are there any mill/scala-3/scala.js examples available?
Is there a guide or example somewhere for using mill build tool with scala-3 and scala.js? I saw that the same question had been asked, but implicitly for sbt, and the answer was essentially "it ...
0
votes
1
answer
86
views
sbt-crossproject default project has different scalaVersion than I set. Why?
I'm writing a cross-compiled library between JSPlatform and JVMPlatform using sbt-scalajs-crossproject. I've explicitly set scalaVersion in common settings and yet:
sbt:oatlibxp> show scalaVersion
...
0
votes
1
answer
136
views
Scala.js - How to convert Array[Byte] to Blob?
DOM API requires Blob but all I have is Array[Byte]. How can I do the conversion?
import org.scalajs.dom.Blob
def toBlob(input: Array[Byte]): Blob = {
// code in question
}
0
votes
2
answers
128
views
How to share data between Scala.js test suites?
I share data between ScalaTest suites using a common singleton Object. This works fine when running on JVM, but to my surprise it fails on Scala.js. It seems on Scala.js a fresh instance of the ...
1
vote
1
answer
67
views
Scala.js - How to convert Seq to js.Iterable lazily?
I have a Seq[Byte] that I need to convert to js.Iterable[Byte]. I have some code that does that task:
import scala.scalajs.js
import scalajs.js.JSConverters.iterableOnceConvertible2JSRichIterableOnce
...
0
votes
1
answer
107
views
How do I use a BigDecimal from Scala.js in my JavaScript application?
I have this Scala object:
@JSExportTopLevel("Calculator")
object Calculator {
@JSExport
def calculate(): BigDecimal = 3.14
}
I can call the exported singleton method from my JavaScript ...
0
votes
1
answer
48
views
Scala.js - Handling NaN
import scala.scalajs.js
import scala.scalajs.js.Date
import org.scalajs.dom.window.alert
val num: Double = new Date("a").getTime
alert((num + 1).toString)
This code reports NaN as the ...
3
votes
3
answers
534
views
Scala.js - Convert Uint8Array to Array[Byte]
How do I implement the following method in Scala.js?
import scala.scalajs.js
def toScalaArray(input: js.typedarray.Uint8Array): Array[Byte] =
// code in question
2
votes
1
answer
213
views
Testing using scalatest for Scala.js and Slinky
I'm trying to create a react-native app using slinky and am trying to run tests using the scala.js port of scalatest.
Simple situation where the deps look like this in build.sbt
scalaVersion := "...
0
votes
1
answer
174
views
importing static javascript functions into scala.js
In a third party library react-native-fbsdk-next I have a file FBAccessToken.ts
The class below has a few ordinary members and a static member function.
class FBAccessToken {
accessToken: string;
...
1
vote
1
answer
120
views
How to create frontend project from multiple scala.js projects?
My project is a game server with frontend for it. For the frontend I'm using scala.js.
Project is a cross-build so I can share files between jvm (server) and js (client).
Cross-build method: https://...
0
votes
0
answers
130
views
Scala scala.js cannot find module js script in sbt build
I'm trying to import a JS Script script.js into a scala program App.scala and use its methods add and divide.
However on running the program, I keep getting the error, Cannot find module 'resources/...
0
votes
1
answer
378
views
Scala Scala.js importing JavaScript module gives error 'method value is not a member of'
I'm trying to import a JavaScript class module script.js into a scala program main.scala and use its methods add and divide.
I'm using scala.js for importing the JS script and SBT for build.
However ...
1
vote
0
answers
30
views
How to hide Scala.JS types from JVM code?
I've been practicing leveraging as much JVM code as possible in Scala.JS in order to benefit from unit testing pure JVM logic, which is of course much faster. At some point though, you run into the ...
1
vote
1
answer
211
views
How to use scala.js compiler as a compiler plugin, thus allowing it to integrate into Gradle or maven?
I have a Scala project that can only be compiled with Gradle, recently someone has asked it to be ported to Scala.js, ideally by cross-build.
When I read the code of Scala.js, I realised that the bulk ...
0
votes
0
answers
50
views
How do I post a non-string value in a Scala Http request?
From a Scala program, I need to send values with different primitive types to a Node server.
Http("http://middleware-api:3000/createPromoCodeInCms?")
.postForm
.param("lifetime&...
2
votes
0
answers
4k
views
How to avoid "`this` has been rewritten to `undefined`" warning when bundling Scala.js file with rollup?
I'm using a Scala.js file with ECMAScript modules inside a Svelte project. When building the project with rollup I get the warning
this has been rewritten to undefined
With pointing at last line of ...
0
votes
1
answer
68
views
Radiobutton click event invoking callback 2 times
I have a radio button defined as:
<.label(
....styling
^.onClick ==> { event =>
event.stopPropagation()
props.select
},
<.input.radio(
...
0
votes
1
answer
53
views
Scalajs, js.Dictionary inconsistent behavior
I have an inconsistent error using ScalaJS. Here is a minimal example: the size and the content of a dictionary variable are inconsistent.
def A(mapping: js.Dictionary[String]): Unit = {
dom....