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
一緒に働きたくなるプログラマの思想 #QiitaConference
mu_zaru
81
21k
KANNA Android の技術的課題と取り組み
watabee
1
450
fieldalignmentから見るGoの構造体
kuro_kurorrr
0
140
「理解」を重視したAI活用開発
fast_doctor
0
300
Global Azure 2025 @ Kansai / Hyperlight
kosmosebi
0
140
知識0からカンファレンスやってみたらこうなった!
syossan27
4
130
Optimizing JRuby 10
headius
0
590
iOSアプリで測る!名古屋駅までの 方向と距離
ryunakayama
0
160
Beyond_the_Prompt__Evaluating__Testing__and_Securing_LLM_Applications.pdf
meteatamel
0
110
Orleans + Sekiban + SignalR でリアルタイムWeb作ってみた
tomohisa
0
240
Embracing Ruby magic
vinistock
2
230
七輪ライブラリー: Claude AI で作る Next.js アプリ
suneo3476
1
190
Featured
See All Featured
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
10
790
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
420
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.5k
Docker and Python
trallard
44
3.4k
BBQ
matthewcrist
88
9.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.7k
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
ありがとうございました