scala.js - yet another what..?

Post on 06-Aug-2015

511 Views

Category:

Documents

6 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Scala.jsYet Another What... ?

Created by / Artur Skowroński @arturskowronski

#JavascriptEverywhere

There are a problems with bigapps in Javascript

We have transpiled languages

We have compiled languages

Google Web Toolkit

Opal (Rb 2 JS)

CobolScript

Brainfuck.js

Scala.js

Said to be production ready

Functional JavaScript is gettingpopularity

Functional ReactiveProgramming

Example 1

object ScalaJSExample extends js.JSApp{ def main() = {

var x = 0 while(x < 999){ x = x + "2".toInt } println(x) }}

ScalaJS.c.Lexample_ScalaJSExample$.prototype.main__V = (function() { var x = 0; while ((x < 999)) { var jsx$1 = x; var this$2 = new ScalaJS.c.sci_StringOps().init___T("2"); var this$4 = ScalaJS.m.jl_Integer$(); var s = this$2.repr$1; x = ((jsx$1 + this$4.parseInt__T__I__I(s, 10)) | 0) }; var x$1 = x; var this$6 = ScalaJS.m.s_Console$(); var this$7 = this$6.outVar$2; ScalaJS.as.Ljava_io_PrintStream(this$7.tl$1.get__O()).println__O__V(x$1)});

<script type="text/javascript" src="/oursample-fastopt.js"></script><script>

</script> oursample.ScalaJSExample().main();

Example 2

object ScalaJSExample extends js.JSApp{ def main() = {}

def exported = {}

def exported2 = {}}

@JSExport

object ScalaJSExample extends js.JSApp{ def main() = {}

@JSExport def exported() = {}

@JSExport def exported2() = {}}

<script> oursample.ScalaJSExample().exported(); oursample.ScalaJSExample().exported2();</script>

$.val()?

val is forbidden in Scala

@JSName

object ScalaJSExample extends js.JSApp{ def main() = {}

@JSExport def exported() = {}

@JSExport def exported2() = {}

@JSExport @JSName('val') def valueOfObject() = {}}

<script> oursample.ScalaJSExample().val();</script>

General problem withTranspiler

SBT Plugin

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0")

compilepackagefastOptJSfullOptJSruntest

compile

Initial Compilation: .scala files to .class and .sjsir files

package

fastOptJs

Fast Optimization: .sjsir files to one smallish/fast .js file

fullOptJsClojure Compiler

Full Optimization: .sjsir files to one smaller/faster .js fileClojure Compiler

run

object RunMe extends js.JSApp{ def main(): Unit = { println("Hello World!") }}

Hello World!

RhinoNode.jsPhantomJs

test

Source Maps

Example 3

@JSExportobject Client extends js.JSApp{ @JSExport def main(container: html.Div) = { val inputBox = input.render val outputBox = ul.render def update() = Ajax.post("/ajax/list", inputBox.value).foreach{ xhr => def response = xhr.responseText (Raw Json Operation) } }}

Not Strongly Typed

autowire

@JSExportobject Client extends js.JSApp{ @JSExport def main(container: html.Div) = { val inputBox = input.render val outputBox = ul.render def update() = Ajaxer[Api].post("/ajax/list", inputBox.value).foreach{ data => (Business Logic on Strongly typed operations) } }}

org.scala-js.scalajs-dom

org.lihaoyi.scalatags

com.lihaoyi.utest

com.lihaoyi.uPickle

me.chrons.boopickle

com.lihaoyi.autowire

com.lihaoyi.workbench

Quirks

Floatprintln(1.4f)1.3999999761 58142

Lack Of Exception Checking

Regular expressions

Reflection Support

Conclusion

Better thanexpected :)

StrenghtsStrongly Typed

IDE Autocompletion

Better know language (for Scala Dev)

Single Language Codebase

WeaknesBig Result Files

Harder Debugging

Don't part of JS Ecosystem

Lack of Support to many libraries (fe. Akka and Guice)

Performance payoffs and don't able to perfomance by hand

OpportunitiesOur Holy Grail :)

More Scalable Codebase

Chances to more library support in future

Creators promise better performance

Treats /Concerns

Project will loose interests and support

Every Abstraction Leaks :(

Links

Activator: play-scalajs-showcase

http://lihaoyi.github.io/hands-on-scala-js/http://www.scala-js-fiddle.com/http://ochrons.github.io/scalajs-spa-tutorial/

Thank You

top related