SlideShare a Scribd company logo
1 of 49
Download to read offline
Scala Warrior
and type-safe front-end development with Scala.js
Naoki Takezoe
@takezoen
BizReach, Inc
Scala WarriorにおけるScala.jsとタイプセーフな
フロントエンド開発
Who am I?
● Scala Programmer at BizReach, Inc
● 4+ years Scala experience
● GitBucket author / Scalatra committer
株式会社ビズリーチに勤務するScalaプログラマです。
本を書いたりGitBucketやScalatraなどを開発しています。
About Scala Warrior
Scala Warriorについて
Scala Warrior
● A game written in Scala for learning Scala
● Inspired by Ruby Warrior
● Based on Scala.js, ScalaTags and ScalaCSS
https://github.com/scalawarrior/scalawarrior
Scala学習用のWebベースのゲームです。
Scala.js、ScalaTags、ScalaCSSなどを使用しています。
Motivation
● We wish Scala to become more popular
programming language in Japan
● Activities we did for that since 2011:
○ Writing Scala books
○ Making hands-on tutorial for Play2 and Slick
○ Using Scala in real business systems
2011年頃からScalaの普及のための様々な活動を行ってきま
した。
But they were not enough...
しかしまだ十分普及したとは言えません。
What's missing?
何が足りないのでしょうか?
Making learning fun
● Newbies are feeling
difficulty in Scala
more than necessary
● In fact, We can learn
Scala step by step
Scala初心者はScalaを必要以上に難しく感じています。
もっと楽しく気軽に学ぶことのできる方法が必要です。
It's a game!
ゲームしか!!
Demo
実際の動作をご覧ください。
Team
Takako Shimamoto
Planning / Illustration
Naoki Takezoe
Programming
Scala Warriorはこの2人で開発しました。
Server
(Play2)
Architecture of Scala Warrior
Web Browser
Scala Warriorの仕組みを説明します。
Server
(Play2)
Architecture of Scala Warrior
Web Browser
Scala
1. Send Scala code edited by user
まず、ユーザが入力したScalaコードをサーバに送信
Server
(Play2)
Architecture of Scala Warrior
Web Browser
Scala
2. Compile Scala code to
JavaScript by Scala.js compiler
1. Send Scala code edited by user
サーバでScala.jsコンパイラでJavaScriptコードを生成
Server
(Play2)
Architecture of Scala Warrior
Web Browser
Scala
JavaScript
2. Compile Scala code to
JavaScript by Scala.js compiler
1. Send Scala code edited by user
生成したJavaScriptコードをブラウザに返却
Server
(Play2)
Architecture of Scala Warrior
Web Browser
Scala
JavaScript
2. Compile Scala code to
JavaScript by Scala.js compiler
1. Send Scala code edited by user
3. Evaluate responded JavaScript code
ブラウザ側で返却されたJavaScriptをeval()して評価
JavaScript libraries
Annimation is built on CreateJS
Code editor is built on Ace
アニメーションにはCreateJS、エディタにはAceを使用
Made their Scala.js facade for Scala.js
● scalajs-ace
○ Ace is a powerful online code editor
○ But Scala Warrior hasn't used for several reasons
● scalajs-createjs
○ CreateJS is a suite of libraries to build rich
interactive web contents
これらのライブラリのScala.js用ファサードを作りました(でも
Scala Warriorではscalajs-aceは使っていません)
Great thanks for Li Haoyi's scala-js-fiddle!
https://github.com/lihaoyi/scala-js-fiddle
Li Haoyiさんのscala-js-fiddleを参考にさせていただきました。
ありがとうございます。
Note
● Scala Warrior is a distinctive application
taking advantage of Scala.js
● Uses Scala.js to compile Scala code
entered by user
● Evaluates compiled code on the browser to
protect the server
Scala Warriorは実行時にScala.jsコンパイラを活用する特殊
なアプリケーションであることに注意してください。
Type-safe frontend development
with Scala.js
Scala.jsによるタイプセーフなフロント開発について
Typesafe front-end stack in Scala
Scala
Scala.js
ScalaTags ScalaCSS
scalajs-react
Server-side
Front-end
Scala.js
Scala Compiler
ScalaJS Compiler
Scala Code
*.sjsir*.class
Translate Scala code
to JavaScript by
Scala compiler plugin
*.js
optimize / package
コンパイラプラグインでJavaScriptへの変換を行います。
Scala.js is awesome!!
他のソリューションと比べてメリットしかありません。
Scala.js is universal!
Play project (server-side)
Scala.js project (client-side)
Cross-build project (common)
Scalaとコードを共有することもできます。
Interoperability
● Need type mapping like .d.ts
○ scala-js-ts-importer can convert from .d.ts
○ You can find a lot of .d.ts at DefinitelyTyped
○ But can't convert perfectly...
● js.Dynamic (not type-safe)
import scala.scalajs.js.Dynamic._
val editor: Dynamic = global.ace.edit("editor")
JavaScriptとの連携も完璧です。
ScalaTags
● Type-safe XML/HTML generation library
● Scala and Scala.js support
ScalaTagsはXMLやHTMLをScalaコードでタイプセーフに生
成するためのライブラリです。
ScalaTags
div(`class`:="modal", id:="gameOverModal", role:="dialog")(
div(`class`:="modal-dialog")(
div(`class`:="modal-content")(
div(Styles.modalBody)(
h4(`class`:="modal-title", "Game Over!")
),
div(`class`:="modal-footer")(
a(
`href`:="/level/" + level, `class`:="btn btn-primary",
"Retry this stage"
)
)
)
)
)
ちょっと厳しい感じがあります。
ScalaCSS
● Type-safe CSS generation library
● Scala and Scala.js support
● 2 different mode
○ Standalone mode
○ Inline mode
● ScalaTags and scala-react integration
ScalaCSSは同じくCSSをScalaコードで生成するためのライブ
ラリです。2つのモードがあります。
ScalaCSS (Standalone mode)
import scalacss.Defaults._
object Styles extends StyleSheet.Standalone {
import dsl._
"h1" - (
fontSize(200 %%),
fontWeight.bold
)
"h2" - (
borderBottom(1 px, solid, black)
)
"div.contents" - (
padding(4 px)
)
}
スタンドアロンモード。ここからCSSを生成できます。
ScalaCSS (Inline mode)
import scalacss.Defaults._
object Styles extends StyleSheet.Inline {
import dsl._
val silkFont = fontFace("Silkscreen")(
_.src("url(/assets/stylesheets/slkscr.ttf)")
)
val silk = style(
fontFamily(silkFont)
)
val logo = style(
verticalAlign.bottom,
width(60 px),
paddingBottom(14 px),
silk
)
}
インラインモード。こんな感じでスタイルを定義しておき
ScalaCSS (Inline mode)
import scalacss.Defaults._
object Styles extends StyleSheet.Inline {
import dsl._
val silkFont = fontFace("Silkscreen")(
_.src("url(/assets/stylesheets/slkscr.ttf)")
)
val silk = style(
fontFamily(silkFont)
)
val logo = style(
verticalAlign.bottom,
width(60 px),
paddingBottom(14 px),
silk
)
}
div(
img(
`class`:= Styles.logo.htmlClass,
src:= "/assets/images/logo.png"
),
"Scala Warrior"
)
Compile-time reference checking
class属性に埋めんで使います。
JavaScript Framework Integration
● React
○ scalajs-recat
● AngularJS
○ scalajs-agular
○ angulate2
メジャーなJavaScriptフレームワークをScala.jsで利用するた
めのライブラリもあります。
Great! Super Type-safe!
超タイプセーフ!!
All goes well!
これで全部うまくいく!!
...Really?
まじで??
Problems
● Generated JavaScript file size
● Cost for creating type mappings
問題もあります。
Problems
● Generated JavaScript file size
● Cost for creating type mappings
● Should front-end engineers write Scala?
一番の問題はそもそもフロントエンジニアがScalaを書くべきな
のか?ということです。
The Approach
Reference:
Scala.js: Beyond the Coast-to-Coast Approach by Katrin Shechtman
https://www.youtube.com/watch?v=aqtoe0xDayM
1つのアプローチを紹介します。
The Approach
Scala
Scala.js
(Interface for Frontend)
User Interface
(React or AngularJS?)
Server-side
Front-end
The Approach
Scala
Scala.js
(Interface for Frontend)
User Interface
(React or AngularJS?)
Server-side
Front-end
JavaScript
Programmer
Scala
Programmer
JavaScript / Scalaプログラマでこのように分担します。
Scala.js and JavaScript ecosystem
既存のJavaScriptのエコシステムとの連携について
● Add this line to build.sbt
● @JSExport annotated elements are
expoted as CommonJS module
Export Scala.js as CommonJS module
scalaJSModuleKind := ModuleKind.CommonJSModule
CommonJSモジュールとしてエクスポートできます。
Export Scala.js as CommonJS module
import scala.scalajs.js
import js.annotation._
@ScalaJSDefined
@JSExport("HelloWorld")
class HelloWorld extends js.Object {
def sayHello(name: String): String = s"Hello ${name}!"
}
var hello = require("./hello-fastopt.js")
var helloWorld = new hello.HelloWorld();
console.log(helloWorld.sayHello("Scala.js"));
Scala.js
JavaScript
Use CommonJS module in Scala.js
import scala.scalajs.js
import js.annotation._
@js.native
@JSImport("./hello-fastopt.js", "HelloWorld")
class HelloWorld extends js.Object {
def sayHello(name: String): String = js.native
}
Scala.jsでCommonJSモジュールを使うこともできます。
Summary
まとめ
Why Scala in frontend?
● Scala.js is not ALL or NOTHING!
○ Scala programmers can provide libraries for
frontend using Scala.js
○ JavaScript programmer can use existing frontend
tools and frameworks
全部Scala.jsで作らないといけないわけではありません。
適切な役割分担によってScalaのメリットを活かせます。
Enjoy type-safe
frontend web development
with Scala.js!
Scala.jsはタイプセーフな"フロント"開発ではなくタイプセーフ
な"Web"開発におすすめです。
...and try Scala Warrior!
https://github.com/scalawarrior/scalawarrior
Scala Warriorも是非試してみてください。

