68
Scala.js Yet Another What... ? Created by / Artur Skowroński @arturskowronski

Scala.js - yet another what..?

Embed Size (px)

Citation preview

Page 1: Scala.js - yet another what..?

Scala.jsYet Another What... ?

Created by / Artur Skowroński @arturskowronski

Page 2: Scala.js - yet another what..?

#JavascriptEverywhere

Page 3: Scala.js - yet another what..?

There are a problems with bigapps in Javascript

Page 4: Scala.js - yet another what..?

We have transpiled languages

Page 5: Scala.js - yet another what..?
Page 6: Scala.js - yet another what..?
Page 7: Scala.js - yet another what..?
Page 8: Scala.js - yet another what..?

We have compiled languages

Page 9: Scala.js - yet another what..?

Google Web Toolkit

Page 10: Scala.js - yet another what..?

Opal (Rb 2 JS)

Page 11: Scala.js - yet another what..?

CobolScript

Page 12: Scala.js - yet another what..?

Brainfuck.js

Page 13: Scala.js - yet another what..?

Scala.js

Page 14: Scala.js - yet another what..?

Said to be production ready

Page 15: Scala.js - yet another what..?

Functional JavaScript is gettingpopularity

Page 16: Scala.js - yet another what..?
Page 17: Scala.js - yet another what..?
Page 18: Scala.js - yet another what..?
Page 19: Scala.js - yet another what..?

Functional ReactiveProgramming

Page 20: Scala.js - yet another what..?

Example 1

Page 21: Scala.js - yet another what..?

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

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

Page 22: Scala.js - yet another what..?

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)});

Page 23: Scala.js - yet another what..?

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

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

Page 24: Scala.js - yet another what..?

Example 2

Page 25: Scala.js - yet another what..?

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

def exported = {}

def exported2 = {}}

Page 26: Scala.js - yet another what..?

@JSExport

Page 27: Scala.js - yet another what..?

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

@JSExport def exported() = {}

@JSExport def exported2() = {}}

Page 28: Scala.js - yet another what..?

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

Page 29: Scala.js - yet another what..?

$.val()?

val is forbidden in Scala

Page 30: Scala.js - yet another what..?

@JSName

Page 31: Scala.js - yet another what..?

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

@JSExport def exported() = {}

@JSExport def exported2() = {}

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

Page 32: Scala.js - yet another what..?

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

Page 33: Scala.js - yet another what..?

General problem withTranspiler

Page 34: Scala.js - yet another what..?

SBT Plugin

Page 35: Scala.js - yet another what..?

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

Page 36: Scala.js - yet another what..?

compilepackagefastOptJSfullOptJSruntest

Page 37: Scala.js - yet another what..?

compile

Page 38: Scala.js - yet another what..?

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

Page 39: Scala.js - yet another what..?

package

Page 40: Scala.js - yet another what..?

fastOptJs

Page 41: Scala.js - yet another what..?

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

Page 42: Scala.js - yet another what..?

fullOptJsClojure Compiler

Page 43: Scala.js - yet another what..?

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

Page 44: Scala.js - yet another what..?

run

Page 45: Scala.js - yet another what..?

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

Page 46: Scala.js - yet another what..?

Hello World!

Page 47: Scala.js - yet another what..?

RhinoNode.jsPhantomJs

Page 48: Scala.js - yet another what..?

test

Page 49: Scala.js - yet another what..?

Source Maps

Page 50: Scala.js - yet another what..?

Example 3

Page 51: Scala.js - yet another what..?

@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) } }}

Page 52: Scala.js - yet another what..?

Not Strongly Typed

Page 53: Scala.js - yet another what..?

autowire

Page 54: Scala.js - yet another what..?

@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) } }}

Page 55: Scala.js - yet another what..?

org.scala-js.scalajs-dom

org.lihaoyi.scalatags

com.lihaoyi.utest

com.lihaoyi.uPickle

me.chrons.boopickle

com.lihaoyi.autowire

com.lihaoyi.workbench

Page 56: Scala.js - yet another what..?

Quirks

Page 57: Scala.js - yet another what..?

Floatprintln(1.4f)1.3999999761 58142

Page 58: Scala.js - yet another what..?

Lack Of Exception Checking

Page 59: Scala.js - yet another what..?

Regular expressions

Page 60: Scala.js - yet another what..?

Reflection Support

Page 61: Scala.js - yet another what..?

Conclusion

Page 62: Scala.js - yet another what..?

Better thanexpected :)

Page 63: Scala.js - yet another what..?

StrenghtsStrongly Typed

IDE Autocompletion

Better know language (for Scala Dev)

Single Language Codebase

Page 64: Scala.js - yet another what..?

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

Page 65: Scala.js - yet another what..?

OpportunitiesOur Holy Grail :)

More Scalable Codebase

Chances to more library support in future

Creators promise better performance

Page 66: Scala.js - yet another what..?

Treats /Concerns

Project will loose interests and support

Every Abstraction Leaks :(

Page 67: Scala.js - yet another what..?

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/

Page 68: Scala.js - yet another what..?

Thank You