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
390
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
650
Other Decks in Programming
See All in Programming
DMMプラットフォームにおけるTiDBの導入から運用まで
pospome
7
3k
CSC307 Lecture 10
javiergs
PRO
0
310
みんなのオブザーバビリティプラットフォームを作ってるんだがパフォーマンスがやばい #mackerelio #srenext
ne_sachirou
0
370
Clean Architecture by TypeScript & NestJS
ryounasso
0
150
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
Temporalを取り巻く仕様を整理する
sajikix
0
110
CSC307 Lecture 09
javiergs
PRO
1
500
유연한 Composable 설계
l2hyunwoo
0
380
TiDB Serverless ~理想のServerless DBを考える~
soso_15315
1
160
SDCon2024: Enabling DevOps and Team Topologies thru architecture: architecting for fast flow
cer
PRO
0
780
生成AIをkintoneに連携してみた
hideg
0
230
CSC307 Lecture 13
javiergs
PRO
0
150
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
25
6.7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
248
20k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
26
1.6k
Robots, Beer and Maslow
schacon
PRO
157
8.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
23
1.9k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
360
22k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
35
6.3k
How to Think Like a Performance Engineer
csswizardry
4
590
Raft: Consensus for Rubyists
vanstee
134
6.5k
Making Projects Easy
brettharned
111
5.7k
Rails Girls Zürich Keynote
gr2m
93
13k
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
ありがとうございました