7. autowireautowire
trait Api {
def order(itemIds: List[Int]): Order
def submit(order: Order): Unit
}
val client = Ajax[Api]
val z: Future[Unit] = for {
order <- client.order(itemIds).call()
result <- client.submit(order).call()
} yield result
9. scala-js-reactscala-js-react
@scalax
def render(self: This) = {
val todo = self.state.todos.count(!_.completed)
<section id="todoapp">
<header id="header">
<h1>todos</h1>
<input id="new-todo"
onChange={self.onChange}
onKeyUp={self.onKeyPress}
value={self.state.text}
placeholder="What needs to be done?"
autofocus={true}></input>
</header>
</section>
}
10. scodecscodec
case class Person(name: String, title: String)
object Person {
implicit val codec = Codec[Person]
}
sealed trait Tree
case class Node(l: Tree, r: Tree) extends Tree
case class Leaf(n: Int) extends Tree
object Tree {
implicit lazy val codec: Codec[Tree] = {
discriminated[Tree]
.by(uint8)
.typecase2(0, int32.as[Leaf])
.typecase2(1, lazily { (codec :: codec).as[Node] })
}
}
13. АА такжетакже
поддержка IDE
инкрементальная компиляция
source maps
Google Closure Compiler
размеры JS
минимум - 100 Кб
TODO MVC - 250 Кб (64 Kb gzip) + react
максимум - 1Mb
14. ЗаключениеЗаключение
Можно скомпилировать Scala в JS
Scala код можно звать из JS, и наоборот
Производительность сопоставима с JS
Есть много библиотек
Можно все написать на ScalaJS :)
Есть альтернативы, см. Haskell, Erlang, Clojure