Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 18 19:06
    @sjrd banned @Amitgup48798297_twitter
  • Mar 29 07:47
    @sjrd banned @quangs
  • Jan 23 06:34
    @sjrd banned @Rebeka58_gitlab
  • Jun 08 2020 20:43
    @sjrd banned @sw7240614
  • Sep 29 2019 08:35
    @sjrd banned @8bitpitRBX_twitter
  • May 23 2019 13:44
    @sjrd banned @BIGCRYPTO001_gitlab
  • May 01 2019 14:31
    @sjrd banned @Certificates1_gitlab
  • Apr 22 2019 15:31
    @sjrd banned @lerbatax
  • Jan 31 2019 23:04
    sjrd commented #3555
  • Jan 31 2019 22:56
    sjrd review_requested #3555
  • Jan 31 2019 22:56
    sjrd opened #3555
  • Jan 31 2019 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 2019 21:06
    sjrd closed #3554
  • Jan 31 2019 20:54
    erikvanoosten commented #2665
  • Jan 31 2019 16:33
    sjrd commented #3538
  • Jan 31 2019 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 2019 15:54
    sjrd closed #3552
  • Jan 31 2019 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 2019 15:54
    sjrd closed #3553
  • Jan 31 2019 15:33
    sjrd commented #2665
Alexis Hernandez
@AlexITC
thanks for the hint, I was trying to avoid that
Sébastien Doeraene
@sjrd
Or better, declare BadgeBackgroundColorDetails as a non-native JS trait, and then create an instance of it using new BadgeBackgroundColorDetails { ... }
@vdnhi When you emit the Scala.js code as an ES module, the @JSExportTopLevel things are exported as members of the module, not as global variables. So you would have to refer to onClick as a member of the main.js module. I'm not sure whether it's easy to do so directly from the HTML.
scalavision
@scalavision

Hi!, I am struggling with importing a js module, using snowpack:

'use strict';
import * as $i_cerebral from "./_snowpack/pkg/cerebral.js";

I get this at the top of my *-fastopt.js file, and it throws Uncaught SyntaxError: Cannot use import statement outside a module. I have the following basic code:

import scala.scalajs.js
import js.annotation.*
import demo.dict.Dictionary

@js.native
@JSImport("cerebral", "Module")
class Module(dict: Dictionary[js.Any]) extends js.Object
class State(  title: String) extends js.Object

class MyApp() extends js.Object:

  def test() =
    val dict = Dictionary.empty[js.Any]
    println("creating dict")
    dict("state") = State("Hello World")
    val module = demo.cerebral.Module(dict)

I tried wrap this around the Main class:

@JSExportTopLevel("MyApp")
object Main:
  def main(args: Array[String]): Unit =
    val myApp = demo.cerebral.MyApp()
    myApp.test()

and in my build.sbt I have added the ESModule that should be similar to snowpack (i.e. native javascript / browser module system)

scalaJSLinkerConfig ~= {
  _.withModuleKind(ModuleKind.ESModule) //.outputPatterns
}

is there something else I am missing? Is it possible to get access to a javascript library without using the JSImport somehow?

I am using Scala 3 by the way ..
Swoorup Joshi
@Swoorup
how do you have a suitable compiler
Sébastien Doeraene
@sjrd
It seems that fiddle tries to use Scala 2.11, which is not supported by ScalaFiddle anymore. You can make it work by selecting Scala 2.12 in the options.
Swoorup Joshi
@Swoorup
weird I don’t see any options
Sébastien Doeraene
@sjrd
You have to expand "Libraries" in the menu on the left.
Swoorup Joshi
@Swoorup
nice, i wonder if it will support scala 3 anytime soon
Eric K Richardson
@ekrich
Is portable-scala-reflect planned to support Scala 3?
Sébastien Doeraene
@sjrd
If someone manages to make it work, yes.
Anton Sviridov
@velvetbaldmime:matrix.org
[m]

@sjrd do you know which bit of the project is unlikely to work? I've seen an issue before that only occured on 1 module on Scala 3:

[error]   NoClassDefFoundError: cats
[error] 
[error]   Class.java:-2            java.lang.Class#getDeclaredFields0
[error]   Class.java:2583          java.lang.Class#privateGetDeclaredFields
[error]   Class.java:2975          java.lang.Class#getField0
[error]   Class.java:1701          java.lang.Class#getField
[error]   Reflect.scala:111        org.portablescala.reflect.Reflect$#isModuleClass
[error]   Reflect.scala:57         org.portablescala.reflect.Reflect$#$anonfun$lookupLoadableModuleClass$1
[error]   Reflect.scala:57         org.portablescala.reflect.Reflect$#$anonfun$lookupLoadableModuleClass$1$adapted
[error]   Option.scala:319         scala.Option#filter
[error]   Reflect.scala:57         org.portablescala.reflect.Reflect$#lookupLoadableModuleClass

