Announcing Scala.js 0.6.8
scala-js.org
scala-js.org
When I first started moving away from Java web apps (where I hated JavaScript), I fell in love with Scala and it's mix of functional and OOP. Features like Futures/Promises, closures, awesome collection library, etc were so refreshing from Java at the time. After a year or so though, I realized JavaScript offered almost the exact same functionality, and had nice libs like underscore.js for collections, etc. :-)
I've been basically 100% JS for the past 4 years, but still admire Scala.
I'm especially interested in reusing model objects between front and back, or is the best practice still to just use REST services the "old fashioned" way? (vs a more GWT-like approach that feels a little more like an RPC)
I would love to have my next project be all Scala but I wonder what are the benefits beyond just having a single language in the project. Is there a good sbt plugin / template that has a good workflow for continuous development/integration/deployment using Scala+Scala.js?
The biggest benefit is probably having a solid type system that's isomorphic. Large, complex responses and post bodies can be seamlessly passed around with full IDE support and refactoring. Beyond that, it's scala.
It uses the excellent sbt-scalajs to provide code shared between server and client, and a websocket controller that can receive those shared messages. It's tied to Play, sihouette, and postgres-async.
That's what I've used for one of my projects and it's worked out pretty well!
import 'MyModule' from 'MyModule.scala.js'
easily from Webpack, etc.There's nothing preventing that single blob from being exported to webpack. I currently export stuff into a legacy require.js/angular app using globals, so I imagine the same could be accomplished with webpack.
The issue will arise when you attempt to include multiple "scala.js webpack" modules. Each one will be compiled as an independent unit and carry it's own subset of the scala standard libraries, etc. For a transitional scenario, that's probably fine, but it does make participation in a fully polyglot webpack-loader or npm ecosystem problematic.
Scala.js also performs whole-program optimizations of the code, besides "simple" dead cole elimination.
But, as other comments note, this is a non-trivial problem.
Very promising enhancement. Thanks !
Would obviously be nice to get generated js blob as lean as possible since Scala 2.13 and overhauled/streamlined collections is still a ways off (at least 18 months post-2.12 GA if release schedule holds).
[1] https://github.com/scala/scala/pull/5003#issuecomment-198150...
The overhaul of collections is, in part, supposed to be more friendly to Scala.js and in particular code size of small applications.