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.5k
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
400
Elm でユーザーストーリーマッピングのツールを作ってみた
jinjor
0
1k
Elm 開発サンプル
jinjor
1
1.1k
Friendly Elm (怖くないElm)
jinjor
3
1.7k
Elmのさわれる副作用
jinjor
2
1.1k
Let's learn Elm
jinjor
3
660
Other Decks in Programming
See All in Programming
Composing an API the *right* way (Droidcon New York 2024)
zsmb
2
120
LangChainでWebサイトの内容取得やGitHubソースコード取得
shukob
0
160
Amazon BedrockでサーバレスなAIお料理ボットを作成する!!
tosuri13
0
230
全部見せます! クラシルリワードのSwiftTesting移行プロジェクト
uetyo
0
210
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
170
Shinjuku.rb#95:心の技術書紹介
free_world21
1
110
2024 컴포즈 정원사
jisungbin
0
150
RAGの回答精度評価用のQAデータセットを生成AIに作らせた話
kurahara
0
250
Jakarta EE meets AI
ivargrimstad
1
520
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
490
Go1.23で入った errorsパッケージの小さなアプデ
kuro_kurorrr
2
390
Modular Monolith Go Server with GraphQL Federation + gRPC
110y
1
590
Featured
See All Featured
Statistics for Hackers
jakevdp
794
220k
Navigating Team Friction
lara
183
13k
Building Flexible Design Systems
yeseniaperezcruz
325
38k
How STYLIGHT went responsive
nonsquared
93
5.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
653
58k
Fantastic passwords and where to find them - at NoRuKo
philnash
48
2.8k
KATA
mclloyd
27
13k
[RailsConf 2023] Rails as a piece of cake
palkan
48
4.6k
Building Adaptive Systems
keathley
36
2.1k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
354
29k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Side Projects
sachag
451
42k
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
ありがとうございました