Skip to content

ScalaLoci reimplementation of the Play Framework with Scala.js Showcase

License

Notifications You must be signed in to change notification settings

scala-loci/case-study-play-scalajs

 
 

Repository files navigation

ScalaLoci reimplementation (see example-multitier directory)

Play Framework with Scala.js Showcase

###Scala: 2.13.7, Scala.js: 1.7.1, Play: 2.8.11, Slick: 3.3.3

This is a small application showing how cool Scala.js is. You can share code across platforms. For the shared code, the Scala compiler compiles your Scala code to JVM byte code, and the ScalaJS compiler compiles the same Scala code to JavaScript. Beside CSS and a few lines of HTML, almost all code in this project are type-safety including HTML (Thanks to scalatags). I made this project for learning purpose during my summer intern. So, the code you will see in this project may look not good, but I hope you can learn something from it like I did. I will try to keep it update-to-date to make sure that it will run with the recent version of Scala.js.

The sbt build file contains 3 modules

  • exampleServer Play application (server side)
  • exampleClient Scala.js application (client side)
  • exampleShared Scala code that you want to share between the server and the client.

This project would not exist if I didn't find this kick-ass example play-with-scalajs-example.

The project contains 4 simple examples:

  • Todo application with backend persistence.(Modified from Todo application)
    • InMemory, Slick, Anorm, Gremlin (Selectable in application.conf)
  • Hangman (Inspired by Yii's demo)
  • HTML5 Fileupload (Modified from How to Use HTML5 File Drag and Drop)
  • Server Push Chat. It supports both Websocket and Server-Sent Event

Run the application

$ sbt
> run
$ open http://localhost:9000

Run the application on heroku

$ heroku login
$ heroku create
$ git push heroku master
$ heroku open

Features

The application uses the sbt-play-scalajs sbt plugin and the play-scalajs-scripts library.

  • Run your application like a regular Play app
    • compile simply triggers the Scala.js compilation
    • run triggers the Scala.js fastOptJS command on page refresh
    • ~compile, ~run, continuous compilation is also available
    • start, stage and dist generate the optimised javascript
    • playscalajs.html.scripts selects the optimised javascript file when the application runs in prod mode (start, stage, dist).
  • Source maps
    • Open your browser dev tool to set breakpoints or to see the guilty line of code when an exception is thrown
    • Source Maps is disabled in production by default to prevent your users from seeing the source files. But it can easily be enabled in production too by setting emitSourceMaps in fullOptJS := true in the Scala.js projects.

About

ScalaLoci reimplementation of the Play Framework with Scala.js Showcase

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 78.2%
  • CSS 11.0%
  • HTML 6.0%
  • JavaScript 4.7%
  • Shell 0.1%