I was going to dig into it, but if you have insight into where to look - that'd be awesome

Note that we've been using portable scala reflect in 2.13 compat mode, and it's been fine for most things, apart from the 1 specific usecase
It's a macro that gets the this value at the call site, and Scala 3 macros don't appear to let us do that. (Somewhat with reason, because it's not hygienic in general.)
nafg
@nafg
What is this circular structure?
Screenshot from 2021-06-17 20-06-20.png
It seems something that has a List can't be passed to JSON.stringify
Material-ui Autocomplete wanted to complain that about something and its error message involved JSON.stringify
But the choices are scala objects that contain a List
So it crashed :(
nafg
@nafg
scala.js 1.6.0, scala 2.13.6
Nikita Gazarov
@raquo

Hm. Not an expert on this, but it looks like this might be the culprit in List.scala:

@transient
private[this] val EmptyUnzip = (Nil, Nil)

In a Nil instance, this makes Nil reference itself, which is not allowed in JSON.

JSON.stringify only looks at enumerable object properties. Perhaps Scala.js should make @transient fields non-enumerable?

Full disclosure, I have no idea how they're treated right now.

nafg
@nafg
Thanks! I thought I searched for something called EmptyUnzip and didn't find it, maybe I didn't search the right way...
In what scala version was that introduced?
looks like 2.13.0-RC1 scala/scala@535e67a
Anyway I think adding a getOptionSelected prop will avoid this crash
It's actually trying to log a warning, because the initial value is not one of the options (I assume via reference equality since it should be the same as an option, but my own comparison function is definitely a better way)
evbo
@evbo
is this syntax possible in scalajs (window. in front)?:
const { ipcRenderer } = window.require('electron');
Sébastien Doeraene
@sjrd
@evbo Sure: js.Dynamic.global.window.require("electron")
nafg
@nafg
@sjrd any thoughts about JSON.stringify(Nil) crashing?
Sébastien Doeraene
@sjrd
Nil is a Scala object. You cannot meaningfully stringify it. Use JS objects instead.
nafg
@nafg
@sjrd see above for the context
Suppose I want to render a JS widget that chooses scala objects. What else should I do?
Sébastien Doeraene
@sjrd
Well that depends on how your JS widget framework works. But if you have to JSON.stringify it, you can't use Scala objects.
nafg
@nafg
The question is not whether the stringification is meaningful (I assume that means roundtrippable or otherwise useful). I still think it should crash
I'm not the one calling JSON.stringify. It was calling it in a console.warn line
(It = the JS library)
Sébastien Doeraene
@sjrd
Then I suggest you complain to that library that its console.warn breaks when using circular data structures.
nafg
@nafg
ok. You don't see any issue with Nil being a circular data structure?

What do you think of @raquo 's suggestion above?

JSON.stringify only looks at enumerable object properties. Perhaps Scala.js should make @transient fields non-enumerable?

Sébastien Doeraene
@sjrd

You don't see any issue with Nil being a circular data structure?

No. It's Scala.js' business to store Scala objects in any way it wants.

Perhaps Scala.js should make @transient fields non-enumerable?

Creating anything but enumerable, writable and configurable fields is a performance cliff hazard.

nafg
@nafg
Ok so what's the safe / right thing to do when I have scala values that I need to be managed by javascript code, like here?
Sébastien Doeraene
@sjrd
Nothing special. You should be able to pass them to JavaScript code as is, if it doesn't try to look into them. The problem here is not the Scala value being passed to JavaScript code, but the fact that that JavaScript code, which I presume is documented to accept any value and not try to dive into its structure, is (probably not intentionally) broken for cyclic structures. It would be just as broken for a JavaScript user passing it their own cyclic data structure. There's nothing Scala.js-specific here.
objektwerks
@objektwerks
I'm no web guru, but does it make sense to add checkValidity and the like to the scala-js-dom HTMLInputElement per the MDN docs?
Sébastien Doeraene
@sjrd
If it's standardized, yes, sure.
objektwerks
@objektwerks
Thanks, Sebastien!