Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Elm for React.js Users
Search
Yosuke Torii
February 23, 2016
Programming
5
2.7k
Elm for React.js Users
React.js Meetup #3 での発表資料。Elmの簡単な紹介です。
Yosuke Torii
February 23, 2016
Tweet
Share
More Decks by Yosuke Torii
See All by Yosuke Torii
TEA++
jinjor
2
430
Elm でユーザーストーリーマッピングのツールを作ってみた
jinjor
0
1.1k
Elm 開発サンプル
jinjor
1
1.1k
Friendly Elm (怖くないElm)
jinjor
3
1.8k
Elmのさわれる副作用
jinjor
2
1.2k
Let's learn Elm
jinjor
3
680
Other Decks in Programming
See All in Programming
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
API for docs
soutaro
3
1.6k
2ヶ月で生産性2倍、お買い物アプリ「カウシェ」4チーム同時改善の取り組み
ike002jp
1
110
KANNA Android の技術的課題と取り組み
watabee
0
190
By the way Google Cloud Next 2025に行ってみてどうだった
ymd65536
0
110
The Evolution of the CRuby Build System
kateinoigakukun
1
760
Носок на сок
bo0om
0
1.1k
flutter_kaigi_mini_4.pdf
nobu74658
0
140
The Implementations of Advanced LR Parser Algorithm
junk0612
1
1.3k
一緒に働きたくなるプログラマの思想 #QiitaConference
mu_zaru
78
20k
eBPF超入門「o11yに使える」とは (20250424_eBPF_o11y)
thousanda
1
110
Jakarta EE Meets AI
ivargrimstad
0
780
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
33
6.6k
Designing Experiences People Love
moore
142
24k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.4k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
2.9k
Done Done
chrislema
184
16k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
179
53k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Agile that works and the tools we love
rasmusluckow
329
21k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
690
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.3k
Transcript
React.js ユーザのための Elm 2016/02/23 Yosuke Torii
・鳥居 陽介 ・株式会社ワークスアプリケーションズ勤務 ・ CodeZine に 5 記事 (React.js, HTTP/2, Elm)
・ジンジャー研究室 誰? @jinjor
Elm の紹介
main = span [class "message"] [text "Hello, World!"] ・関数型言語 ・静的型付き言語
・ JavaScript にコンパイルされる ・ 2012 年誕生 Elm is 何?
React.js Elm なぜ React.js Meetup で Elm ? ?
React.js Flux Elm と一緒に使われる アーキテクチャの なぜ React.js Meetup で Elm
? ?
React.js Flux Elm Redux と一緒に使われる アーキテクチャの で有名な ライブラリの なぜ React.js
Meetup で Elm ? ?
React.js Flux Elm Redux と一緒に使われる アーキテクチャの で有名な ライブラリの が参考にしたと 言われる
なぜ React.js Meetup で Elm ? ?
React.js/Flux を追っている人なら Elm を楽しめるはず!
フロントエンド界隈で人気急上昇 2015 年内に 3 倍の伸び http://elm-lang.org/blog/new-adventures-for-elm
最近の Elm Virtual DOM の導入 The Elm Architecture
Virtual DOM の導入
VDOM の生成コストを抑えたい Old VDOM New VDOM diff
VDOM の生成コストを抑えたい Old Model Old VDOM New Model New VDOM
diff diff ・ Model 同士を比較したい ・ shouldComponentUpdate() ・ Immutable.js
VDOM の生成コストを抑えたい Old Model Old VDOM New Model New VDOM
diff diff ・ Model 同士を比較したい ・ shouldComponentUpdate() ・ Immutable.js Elm では全てのデータが Immutable
Elm の描画は速い ※2014 年当時
The Elm Architecture
Elm は FRP 言語 ・ FRP = Functional Reactive Programming
(関数型リアクティブプログラミング) ・ JS ライブラリでは RxJS, Bacon.js, Kefier など
Elm は FRP 言語 Time a 2 1 Signal: 時間とともに変化する値
Elm は FRP 言語 Time a 2 1 Time b
4 2 map (*2) Signal: 時間とともに変化する値
例:クリック回数を出力する Time Time mouse clicks count 2 1 Time HTML
<div> 1 </div> <div> 2 </div> map foldp
Elm アプリケーションの構造 mouse position HTML mouse clicks keydown Enter ?
アクションの Signal を 最終的に HTML の Signal に変換するのが目的
設計方針がないとカオスに mouse position mouse clicks keydown Enter HTML ? ?
? ? ? ? ? ? ?
The Elm Architecture ・ Elm 公式で推しているアーキテクチャ ・ Redux にインスピレーションを与えた ・
GitHub のチュートリアルが人気(★ 1774 )
The Elm Architecture ・ Elm 公式で推しているアーキテクチャ ・ Redux にインスピレーションを与えた ・
GitHub のチュートリアルが人気(★ 1774 ) 去年の 11 月
Elm Architecture に従うと Action View Model
Elm Architecture に従うと Action View Model しかも、 開発者は Signal をほとんど意識しなくていい
コードが見たい
カウンターを作る
カウンターを作る import StartApp.Simple exposing (start) main = start { model
= model, update = update, view = view } 初期状態 状態を更新 する関数 HTML 描画 する関数
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ]
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] 初期状態
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] 初期状態 アクションの種類
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] 初期状態 アクションの種類 アクションの種類に 応じて状態を更新
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] 初期状態 アクションの種類 アクションの種類に 応じて状態を更新 状態に対応する HTML を生成
model = 0 type Action = Increment | Decrement update
action model = case action of Increment -> model + 1 Decrement -> model - 1 view address model = div [ ] [ button [ onClick address Decrement ] [ text "-" ] , span [ ] [ text (toString model) ] , button [ onClick address Increment ] [ text "+" ] ] 初期状態 アクションの種類 アクションの種類に 応じて状態を更新 状態に対応する HTML を生成
Model Model 複雑なケースは Tutorial で ・コンポーネントの階層化 ・非同期通信するコンポーネント Action View Model
Action View Model Effect Action Action View View
改めて Elm の良さ
膨大なスタックを必要としない React TypeScript Fluxible FluxUtils virtual-dom Immutable.js Redux Flow Browserify
Gulp react-tools Babel ES6 JSX webpack (start-app) elm-html (Gulp) JS Elm
静的型付け最高 ・基本的にランタイムエラーが起きない ・超絶リファクタリングしてもバグらない ・アーキテクチャをきちんと守れる
本番で使えるの? ・覚悟の問題 ・まずは社内で 社内ビデオ通話アプリ
Elm をはじめるには ・ Elm 公式 http://elm-lang.org/ ・ The Elm Architecture
https://github.com/evancz/elm-architecture-tutorial ・関数型リアクティブプログラミング言語 Elm に学ぶ フロントエンド開発の 新しい形 ( CodeZine ) 【前編】 http://codezine.jp/article/detail/8873 【後編】 http://codezine.jp/article/detail/8986 ・ Elm Advent Calendar 2014 http://qiita.com/advent-calendar/2014/elm ・ Elm Advent Calendar 2015 http://qiita.com/advent-calendar/2015/elm
ありがとうございました