More Related Content

What's hot

[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24
[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24
[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24Kazuhiro Sera
 
ScalaでBacklogの通知bot作ったで
ScalaでBacklogの通知bot作ったでScalaでBacklogの通知bot作ったで
ScalaでBacklogの通知bot作ったでAsami Abe
 
JavaからScalaへ
JavaからScalaへJavaからScalaへ
JavaからScalaへtakezoe
 
【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.js【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.jsYuto Suzuki
 
多分モダンなWebアプリ開発
多分モダンなWebアプリ開発多分モダンなWebアプリ開発
多分モダンなWebアプリ開発tak-nakamura
 
並行処理初心者のためのAkka入門
並行処理初心者のためのAkka入門並行処理初心者のためのAkka入門
並行処理初心者のためのAkka入門Yoshimura Soichiro
 
Akka-Streams in Production
Akka-Streams in ProductionAkka-Streams in Production
Akka-Streams in ProductionKazunobu Raita
 
Scalaの現状と課題
Scalaの現状と課題Scalaの現状と課題
Scalaの現状と課題Kota Mizushima
 
Servlet と Future の関わり方 #scala_ks
Servlet と Future の関わり方 #scala_ksServlet と Future の関わり方 #scala_ks
Servlet と Future の関わり方 #scala_ksKazuhiro Sera
 
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けープログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けーTanUkkii
 
Akka meetup 2014_sep
Akka meetup 2014_sepAkka meetup 2014_sep
Akka meetup 2014_sepmasahitojp
 
Scala + Finagleの魅力
Scala + Finagleの魅力Scala + Finagleの魅力
Scala + Finagleの魅力Kota Mizushima
 
Yesodを支える技術
Yesodを支える技術Yesodを支える技術
Yesodを支える技術Hiromi Ishii
 
Sbtのマルチプロジェクトはいいぞ
SbtのマルチプロジェクトはいいぞSbtのマルチプロジェクトはいいぞ
SbtのマルチプロジェクトはいいぞYoshitaka Fujii
 
20150207 何故scalaを選んだのか
20150207 何故scalaを選んだのか20150207 何故scalaを選んだのか
20150207 何故scalaを選んだのかKatsunori Kanda
 
akka-doc-ja
akka-doc-jaakka-doc-ja
akka-doc-jaTIS Inc.
 
Single Command Deployのための gradle-aws-plugin講座
Single Command Deployのための gradle-aws-plugin講座Single Command Deployのための gradle-aws-plugin講座
Single Command Deployのための gradle-aws-plugin講座都元ダイスケ Miyamoto
 

What's hot (20)

[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24
[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24
[Japanese] Skinny Framework で始める Scala #jjug_ccc #ccc_r24
 
実戦Scala
実戦Scala実戦Scala
実戦Scala
 
ScalaでBacklogの通知bot作ったで
ScalaでBacklogの通知bot作ったでScalaでBacklogの通知bot作ったで
ScalaでBacklogの通知bot作ったで
 
JavaからScalaへ
JavaからScalaへJavaからScalaへ
JavaからScalaへ
 
【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.js【LT】 怖くない恐怖のScala.js
【LT】 怖くない恐怖のScala.js
 
多分モダンなWebアプリ開発
多分モダンなWebアプリ開発多分モダンなWebアプリ開発
多分モダンなWebアプリ開発
 
並行処理初心者のためのAkka入門
並行処理初心者のためのAkka入門並行処理初心者のためのAkka入門
並行処理初心者のためのAkka入門
 
Akka-Streams in Production
Akka-Streams in ProductionAkka-Streams in Production
Akka-Streams in Production
 
Scalaの現状と課題
Scalaの現状と課題Scalaの現状と課題
Scalaの現状と課題
 
Servlet と Future の関わり方 #scala_ks
Servlet と Future の関わり方 #scala_ksServlet と Future の関わり方 #scala_ks
Servlet と Future の関わり方 #scala_ks
 
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けープログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
プログラミング言語のパラダイムシフト(ダイジェスト)ーScalaから見る関数型と並列性時代の幕開けー
 
Akka meetup 2014_sep
Akka meetup 2014_sepAkka meetup 2014_sep
Akka meetup 2014_sep
 
Scala + Finagleの魅力
Scala + Finagleの魅力Scala + Finagleの魅力
Scala + Finagleの魅力
 
Yesodを支える技術
Yesodを支える技術Yesodを支える技術
Yesodを支える技術
 
とりあえず使えるSBT
とりあえず使えるSBTとりあえず使えるSBT
とりあえず使えるSBT
 
Sbtのマルチプロジェクトはいいぞ
SbtのマルチプロジェクトはいいぞSbtのマルチプロジェクトはいいぞ
Sbtのマルチプロジェクトはいいぞ
 
Ppl
PplPpl
Ppl
 
20150207 何故scalaを選んだのか
20150207 何故scalaを選んだのか20150207 何故scalaを選んだのか
20150207 何故scalaを選んだのか
 
akka-doc-ja
akka-doc-jaakka-doc-ja
akka-doc-ja
 
Single Command Deployのための gradle-aws-plugin講座
Single Command Deployのための gradle-aws-plugin講座Single Command Deployのための gradle-aws-plugin講座
Single Command Deployのための gradle-aws-plugin講座
 

Viewers also liked

Preparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuriPreparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuriTIS Inc.
 
Tracing Microservices with Zipkin
Tracing Microservices with ZipkinTracing Microservices with Zipkin
Tracing Microservices with Zipkintakezoe
 
Make your programs Free
Make your programs FreeMake your programs Free
Make your programs FreePawel Szulc
 
GitBucketで社内OSSしませんか?
GitBucketで社内OSSしませんか?GitBucketで社内OSSしませんか?
GitBucketで社内OSSしませんか?Kiyotaka Kunihira
 
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Patternchibochibo
 
7 key recipes for data engineering
7 key recipes for data engineering7 key recipes for data engineering
7 key recipes for data engineeringunivalence
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldKonrad Malawski
 
Reducing Boilerplate and Combining Effects: A Monad Transformer Example
Reducing Boilerplate and Combining Effects: A Monad Transformer ExampleReducing Boilerplate and Combining Effects: A Monad Transformer Example
Reducing Boilerplate and Combining Effects: A Monad Transformer ExampleConnie Chen
 
Type-safe front-end development with Scala
Type-safe front-end development with ScalaType-safe front-end development with Scala
Type-safe front-end development with Scalatakezoe
 
Git LFSを触ってみた
Git LFSを触ってみたGit LFSを触ってみた
Git LFSを触ってみたYuto Suzuki
 
大容量ファイルもGitで管理。 Git LFSの使い方
大容量ファイルもGitで管理。 Git LFSの使い方大容量ファイルもGitで管理。 Git LFSの使い方
大容量ファイルもGitで管理。 Git LFSの使い方hibiki443
 
Akka Cluster and Auto-scaling
Akka Cluster and Auto-scalingAkka Cluster and Auto-scaling
Akka Cluster and Auto-scalingIkuo Matsumura
 
Going bananas with recursion schemes for fixed point data types
Going bananas with recursion schemes for fixed point data typesGoing bananas with recursion schemes for fixed point data types
Going bananas with recursion schemes for fixed point data typesPawel Szulc
 
Van laarhoven lens
Van laarhoven lensVan laarhoven lens
Van laarhoven lensNaoki Aoyama
 
Introduction to GraphQL in Scala (ScalaMatsuri 2017)
Introduction to GraphQL in Scala (ScalaMatsuri 2017)Introduction to GraphQL in Scala (ScalaMatsuri 2017)
Introduction to GraphQL in Scala (ScalaMatsuri 2017)Yuki Katada
 
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Masahito Zembutsu
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016takezoe
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 

Viewers also liked (20)

Preparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuriPreparing for distributed system failures using akka #ScalaMatsuri
Preparing for distributed system failures using akka #ScalaMatsuri
 
Tracing Microservices with Zipkin
Tracing Microservices with ZipkinTracing Microservices with Zipkin
Tracing Microservices with Zipkin
 
Make your programs Free
Make your programs FreeMake your programs Free
Make your programs Free
 
GitBucketで社内OSSしませんか?
GitBucketで社内OSSしませんか?GitBucketで社内OSSしませんか?
GitBucketで社内OSSしませんか?
 
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching PatternDeadly Code! (seriously) Blocking & Hyper Context Switching Pattern
Deadly Code! (seriously) Blocking & Hyper Context Switching Pattern
 
7 key recipes for data engineering
7 key recipes for data engineering7 key recipes for data engineering
7 key recipes for data engineering
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
 
Scala Matsuri 2017
Scala Matsuri 2017Scala Matsuri 2017
Scala Matsuri 2017
 
Reducing Boilerplate and Combining Effects: A Monad Transformer Example
Reducing Boilerplate and Combining Effects: A Monad Transformer ExampleReducing Boilerplate and Combining Effects: A Monad Transformer Example
Reducing Boilerplate and Combining Effects: A Monad Transformer Example
 
Type-safe front-end development with Scala
Type-safe front-end development with ScalaType-safe front-end development with Scala
Type-safe front-end development with Scala
 
Git LFSを触ってみた
Git LFSを触ってみたGit LFSを触ってみた
Git LFSを触ってみた
 
大容量ファイルもGitで管理。 Git LFSの使い方
大容量ファイルもGitで管理。 Git LFSの使い方大容量ファイルもGitで管理。 Git LFSの使い方
大容量ファイルもGitで管理。 Git LFSの使い方
 
Akka Cluster and Auto-scaling
Akka Cluster and Auto-scalingAkka Cluster and Auto-scaling
Akka Cluster and Auto-scaling
 
Going bananas with recursion schemes for fixed point data types
Going bananas with recursion schemes for fixed point data typesGoing bananas with recursion schemes for fixed point data types
Going bananas with recursion schemes for fixed point data types
 
Van laarhoven lens
Van laarhoven lensVan laarhoven lens
Van laarhoven lens
 
Introduction to GraphQL in Scala (ScalaMatsuri 2017)
Introduction to GraphQL in Scala (ScalaMatsuri 2017)Introduction to GraphQL in Scala (ScalaMatsuri 2017)
Introduction to GraphQL in Scala (ScalaMatsuri 2017)
 
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
Dockerの期待と現実~Docker都市伝説はなぜ生まれるのか~
 
Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016Scala Frameworks for Web Application 2016
Scala Frameworks for Web Application 2016
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
Pratical eff
Pratical effPratical eff
Pratical eff
 

Similar to Scala Warrior and type-safe front-end development with Scala.js

Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarcon
Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarconSeasar ユーザだったプログラマが目指す OSS の世界展開 #seasarcon
Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarconKazuhiro Sera
 
Isomorphic web development with scala and scala.js
Isomorphic web development  with scala and scala.jsIsomorphic web development  with scala and scala.js
Isomorphic web development with scala and scala.jsTanUkkii
 
ScalaでASICやFPGA用の回路を設計するChisel
ScalaでASICやFPGA用の回路を設計するChiselScalaでASICやFPGA用の回路を設計するChisel
ScalaでASICやFPGA用の回路を設計するChiselKei Nakazawa
 
Scala.jsはじめました!
Scala.jsはじめました!Scala.jsはじめました!
Scala.jsはじめました!K Kinzal
 
Scalaでのプログラム開発
Scalaでのプログラム開発Scalaでのプログラム開発
Scalaでのプログラム開発Kota Mizushima
 
Skinny Framework 進捗どうですか? #fud_scala
Skinny Framework 進捗どうですか? #fud_scalaSkinny Framework 進捗どうですか? #fud_scala
Skinny Framework 進捗どうですか? #fud_scalaKazuhiro Sera
 
株式会社インタースペース 沖本様 登壇資料
株式会社インタースペース 沖本様 登壇資料株式会社インタースペース 沖本様 登壇資料
株式会社インタースペース 沖本様 登壇資料leverages_event
 
Dev love関西 forslideshare
Dev love関西 forslideshareDev love関西 forslideshare
Dev love関西 forslideshareDaisuke Kasuya
 
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksqlMitsutoshi Kiuchi
 
scala+liftで遊ぼう
scala+liftで遊ぼうscala+liftで遊ぼう
scala+liftで遊ぼうyouku
 
Scala: Mobile Backend on AWS
Scala: Mobile Backend on AWSScala: Mobile Backend on AWS
Scala: Mobile Backend on AWScmaraiyusuke
 
Couch Db勉強会0623 by yssk22
Couch Db勉強会0623 by yssk22Couch Db勉強会0623 by yssk22
Couch Db勉強会0623 by yssk22Yohei Sasaki
 
成長を加速する minne の技術基盤戦略
成長を加速する minne の技術基盤戦略成長を加速する minne の技術基盤戦略
成長を加速する minne の技術基盤戦略Hiroshi SHIBATA
 
はじめよう Backbone.js
はじめよう Backbone.jsはじめよう Backbone.js
はじめよう Backbone.jsHiroki Toyokawa
 
HTML5-20100626
HTML5-20100626HTML5-20100626
HTML5-20100626Taku AMANO
 
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方Yuki Morishita
 
Scalaプロダクトのビルド高速化
Scalaプロダクトのビルド高速化Scalaプロダクトのビルド高速化
Scalaプロダクトのビルド高速化kuro kuro
 

Similar to Scala Warrior and type-safe front-end development with Scala.js (20)

Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarcon
Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarconSeasar ユーザだったプログラマが目指す OSS の世界展開 #seasarcon
Seasar ユーザだったプログラマが目指す OSS の世界展開 #seasarcon
 
Isomorphic web development with scala and scala.js
Isomorphic web development  with scala and scala.jsIsomorphic web development  with scala and scala.js
Isomorphic web development with scala and scala.js
 
ScalaでASICやFPGA用の回路を設計するChisel
ScalaでASICやFPGA用の回路を設計するChiselScalaでASICやFPGA用の回路を設計するChisel
ScalaでASICやFPGA用の回路を設計するChisel
 
Scala.jsはじめました!
Scala.jsはじめました!Scala.jsはじめました!
Scala.jsはじめました!
 
Scalaでのプログラム開発
Scalaでのプログラム開発Scalaでのプログラム開発
Scalaでのプログラム開発
 
Skinny Framework 進捗どうですか? #fud_scala
Skinny Framework 進捗どうですか? #fud_scalaSkinny Framework 進捗どうですか? #fud_scala
Skinny Framework 進捗どうですか? #fud_scala
 
株式会社インタースペース 沖本様 登壇資料
株式会社インタースペース 沖本様 登壇資料株式会社インタースペース 沖本様 登壇資料
株式会社インタースペース 沖本様 登壇資料
 
Dev love関西 forslideshare
Dev love関西 forslideshareDev love関西 forslideshare
Dev love関西 forslideshare
 
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql9/16 Tokyo Apache Drill Meetup - drill vs sparksql
9/16 Tokyo Apache Drill Meetup - drill vs sparksql
 
scala+liftで遊ぼう
scala+liftで遊ぼうscala+liftで遊ぼう
scala+liftで遊ぼう
 
Scala: Mobile Backend on AWS
Scala: Mobile Backend on AWSScala: Mobile Backend on AWS
Scala: Mobile Backend on AWS
 
Couch Db勉強会0623 by yssk22
Couch Db勉強会0623 by yssk22Couch Db勉強会0623 by yssk22
Couch Db勉強会0623 by yssk22
 
成長を加速する minne の技術基盤戦略
成長を加速する minne の技術基盤戦略成長を加速する minne の技術基盤戦略
成長を加速する minne の技術基盤戦略
 
Asset Pipeline for Perl
Asset Pipeline for PerlAsset Pipeline for Perl
Asset Pipeline for Perl
 
はじめよう Backbone.js
はじめよう Backbone.jsはじめよう Backbone.js
はじめよう Backbone.js
 
scala-kaigi1-sbt
scala-kaigi1-sbtscala-kaigi1-sbt
scala-kaigi1-sbt
 
HTML5-20100626
HTML5-20100626HTML5-20100626
HTML5-20100626
 
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方
サンプルアプリケーションで学ぶApache Cassandraを使ったJavaアプリケーションの作り方
 
First sass
First sassFirst sass
First sass
 
Scalaプロダクトのビルド高速化
Scalaプロダクトのビルド高速化Scalaプロダクトのビルド高速化
Scalaプロダクトのビルド高速化
 

More from takezoe

Journey of Migrating Millions of Queries on The Cloud
Journey of Migrating Millions of Queries on The CloudJourney of Migrating Millions of Queries on The Cloud
Journey of Migrating Millions of Queries on The Cloudtakezoe
 
GitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by ScalaGitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by Scalatakezoe
 
Testing Distributed Query Engine as a Service
Testing Distributed Query Engine as a ServiceTesting Distributed Query Engine as a Service
Testing Distributed Query Engine as a Servicetakezoe
 
Revisit Dependency Injection in scala
Revisit Dependency Injection in scalaRevisit Dependency Injection in scala
Revisit Dependency Injection in scalatakezoe
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationstakezoe
 
GitBucket: Git Centric Software Development Platform by Scala
GitBucket:  Git Centric Software Development Platform by ScalaGitBucket:  Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scalatakezoe
 
Non-Functional Programming in Scala
Non-Functional Programming in ScalaNon-Functional Programming in Scala
Non-Functional Programming in Scalatakezoe
 
Scala警察のすすめ
Scala警察のすすめScala警察のすすめ
Scala警察のすすめtakezoe
 
Scala製機械学習サーバ「Apache PredictionIO」
Scala製機械学習サーバ「Apache PredictionIO」Scala製機械学習サーバ「Apache PredictionIO」
Scala製機械学習サーバ「Apache PredictionIO」takezoe
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtendtakezoe
 
Macro in Scala
Macro in ScalaMacro in Scala
Macro in Scalatakezoe
 
Java9 and Project Jigsaw
Java9 and Project JigsawJava9 and Project Jigsaw
Java9 and Project Jigsawtakezoe
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3takezoe
 
markedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMmarkedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMtakezoe
 
Excel方眼紙を支えるJava技術 2015
Excel方眼紙を支えるJava技術 2015Excel方眼紙を支えるJava技術 2015
Excel方眼紙を支えるJava技術 2015takezoe
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scalatakezoe
 
Play2実践tips集
Play2実践tips集Play2実践tips集
Play2実践tips集takezoe
 
Scala界隈の近況
Scala界隈の近況Scala界隈の近況
Scala界隈の近況takezoe
 
そんなトランザクションマネージャで大丈夫か?
そんなトランザクションマネージャで大丈夫か?そんなトランザクションマネージャで大丈夫か?
そんなトランザクションマネージャで大丈夫か?takezoe
 
SIerでScalaを使うために私がしたこと
SIerでScalaを使うために私がしたことSIerでScalaを使うために私がしたこと
SIerでScalaを使うために私がしたことtakezoe
 

More from takezoe (20)

Journey of Migrating Millions of Queries on The Cloud
Journey of Migrating Millions of Queries on The CloudJourney of Migrating Millions of Queries on The Cloud
Journey of Migrating Millions of Queries on The Cloud
 
GitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by ScalaGitBucket: Open source self-hosting Git server built by Scala
GitBucket: Open source self-hosting Git server built by Scala
 
Testing Distributed Query Engine as a Service
Testing Distributed Query Engine as a ServiceTesting Distributed Query Engine as a Service
Testing Distributed Query Engine as a Service
 
Revisit Dependency Injection in scala
Revisit Dependency Injection in scalaRevisit Dependency Injection in scala
Revisit Dependency Injection in scala
 
How to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applicationsHow to keep maintainability of long life Scala applications
How to keep maintainability of long life Scala applications
 
GitBucket: Git Centric Software Development Platform by Scala
GitBucket:  Git Centric Software Development Platform by ScalaGitBucket:  Git Centric Software Development Platform by Scala
GitBucket: Git Centric Software Development Platform by Scala
 
Non-Functional Programming in Scala
Non-Functional Programming in ScalaNon-Functional Programming in Scala
Non-Functional Programming in Scala
 
Scala警察のすすめ
Scala警察のすすめScala警察のすすめ
Scala警察のすすめ
 
Scala製機械学習サーバ「Apache PredictionIO」
Scala製機械学習サーバ「Apache PredictionIO」Scala製機械学習サーバ「Apache PredictionIO」
Scala製機械学習サーバ「Apache PredictionIO」
 
The best of AltJava is Xtend
The best of AltJava is XtendThe best of AltJava is Xtend
The best of AltJava is Xtend
 
Macro in Scala
Macro in ScalaMacro in Scala
Macro in Scala
 
Java9 and Project Jigsaw
Java9 and Project JigsawJava9 and Project Jigsaw
Java9 and Project Jigsaw
 
Reactive database access with Slick3
Reactive database access with Slick3Reactive database access with Slick3
Reactive database access with Slick3
 
markedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVMmarkedj: The best of markdown processor on JVM
markedj: The best of markdown processor on JVM
 
Excel方眼紙を支えるJava技術 2015
Excel方眼紙を支えるJava技術 2015Excel方眼紙を支えるJava技術 2015
Excel方眼紙を支えるJava技術 2015
 
GitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by ScalaGitBucket: The perfect Github clone by Scala
GitBucket: The perfect Github clone by Scala
 
Play2実践tips集
Play2実践tips集Play2実践tips集
Play2実践tips集
 
Scala界隈の近況
Scala界隈の近況Scala界隈の近況
Scala界隈の近況
 
そんなトランザクションマネージャで大丈夫か?
そんなトランザクションマネージャで大丈夫か?そんなトランザクションマネージャで大丈夫か?
そんなトランザクションマネージャで大丈夫か?
 
SIerでScalaを使うために私がしたこと
SIerでScalaを使うために私がしたことSIerでScalaを使うために私がしたこと
SIerでScalaを使うために私がしたこと
 

Scala Warrior and type-safe front-end development with Scala.js

  • 1. Scala Warrior and type-safe front-end development with Scala.js Naoki Takezoe @takezoen BizReach, Inc Scala WarriorにおけるScala.jsとタイプセーフな フロントエンド開発
  • 2. Who am I? ● Scala Programmer at BizReach, Inc ● 4+ years Scala experience ● GitBucket author / Scalatra committer 株式会社ビズリーチに勤務するScalaプログラマです。 本を書いたりGitBucketやScalatraなどを開発しています。
  • 3. About Scala Warrior Scala Warriorについて
  • 4. Scala Warrior ● A game written in Scala for learning Scala ● Inspired by Ruby Warrior ● Based on Scala.js, ScalaTags and ScalaCSS https://github.com/scalawarrior/scalawarrior Scala学習用のWebベースのゲームです。 Scala.js、ScalaTags、ScalaCSSなどを使用しています。
  • 5. Motivation ● We wish Scala to become more popular programming language in Japan ● Activities we did for that since 2011: ○ Writing Scala books ○ Making hands-on tutorial for Play2 and Slick ○ Using Scala in real business systems 2011年頃からScalaの普及のための様々な活動を行ってきま した。
  • 6. But they were not enough... しかしまだ十分普及したとは言えません。
  • 8. Making learning fun ● Newbies are feeling difficulty in Scala more than necessary ● In fact, We can learn Scala step by step Scala初心者はScalaを必要以上に難しく感じています。 もっと楽しく気軽に学ぶことのできる方法が必要です。
  • 11. Team Takako Shimamoto Planning / Illustration Naoki Takezoe Programming Scala Warriorはこの2人で開発しました。
  • 12. Server (Play2) Architecture of Scala Warrior Web Browser Scala Warriorの仕組みを説明します。
  • 13. Server (Play2) Architecture of Scala Warrior Web Browser Scala 1. Send Scala code edited by user まず、ユーザが入力したScalaコードをサーバに送信
  • 14. Server (Play2) Architecture of Scala Warrior Web Browser Scala 2. Compile Scala code to JavaScript by Scala.js compiler 1. Send Scala code edited by user サーバでScala.jsコンパイラでJavaScriptコードを生成
  • 15. Server (Play2) Architecture of Scala Warrior Web Browser Scala JavaScript 2. Compile Scala code to JavaScript by Scala.js compiler 1. Send Scala code edited by user 生成したJavaScriptコードをブラウザに返却
  • 16. Server (Play2) Architecture of Scala Warrior Web Browser Scala JavaScript 2. Compile Scala code to JavaScript by Scala.js compiler 1. Send Scala code edited by user 3. Evaluate responded JavaScript code ブラウザ側で返却されたJavaScriptをeval()して評価
  • 17. JavaScript libraries Annimation is built on CreateJS Code editor is built on Ace アニメーションにはCreateJS、エディタにはAceを使用
  • 18. Made their Scala.js facade for Scala.js ● scalajs-ace ○ Ace is a powerful online code editor ○ But Scala Warrior hasn't used for several reasons ● scalajs-createjs ○ CreateJS is a suite of libraries to build rich interactive web contents これらのライブラリのScala.js用ファサードを作りました(でも Scala Warriorではscalajs-aceは使っていません)
  • 19. Great thanks for Li Haoyi's scala-js-fiddle! https://github.com/lihaoyi/scala-js-fiddle Li Haoyiさんのscala-js-fiddleを参考にさせていただきました。 ありがとうございます。
  • 20. Note ● Scala Warrior is a distinctive application taking advantage of Scala.js ● Uses Scala.js to compile Scala code entered by user ● Evaluates compiled code on the browser to protect the server Scala Warriorは実行時にScala.jsコンパイラを活用する特殊 なアプリケーションであることに注意してください。
  • 21. Type-safe frontend development with Scala.js Scala.jsによるタイプセーフなフロント開発について
  • 22. Typesafe front-end stack in Scala Scala Scala.js ScalaTags ScalaCSS scalajs-react Server-side Front-end
  • 23. Scala.js Scala Compiler ScalaJS Compiler Scala Code *.sjsir*.class Translate Scala code to JavaScript by Scala compiler plugin *.js optimize / package コンパイラプラグインでJavaScriptへの変換を行います。
  • 25. Scala.js is universal! Play project (server-side) Scala.js project (client-side) Cross-build project (common) Scalaとコードを共有することもできます。
  • 26. Interoperability ● Need type mapping like .d.ts ○ scala-js-ts-importer can convert from .d.ts ○ You can find a lot of .d.ts at DefinitelyTyped ○ But can't convert perfectly... ● js.Dynamic (not type-safe) import scala.scalajs.js.Dynamic._ val editor: Dynamic = global.ace.edit("editor") JavaScriptとの連携も完璧です。
  • 27. ScalaTags ● Type-safe XML/HTML generation library ● Scala and Scala.js support ScalaTagsはXMLやHTMLをScalaコードでタイプセーフに生 成するためのライブラリです。
  • 28. ScalaTags div(`class`:="modal", id:="gameOverModal", role:="dialog")( div(`class`:="modal-dialog")( div(`class`:="modal-content")( div(Styles.modalBody)( h4(`class`:="modal-title", "Game Over!") ), div(`class`:="modal-footer")( a( `href`:="/level/" + level, `class`:="btn btn-primary", "Retry this stage" ) ) ) ) ) ちょっと厳しい感じがあります。
  • 29. ScalaCSS ● Type-safe CSS generation library ● Scala and Scala.js support ● 2 different mode ○ Standalone mode ○ Inline mode ● ScalaTags and scala-react integration ScalaCSSは同じくCSSをScalaコードで生成するためのライブ ラリです。2つのモードがあります。
  • 30. ScalaCSS (Standalone mode) import scalacss.Defaults._ object Styles extends StyleSheet.Standalone { import dsl._ "h1" - ( fontSize(200 %%), fontWeight.bold ) "h2" - ( borderBottom(1 px, solid, black) ) "div.contents" - ( padding(4 px) ) } スタンドアロンモード。ここからCSSを生成できます。
  • 31. ScalaCSS (Inline mode) import scalacss.Defaults._ object Styles extends StyleSheet.Inline { import dsl._ val silkFont = fontFace("Silkscreen")( _.src("url(/assets/stylesheets/slkscr.ttf)") ) val silk = style( fontFamily(silkFont) ) val logo = style( verticalAlign.bottom, width(60 px), paddingBottom(14 px), silk ) } インラインモード。こんな感じでスタイルを定義しておき
  • 32. ScalaCSS (Inline mode) import scalacss.Defaults._ object Styles extends StyleSheet.Inline { import dsl._ val silkFont = fontFace("Silkscreen")( _.src("url(/assets/stylesheets/slkscr.ttf)") ) val silk = style( fontFamily(silkFont) ) val logo = style( verticalAlign.bottom, width(60 px), paddingBottom(14 px), silk ) } div( img( `class`:= Styles.logo.htmlClass, src:= "/assets/images/logo.png" ), "Scala Warrior" ) Compile-time reference checking class属性に埋めんで使います。
  • 33. JavaScript Framework Integration ● React ○ scalajs-recat ● AngularJS ○ scalajs-agular ○ angulate2 メジャーなJavaScriptフレームワークをScala.jsで利用するた めのライブラリもあります。
  • 37. Problems ● Generated JavaScript file size ● Cost for creating type mappings 問題もあります。
  • 38. Problems ● Generated JavaScript file size ● Cost for creating type mappings ● Should front-end engineers write Scala? 一番の問題はそもそもフロントエンジニアがScalaを書くべきな のか?ということです。
  • 39. The Approach Reference: Scala.js: Beyond the Coast-to-Coast Approach by Katrin Shechtman https://www.youtube.com/watch?v=aqtoe0xDayM 1つのアプローチを紹介します。
  • 40. The Approach Scala Scala.js (Interface for Frontend) User Interface (React or AngularJS?) Server-side Front-end
  • 41. The Approach Scala Scala.js (Interface for Frontend) User Interface (React or AngularJS?) Server-side Front-end JavaScript Programmer Scala Programmer JavaScript / Scalaプログラマでこのように分担します。
  • 42. Scala.js and JavaScript ecosystem 既存のJavaScriptのエコシステムとの連携について
  • 43. ● Add this line to build.sbt ● @JSExport annotated elements are expoted as CommonJS module Export Scala.js as CommonJS module scalaJSModuleKind := ModuleKind.CommonJSModule CommonJSモジュールとしてエクスポートできます。
  • 44. Export Scala.js as CommonJS module import scala.scalajs.js import js.annotation._ @ScalaJSDefined @JSExport("HelloWorld") class HelloWorld extends js.Object { def sayHello(name: String): String = s"Hello ${name}!" } var hello = require("./hello-fastopt.js") var helloWorld = new hello.HelloWorld(); console.log(helloWorld.sayHello("Scala.js")); Scala.js JavaScript
  • 45. Use CommonJS module in Scala.js import scala.scalajs.js import js.annotation._ @js.native @JSImport("./hello-fastopt.js", "HelloWorld") class HelloWorld extends js.Object { def sayHello(name: String): String = js.native } Scala.jsでCommonJSモジュールを使うこともできます。
  • 47. Why Scala in frontend? ● Scala.js is not ALL or NOTHING! ○ Scala programmers can provide libraries for frontend using Scala.js ○ JavaScript programmer can use existing frontend tools and frameworks 全部Scala.jsで作らないといけないわけではありません。 適切な役割分担によってScalaのメリットを活かせます。
  • 48. Enjoy type-safe frontend web development with Scala.js! Scala.jsはタイプセーフな"フロント"開発ではなくタイプセーフ な"Web"開発におすすめです。
  • 49. ...and try Scala Warrior! https://github.com/scalawarrior/scalawarrior Scala Warriorも是非試してみてください。