FOSS-SEA 2013
JavaScript & modern scala backendRuslan Shevchenko
@rssh1
(gradsoft, gosave)
?
- web 90, MVC, ROR-Like, one-page ..
- scala-frameworkslift, play, spray.io, scalatra
- javascriptjscala, scala-js
90-
/ html (JavaScript )
,
M
V
C
MVC
,
M
V
C
MVC
Ajax
Javascript
M
V
C
MVC
Rich client
Presentation Layer
M
V
C
REST
Rich client/ backbone style
M
V
C
REST
=
Rich client / Angular style
- ( RPC)
M
V
C
RPC
persistence REST application ?
M
V
C
RPC
(websockets, comet)
M
V
C
Scala
javascript ?
- static typing.
[99, 100, 101].sort()
Scala
javascript ?
-
-
Main frameworks:
Lift(old-style, presentation first)
Play(mainstream, ROR analog)
Spray.io(ligthweight, RPC style)
Scalatra(servlet compatible)
Lift
def render = { "type=submit" #> SHtml.submit("Register", process, "onclick" -> JsIf(JsEq(ValById("first_name"), ""), Alert("alert") & JsReturn(false)).toJsCmd) }
XML ( )
Play
- Request response - view compile-time ( )
Netty, spray.ioo
Play / Example
def index = Action.async { val futureInt = Future { intensiveComputation() } val timeoutFuture = Promise.timeout("Oops", 1.second) Future.firstCompletedOf(Seq(futureInt, timeoutFuture)).map { case i: Int => Ok("Got result: " + i) case t: String => InternalServerError(t) }}
Play/JSON
case class Person( name: String, age: Int)
object Person{ implicit val personFmt = Json.format[Person] }
JavaScript / scala
Write in scala, produce javascriotJscala http://www.jscala.org(lightweight, macros, from Alexander Nemish, Kiev)
Scala-js http://www.scala-js.org(fully functional scala-to-js compiler, EPFL institute)
jscala
import org.jscala._@JavaScript class Test { def hello() { print("Hello") }}val testJs = Test.javaScript.as[JsStmt] // Get class Test JsAstval main = javascript { val t = new Test() t.hello()}
jscala
import org.jscala._@JavaScript class Test { def hello() { print("Hello") }}
jscala
val testJs = Test.javaScript.as[JsStmt]val main = javascript { val t = new Test() t.hello()}
jscala
@JavaScript, javascript{ .. }
scala scala-lib
,
DOM API ()
javascript runtime
scala-js
,
10 Mb / (js) google closure
Scala/javascript
- API (thrift)
- API
- (jscala, scala-js)
- Scala Akka
Erlang, RxJava
?
-
@rssh1