Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 23 13:44
    @sjrd banned @BIGCRYPTO001_gitlab
  • May 01 14:31
    @sjrd banned @Certificates1_gitlab
  • Apr 22 15:31
    @sjrd banned @lerbatax
  • Jan 31 23:04
    sjrd commented #3555
  • Jan 31 22:56
    sjrd review_requested #3555
  • Jan 31 22:56
    sjrd opened #3555
  • Jan 31 21:06

    sjrd on 0.6.x

    Remove dead code: specific coll… Adapt the signature of `js.Arra… Merge pull request #3554 from s… (compare)

  • Jan 31 21:06
    sjrd closed #3554
  • Jan 31 20:54
    erikvanoosten commented #2665
  • Jan 31 16:33
    sjrd commented #3538
  • Jan 31 15:54

    sjrd on master

    Fix analyzer cycle detection to… Add toString methods to analyze… Do not provide linked ClassInfo… and 1 more (compare)

  • Jan 31 15:54
    sjrd closed #3552
  • Jan 31 15:54

    sjrd on master

    Remove Logger.success It is un… Make level helpers final Clean-up ScalaConsoleLogger cod… and 1 more (compare)

  • Jan 31 15:54
    sjrd closed #3553
  • Jan 31 15:33
    sjrd commented #2665
  • Jan 31 15:30
    erikvanoosten commented #2665
  • Jan 31 10:41
    sjrd review_requested #3554
  • Jan 31 10:41
    sjrd opened #3554
  • Jan 31 10:05
    gzm0 synchronize #3552
  • Jan 31 10:05
    gzm0 commented #3552
Sébastien Doeraene
@sjrd
The reason is that Scala.js is independent of Node.js. Passing process.argv would fail in other JS environments. Scala.js does not take sides.
aappddeevv
@aappddeevv
Don't forget that node has the node bin and then the script name so val args = process.argv.drop(2) to access the first arg. I typically have a separate project with 2-3 lines in it representing "main" and handling some major "context" instance specific to the environment. Same on the JVM side.
Frank P. Tominc
@franktominc
@aappddeevv can you share a minimal project with me, please?
Frank P. Tominc
@franktominc

Well, I got something working here.


@JSExportAll
@JSExportTopLevel("Main")
object Main {

  def test(s: Array[String]): Unit = {
    println("ABC")
    s.foreach(println)
  }
}
var main = require("./test.js");

main.Main.test(process.argv);

It prints the ABC but on the foreach it's giving me a TypeError: Cannot read property 'length' of undefined. I'm using .jsSettings(scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) }) and calling it using:

node myScript.js 123 123 123

Any ideas?

Sébastien Doeraene
@sjrd
A JS array is not a valid Array[String], so you're running into undefined behavior. But it should have thrown an UndefinedBehaviorError. Unless you're testing in fullOpt mode?
aappddeevv
@aappddeevv
Sébastien Doeraene
@sjrd
You need to export a method that takes a js.Array[String], if you want to go the exports route.
aappddeevv
@aappddeevv
If you are just trying to access the args, use a nodejs facade, or define your own.
Frank P. Tominc
@franktominc
Oh, I'm using the fullOpt mode
Sébastien Doeraene
@sjrd
You should only use the fullOpt mode when you're happy with your testing and you want to deploy/run for real.
fullOpt is not suited for iterative development: it does not check undefined behavior, and takes way longer to compile.
Frank P. Tominc
@franktominc
I made a little parser for arithmetic expressions and I want to run some tests to convince my boss that the java result and the scalaJs result are the same(I'm using BigDecimals)
I am trying to write something minimal, so I can generate a lot of test cases, call the jar file, call the JS file and compare both outputs
aappddeevv
@aappddeevv
You may just want to setup tests, say, with scalatest and demonstrate the sameness by running the tests.
Frank P. Tominc
@franktominc
Yeah, but how can I run scalatests against the JS file?
Sébastien Doeraene
@sjrd
With theProjectJS/test. Exact same thing than theProjectJVM/test for running the tests on the JVM.
Marc Grue
@marcgrue
image.png
^
@oyvindberg and @jhegedus42 - Alright, I can test/debug shared files in IntelliJ by right-clicking the jvm package and choose Run or Debug. Thanks for your help and input. This is good enough for now. I'll probably file a bug report with IntelliJ that you can't do the same by right-clicking the individual shared files directly.
aappddeevv
@aappddeevv
With tests, you can skip the "main" issue. An if you are new to scala/sbt, you could just write the JVM version, run it. Then copy the entire project to a new directory, add the scala-js plugin and %%% to the scalatest dependency. Then run the test in that new dir the same way.
Frank P. Tominc
@franktominc

Build.properties

sbt.version = 1.2.8

Plugins.sbt

addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.28")

build.sbt

import sbtcrossproject.CrossPlugin.autoImport.crossProject

val sharedSettings = Seq(
  name := "arithmetic-interpreter",
  version := "0.1.0-SNAPSHOT",
  libraryDependencies += "com.lihaoyi" %%% "fastparse" % "2.1.3"
)

lazy val arithmeticInterpreter = crossProject(JSPlatform, JVMPlatform)
    .in(file("."))
    .settings(sharedSettings)

Project Structure
https://imgur.com/dlJsydi

When I do a publishLocal and try to run it I'm running into a ClassNotFoundException, so somehow it's not getting the scalalib and packaging together with my jar, any idea why?

Exception in thread "main" java.lang.NoClassDefFoundError: scala/collection/mutable/ArrayOps$ofRef
    at Main$.main(Main.scala:6)
    at Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.collection.mutable.ArrayOps$ofRef
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

Tried to call using java -cp <scalalib> -jar <myjar> and java -jar <myjar>

Sébastien Doeraene
@sjrd
Why not run from sbt with arithmeticInterpreterJVM/run?
Victor Ivri
@vivri
Hi, what's the best way to declare an imported function that accepts an object as an arg? will it be js.Object, js.Dictionary[???] or something else?
^ specifically, here's the function I'd like to import: https://github.com/katzer/cordova-plugin-background-mode#override-defaults
Antoine Doeraene
@sherpal
@vivri you can define a trait NotificationOptions extends js.Object where you set the members that you can set being js.UndefOr[T] for T the type you need. For example val title: js.UndefOr[String] = js.undefined.
Then, when you write the facade for that function, you ask def setDefaults(options: NotificationOptions): Unit = js.native. And you can feed the argument by instantiated new instances of NotificationOptions (a method apply in the companion object is not a bad idea in general)
Victor Ivri
@vivri
Great, thank you @sherpal !
Victor Ivri
@vivri
I wonder if it makes sense to convert the UndefOr[T] to Option[T]? Or will it erase the distinction between undefined and null...
Antoine Doeraene
@sherpal
I think the problem is that Option[T] is not a js object
Victor Ivri
@vivri
I meant on the level of Scala.js API design
aappddeevv
@aappddeevv
I always thought that I should keep Option throughout my code but then I realized that for data coming from an API that is already marked as js.UndefOr, it was easier just to start using js.UndefOr for data that is always intended for a JS API. I defined an extensive amount of js.UndefOr, A|Null, js.Any, js.Object, Null, truthy and Option converters to switch between them as needed. Alot of js doc is subtly wrong about what they accept/don't accept.
Victor Ivri
@vivri
@aappddeevv these converters look like prime candidates for a companion lib :-D

Alot of js doc is subtly wrong about what they accept/don't accept.

agree!

aappddeevv
@aappddeevv
Yeah....I did define one as well as kept them part of the project. Here's the version embedded in one of my repos. The lib version is published elsewhere.
aappddeevv
@aappddeevv
I especially like when the docs say the value will be undefined, comes in as null though, and I have to use a value.toNonNullOption because the scalajslib .toOption does not check for the null as it follows scala semantics (so you can inadvertently get a Some(null)). You either wind up always using .filter or my hideous .toNonNullOption or .truthyOption, or, you model it as a UndefOr[A|Null], ...
Øyvind Raddum Berg
@oyvindberg
I've wanted a js.NullableOrUndefinedOr (with a shorter name) for a very long time too
elyphas
@elyphas
Hi, is there a way to know which html element is going to get the focus before get the focus?
Dan Di Spaltro
@dispalt
@oyvindberg same
nafg
@nafg
@elyphas why do you want that?
elyphas
@elyphas
@nafg , Because i want to hide an element when the active element transition to other element but not certain element
elyphas
@elyphas
Put it in another way if i am in a element and lost the focus i want to know which element is going to get the focus so a thirth element is going to be hide or show
ritschwumm
@ritschwumm
@elyphas https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/relatedTarget could work.
apart from that: don't do it. focus/blur events are finicky for the developer.
and - in my experience - quite often the end-result is actually confusing for the user.
elyphas
@elyphas
@ritschwumm , ok thank you
Nikita Gazarov
@raquo
I've recently learned that Scala.js supports inlining classes much like it can inline methods with @inline annotation. In Scala, value classes have certain rules for which usages will trigger the need to instantiate such classes (e.g. trying to use the value where an instance of a parent trait is expected). Are there similar rules described anywhere for Scala.js @inline classes? Are those rules fairly stable over time? We're considering an optimization in our library that relies on @inline class-es not being instantiated in a certain usage pattern. But that usage will be up to other developers so I'm wondering how fragile this optimization would be.
Sébastien Doeraene
@sjrd
@inline is a hint to the optimizer, so it never changes semantics. That means that if an instance of an inline class escapes even a method, it will be allocated.
It's best to think about it as stack allocation.
Mark Dixon
@mnd999
Is circe 0.12 supported? I'm getting Referring to non-existent method java.time.LocalDateTime$.parse
Sébastien Doeraene
@sjrd
The real question is: does Circe 0.12 support Scala.js? Which you can probably find out on their readme.
Mark Dixon
@mnd999
That's a nice way of looking at it, but probably circe is more important to scalajs than scalajs is to circe
Sébastien Doeraene
@sjrd
It's not a "nice" way of looking at it. It's the technological way of looking at it. Scala.js does not support libraries. It provides the compiler and the infrastructure necessary for projects to add Scala.js support to their build, or not. Scala.js does not have the power to support libraries, technologically speaking. It's the other way around.
Răzvan Rotaru
@roti
Hi, how can I use v1.0.0-M8-scala-2.13.0 instead of v1.0.0-M8? the sbt plugin does not seem to have a scala 2.13 version...
Travis Brown
@travisbrown
@mnd999 FWIW I think the more relevant question here is "does Scala.js support widely-used parts of the Java standard library?"