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
Jacob Bogers
@Jacob_Bogers_twitter
hi
scala.js, I am blown away
can you make it work with react or svelte?
Antoine Doeraene
@sherpal
For react there is at least two different ways : slinky and scala-js-react. For svelte I don't know anything existing
Jacob Bogers
@Jacob_Bogers_twitter
maybe someone made a framework in scala.js itself
Antoine Doeraene
@sherpal
For frameworks in scala js itself there are at least laminar and outwatch0fw
Outwatch*. There is also scala tags although I'm not sure where people consider it to be a framework
Ulugbek Abdullaev
@ulugbekna
Hi! I have two text files that I want to use in scala-jvm and scala-js (separate) code. In scala-jvm code, I can just read the files, what's a good way to get those files in scala-js? Maybe sbt can load them as variables on compilation or I can somehow embed them in the html? (sorry if the question is not very scala-js specific)
Antoine Doeraene
@sherpal
If you're talking about html, I'm assuming you want to get some text file from the server, or perhaps embedded inside the scala-js compiled file (which, depending on the size of your files, might be bad). (In case you are on node.js, you should simply use the fs module.) if you don't want to deal with a server, then probably the best is to embed in the html, for example in a hidden div with a unique id, and you get it using dom.document.getElementById(myId).innerText (and yes, you can tweak the fastOptJS task to copy paste from your resources, for example). If you want to get it from a server instead, you can simply make an http request. Note, however, that there will be no way to do that synchronously (which is not a bad thing)
3 replies
Dan Di Spaltro
@dispalt
@gzm0 there are options to compress things more in these plugins like terser and friends, the big one for SJS would be mangle properties, however, without some sort of guidance on how to do it, it's too aggressive and the app breaks. I noticed in the GCC linker you have some settings and I wonder if we could come up with some way to enable some lite mangling while respecting some scalajs rules, like don't touch $classData
Tobias Schlatter
@gzm0
hmmm... probably :) I'm quite sure we could extend / change the linker to JS in a different shape. But the specifics would really depend on what plugins we would want to target and what they need. I'm afraid I will not have the cycles to look into the plugins specifically. But if this is important to you, you could have a look at how GCCs advanced optimizations (what we target) compare to the modes of the plugins you'd like. That would be helpful for us so we can better assess whether adjusting the linker would be feasible.
Sébastien Doeraene
@sjrd
I'm slowly starting to think that we might want to build our own minifier for global names (class names, property names, function names). If we do that, then hopefully any local-only JS minifier could be applied to individual .js files to finish the job. It might not be as good as GCC applied to an entire .js file, but it might be able to go a long way in the right direction.
1 reply
Tobias Schlatter
@gzm0
Would that mean ditching GCC entirely?
Sébastien Doeraene
@sjrd
At least as an option, yes. Or we could use GCC in SIMPLE mode on each file separately (after our global name minify phase).
Dan Di Spaltro
@dispalt

I'm slowly starting to think that we might want to build our own minifier for global names (class names, property names, function names). If we do that, then hopefully any local-only JS minifier could be applied to individual .js files to finish the job. It might not be as good as GCC applied to an entire .js file, but it might be able to go a long way in the right direction.

Yeah honestly, if we just shrink some of the property names, I think the bundle would be quite a bit smaller. Right now terser takes 13MB -> 5.6mb for us, incorrectly mangling properties (FWIW) goes from 5.66 -> 2.8MB then gzip is like 500kb

Carlos Quiroz
@cquiroz
Agreed an internal name mangling would go a long way, if you look at the produced js you can see the original names taking a lot of space
After that things like terser could do a bit more
nafg
@nafg
What's the status of getting npmDependencies decoupled from webpacking (as in scalajs-bundler)? Has it happened? Is there any chance of npmDependencies becoming part of scala.js?
Sébastien Doeraene
@sjrd
I don't think anyone has worked on that.
In any case, they would become two separate sbt plugins. We won't add anything to sbt-scalajs (why would we?).
nafg
@nafg
Yeah that's not important. But the convention of the way it records npmDependencies in jar files so they propagate transitively should be documented as a standard that transcends a particular sbt plugin. Also, it needs to be supported in Mill.
Mathieu
@mathieuleclaire
Hi,
I have a question concerning jsDependencies.
I have a facade for plotly.js, but webpacking this library is terrible, so that I have given up using scalajs-bundler to deal with the js sources. So I now use jsDependencies plugin in my facade build. The result is a wrap of the plotly.min.js in my facade jar output as expected.
My question is: how to get this js resource (conained in the jar facade) from a project depending on this facade (so that I could copy it to the right place to render it accessible in my html) ?
I guess it is a trivial use case, but I didn't find the right methods to achieve that.
N.S. Cutler
@godenji

Are there any html libraries available for Scala 3 (or any of the RCs)? I know there's ScalaTags, but like many of the author's libraries, it's vaguely maintained :) Ideally the library itself won't depend on a framework or have other strings attached.

XML literals, sans XML feature support (read: weight/bugs/performance) would be ideal, but that's not happening, so a DSL of some sort is needed to write markup in Scala.

scala 3 builder pattern looks like it could good be a good foundation for markup DSLs:
import scala.collection.mutable.ArrayBuffer

class Table:
  val rows = new ArrayBuffer[Row]
  def add(r: Row): Unit = rows += r
  override def toString = rows.mkString("<table>", "", "</table>")

class Row:
  val cells = new ArrayBuffer[Cell]
  def add(c: Cell): Unit = cells += c
  override def toString = cells.mkString("<tr>", "", "</tr>")

case class Cell(elem: String):
  override def toString = s"<td>$elem</td>"

def table(init: Table ?=> Unit) =   
  given t: Table = Table()
  init
  t

def row(init: Row ?=> Unit)(using t: Table) =
  given r: Row = Row()
  init
  t.add(r)

def cell(str: String)(using r: Row) =
  r.add(new Cell(str))

table {
  row {
    cell("top left")
    cell("top right")
  }
  row {
    cell("bottom left")
    cell("bottom right")
  }
}
N.S. Cutler
@godenji

Once you add in attributes then it's not quite as nice as xml literals, but decent enough I suppose.

e.g. empty attribs in xml literals require no extra syntax (<table>...</table>) vs. builder pattern which requires empty set of parens (table() { ... })

Li Haoyi
@lihaoyi

If you want something production ready, and you think Scalatags isn't well enough maintained, you should definitely fork it before you try coming up with your own thing. That will get you to a well-maintained, usable, production-ready implementation much faster.

Unless your goal is to invent a HTML library or play with new language features, in which case go right ahead :) Just know that it'll inevitably be even more poorly maintained than Scalatags already is!

lots of people have forked Scalatags when they needed more control (e.g. Scala-Js-React did, Slinky basically has a carbon-copy though not sure if it's a fork or re-write) so there's no harm or shame in doing so
August Nagro
@AugustNagro

@godenji I am working on a Scala 3 DSL using the new Context Functions. I'm really enjoying it so far.

@main def launchApp: Unit = shaka.render(ShoppingList("Odersky"))

class ShoppingList(name: String) extends Component:
  override def template: ComponentBuilder =
    import shaka.builders.{name as _, *}
    div{className("shopping-list")
      h1{t"Shopping list for $name"}
      ul{
        li{t"Scala 3 Books"}
        li{t"Scala.js Tutorials"}
        li{t"Cooking guides!"}
      }
    }

I've made a bunch of demos here: https://github.com/getshaka-org/shaka-docsite/blob/master/src/main/scala/org/getshaka/shaka/docsite/Demos.scala

It's not done yet (not published for Scala 3 and site is down), but check it out if you're interested: https://github.com/getshaka-org/shaka

N.S. Cutler
@godenji

Just know that it'll inevitably be even more poorly maintained than Scalatags already is!

ha, touché :)

You're rather prolific, and with that comes too much on one's plate I suspect. Just exploring some ideas around scala 3 + scala-js, so any markup solution will do the trick in the early stages.

N.S. Cutler
@godenji

@AugustNagro cool, interesting approach, my first instinct with scala markup builder would be to have the tag take a Seq of arguments and have 2nd param block receive the child tag block (e.g. something like: div(cls ~ "...", click ~ "..."){ h1{...} })

I'll take a look at your library, thanks.

August Nagro
@AugustNagro

@godenji In my first iteration I had a varargs param group for properties/styles exactly like you say. But performance is >100 times better without varargs, which create many allocations and cannot be inline'd

You can see the change in getshaka-org/shaka@2c84679.

With inlining, the fullLinkJS output for

div{color("purple"); t"Hello $user"}

Becomes

var b = document.createElement("div");
b.style.color = "purple";
b.appendChild(document.createTextNode("Hello "));
var c = this.Wo;
null !== c && void 0 === c ||
b.appendChild(document.createTextNode(c));
b.appendChild(document.createTextNode(""));
a.appendChild(b);

Which is quite good. So given the perf benefit it's a no brainer. I still use the DSL like HTML, with properties on the same line as the tag, and children in the indented region:

div{`class`("myCls"); id("abc"); otherProp(23)
  p{t"this is the body"}
}
N.S. Cutler
@godenji
@AugustNagro nice start, implement a router and you've got the makings of a native scala SPA framework :)
renghen
@renghen
hi to all
how do we write javascript generators in scala.js ?
Tobias Schlatter
@gzm0
No easy way to do it IIRC.
I'm trying to dig up the discussions we had how to type them.
PR for Iterable (without full generator typing): scala-js/scala-js#2784
This is the original PR: scala-js/scala-js#2110
(with relevant discussion)
nafg
@nafg
@renghen do you actually need to, or do you just want to achieve a similar result?
renghen
@renghen
I am doing some experiments around javascript and cps
I wanted to emulate the same thing on scala.js
Jacob Bogers
@Jacob_Bogers_twitter
is scala.js a good way to learn scala?
Lorenzo Gabriele
@lolgab
@Jacob_Bogers_twitter Scala on JVM and JS are mostly the same language. If you plan to use Scala on the frontend i'd say, why not?
I personally learned it on the JVM because I was coming from Java, if you're coming from a frontend/nodejs background I think starting with Scala.js is totally cool!
Jacob Bogers
@Jacob_Bogers_twitter
I know Java up to 6 (done it full time up to that point), I was a but put off by the toolchain, but maybe I am reading to much into things, yes, I would like to use scala front/backend all the way if possible
I will start with scala.js , super thanks
Lorenzo Gabriele
@lolgab
No worries, you can ask here or on Discord #scala-js if you have any doubt. I really like to have Scala.js full-stack. I currently use Google firebase on a toy project where everything is Scala.js (cloud functions and SPA) :)
rhazn
@rhanarion_twitter
Hello, I am having a look at compiling an existing lib with scala-js but running into an error setting up the testing framework ("SyntaxError: Unexpected token 'export'" as I configure ScalaJS to export an ESModule). Is there an easy way to turn of the testing for a start? I am not that familiar with sbt :/
Sébastien Doeraene
@sjrd
@rhanarion_twitter If you don't run the test command, it won't test. I'm not sure what you mean by "turn of the testing for a start"?
rhazn
@rhanarion_twitter
I have tests for scala that run when I use test. When I enable the scala-js plugin in the sbt file it also adds it's own tests to the test command. I would like to keep everything I have done (compile the scala lib to javascript) but keep the test command as it was (testing only scala code).