Elmish / F#
SAFE Stack による Web 開発
T. Midorikawa a.k.a midoliy
• 大阪府 大阪市
• C# / F# 愛の伝道師 (非公式)
• Twitter: @ _midoliy_
• GitHub: @ Midoliy
• HP: https://midoliy.com
• Youtube: https://www.youtube.com/user/dgakusei
• 大阪 F# もくもく会 主催: https://oosakafs-moku2.connpass.com
What is SAFE Stack ?
• Fableを使ってSPAを作成するためのプロジェクトテンプレート
Saturn ・・・ バックエンドサービス用 F# ライブラリ.
Azure ・・・ いわずもがなの Microsoft Azure.
Fable ・・・ Babel を搭載した F# → Javascript コンパイラ.
Elmish ・・・ 本日の主役. F# で UI を記述するためのフレームワー
ク.
SAFE Stack 構成図
(引用元) https://safe-stack.github.io/docs/overview/
What is Elmish ?
• Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー
ク
UpdateView
UI
The Elm Architecture (MVU)
HTML Message
Create
New Model
Model
The Elm Architecture (MVU)
What is Elmish ?
• Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー
ク
UpdateView
UI
HTML Message
Create
New Model
Model
View → UI
let view (model : Model) (dispatch : Msg -> unit) =
div []
[ Navbar.navbar [ Navbar.Color IsPrimary ]
[ Navbar.Item.div [ ]
[ Heading.h2 [ ]
[ str "SAFE Template" ] ] ]
Container.container []
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ]
Columns.columns []
[ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ]
Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ]
Footer.footer [ ]
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ safeComponents ] ] ]
View → UI
let view (model : Model) (dispatch : Msg -> unit) =
div []
[ Navbar.navbar [ Navbar.Color IsPrimary ]
[ Navbar.Item.div [ ]
[ Heading.h2 [ ]
[ str "SAFE Template" ] ] ]
Container.container []
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ]
Columns.columns []
[ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ]
Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ]
Footer.footer [ ]
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ safeComponents ] ] ]
<nav class="navbar is-primary">
<div class="navbar-item">
<h2 class="title is-2">SAFE Template</h2>
</div>
</nav>
View → UI
View → UI
Container.container []
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ]
Columns.columns []
[ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ]
Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ]
<div class="container">
<div class="content has-text-centered">
<h3 class="title is-3">Press buttons to manipulate counter: 42</h3>
</div>
<div class="columns">
<div class="column">
<button class="button is-primary is-fullwidth">-</button>
</div>
<div class="column">
<button class="button is-primary is-fullwidth">+</button>
</div>
</div>
</div>
View → UI
Container.container []
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ]
Columns.columns []
[ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ]
Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ]
UI → Update
The Elm Architecture (MVU)
What is Elmish ?
• Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー
ク
UpdateView
UIHTML Message
Create
New Model
Model
View → UI & UI → Update
The Elm Architecture (MVU)
What is Elmish ?
• Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー
ク
UpdateView
UI
HTML Message
Create
New Model
Model
Update → View
let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
match currentModel.Counter, msg with
| Some counter, Increment ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } }
nextModel, Cmd.none
| Some counter, Decrement ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } }
nextModel, Cmd.none
| _, InitialCountLoaded initialCount ->
let nextModel = { Counter = Some initialCount }
nextModel, Cmd.none
| _ -> currentModel, Cmd.none
Update → View
let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
match currentModel.Counter, msg with
| Some counter, Increment ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } }
nextModel, Cmd.none
| Some counter, Decrement ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } }
nextModel, Cmd.none
| _, InitialCountLoaded initialCount ->
let nextModel = { Counter = Some initialCount }
nextModel, Cmd.none
| _ -> currentModel, Cmd.none
Update → View
let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> =
match currentModel.Counter, msg with
| Some counter, Increment ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } }
nextModel, Cmd.none
| Some counter, Decrement ->
let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } }
nextModel, Cmd.none
| _, InitialCountLoaded initialCount ->
let nextModel = { Counter = Some initialCount }
nextModel, Cmd.none
| _ -> currentModel, Cmd.none
View → UI
let view (model : Model) (dispatch : Msg -> unit) =
div []
[ Navbar.navbar [ Navbar.Color IsPrimary ]
[ Navbar.Item.div [ ]
[ Heading.h2 [ ]
[ str "SAFE Template" ] ] ]
Container.container []
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ]
Columns.columns []
[ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ]
Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ]
Footer.footer [ ]
[ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ]
[ safeComponents ] ] ]
まとめ
• Elmish = F# で Web開発するためのイケてるライブラリ
• Reactが下で動作しているので、実行効率もそこまで悪くない
• サーバ側と型を共有できるので、型安全にコーディング可能
• 関数型プログラミングでバグり難い開発を!
ご清聴ありがとうございまし
た

More Related Content

DOCX
Java script slideshow by karan chanana
PDF
djangoのmigrationはどう動いているか
PDF
Jquery presentation
PDF
WooCommerce: Conditional Logic
PDF
Game jump: frontend introduction #1
PDF
Rethink Frontend Development With Elm
PDF
Idioms in swift 2016 05c
PDF
Tech fest
Java script slideshow by karan chanana
djangoのmigrationはどう動いているか
Jquery presentation
WooCommerce: Conditional Logic
Game jump: frontend introduction #1
Rethink Frontend Development With Elm
Idioms in swift 2016 05c
Tech fest

Recently uploaded (20)

PPTX
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
Feature types and data preprocessing steps
PPTX
Software Engineering and software moduleing
PDF
Java Basics-Introduction and program control
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
Amdahl’s law is explained in the above power point presentations
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PDF
MLpara ingenieira CIVIL, meca Y AMBIENTAL
PDF
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PPTX
Principal presentation for NAAC (1).pptx
PPTX
ai_satellite_crop_management_20250815030350.pptx
PPTX
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
PPTX
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
PDF
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
PPTX
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Chapter 2 -Technology and Enginerring Materials + Composites.pptx
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
Feature types and data preprocessing steps
Software Engineering and software moduleing
Java Basics-Introduction and program control
Soil Improvement Techniques Note - Rabbi
Amdahl’s law is explained in the above power point presentations
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
MLpara ingenieira CIVIL, meca Y AMBIENTAL
Prof. Dr. KAYIHURA A. SILAS MUNYANEZA, PhD..pdf
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
August -2025_Top10 Read_Articles_ijait.pdf
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
Principal presentation for NAAC (1).pptx
ai_satellite_crop_management_20250815030350.pptx
tack Data Structure with Array and Linked List Implementation, Push and Pop O...
Graph Data Structures with Types, Traversals, Connectivity, and Real-Life App...
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
Chemical Technological Processes, Feasibility Study and Chemical Process Indu...
Ad
Ad

dotnetConf2019 meetup in AICHI / Elmish

  • 1. Elmish / F# SAFE Stack による Web 開発
  • 2. T. Midorikawa a.k.a midoliy • 大阪府 大阪市 • C# / F# 愛の伝道師 (非公式) • Twitter: @ _midoliy_ • GitHub: @ Midoliy • HP: https://midoliy.com • Youtube: https://www.youtube.com/user/dgakusei • 大阪 F# もくもく会 主催: https://oosakafs-moku2.connpass.com
  • 3. What is SAFE Stack ? • Fableを使ってSPAを作成するためのプロジェクトテンプレート Saturn ・・・ バックエンドサービス用 F# ライブラリ. Azure ・・・ いわずもがなの Microsoft Azure. Fable ・・・ Babel を搭載した F# → Javascript コンパイラ. Elmish ・・・ 本日の主役. F# で UI を記述するためのフレームワー ク.
  • 4. SAFE Stack 構成図 (引用元) https://safe-stack.github.io/docs/overview/
  • 5. What is Elmish ? • Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー ク UpdateView UI The Elm Architecture (MVU) HTML Message Create New Model Model
  • 6. The Elm Architecture (MVU) What is Elmish ? • Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー ク UpdateView UI HTML Message Create New Model Model
  • 7. View → UI let view (model : Model) (dispatch : Msg -> unit) = div [] [ Navbar.navbar [ Navbar.Color IsPrimary ] [ Navbar.Item.div [ ] [ Heading.h2 [ ] [ str "SAFE Template" ] ] ] Container.container [] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ] Columns.columns [] [ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ] Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ] Footer.footer [ ] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ safeComponents ] ] ]
  • 8. View → UI let view (model : Model) (dispatch : Msg -> unit) = div [] [ Navbar.navbar [ Navbar.Color IsPrimary ] [ Navbar.Item.div [ ] [ Heading.h2 [ ] [ str "SAFE Template" ] ] ] Container.container [] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ] Columns.columns [] [ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ] Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ] Footer.footer [ ] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ safeComponents ] ] ] <nav class="navbar is-primary"> <div class="navbar-item"> <h2 class="title is-2">SAFE Template</h2> </div> </nav>
  • 10. View → UI Container.container [] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ] Columns.columns [] [ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ] Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ] <div class="container"> <div class="content has-text-centered"> <h3 class="title is-3">Press buttons to manipulate counter: 42</h3> </div> <div class="columns"> <div class="column"> <button class="button is-primary is-fullwidth">-</button> </div> <div class="column"> <button class="button is-primary is-fullwidth">+</button> </div> </div> </div>
  • 11. View → UI Container.container [] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ] Columns.columns [] [ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ] Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ] UI → Update
  • 12. The Elm Architecture (MVU) What is Elmish ? • Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー ク UpdateView UIHTML Message Create New Model Model
  • 13. View → UI & UI → Update
  • 14. The Elm Architecture (MVU) What is Elmish ? • Elmスタイルの 「Model - View - Update」アーキテクチャをサポートするフレームワー ク UpdateView UI HTML Message Create New Model Model
  • 15. Update → View let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> = match currentModel.Counter, msg with | Some counter, Increment -> let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } } nextModel, Cmd.none | Some counter, Decrement -> let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } } nextModel, Cmd.none | _, InitialCountLoaded initialCount -> let nextModel = { Counter = Some initialCount } nextModel, Cmd.none | _ -> currentModel, Cmd.none
  • 16. Update → View let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> = match currentModel.Counter, msg with | Some counter, Increment -> let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } } nextModel, Cmd.none | Some counter, Decrement -> let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } } nextModel, Cmd.none | _, InitialCountLoaded initialCount -> let nextModel = { Counter = Some initialCount } nextModel, Cmd.none | _ -> currentModel, Cmd.none
  • 17. Update → View let update (msg : Msg) (currentModel : Model) : Model * Cmd<Msg> = match currentModel.Counter, msg with | Some counter, Increment -> let nextModel = { currentModel with Counter = Some { Value = counter.Value + 1 } } nextModel, Cmd.none | Some counter, Decrement -> let nextModel = { currentModel with Counter = Some { Value = counter.Value - 1 } } nextModel, Cmd.none | _, InitialCountLoaded initialCount -> let nextModel = { Counter = Some initialCount } nextModel, Cmd.none | _ -> currentModel, Cmd.none
  • 18. View → UI let view (model : Model) (dispatch : Msg -> unit) = div [] [ Navbar.navbar [ Navbar.Color IsPrimary ] [ Navbar.Item.div [ ] [ Heading.h2 [ ] [ str "SAFE Template" ] ] ] Container.container [] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ Heading.h3 [] [ str ("Press buttons to manipulate counter: " + show model) ] ] Columns.columns [] [ Column.column [] [ button "-" (fun _ -> dispatch Decrement) ] Column.column [] [ button "+" (fun _ -> dispatch Increment) ] ] ] Footer.footer [ ] [ Content.content [ Content.Modifiers [ Modifier.TextAlignment (Screen.All, TextAlignment.Centered) ] ] [ safeComponents ] ] ]
  • 19. まとめ • Elmish = F# で Web開発するためのイケてるライブラリ • Reactが下で動作しているので、実行効率もそこまで悪くない • サーバ側と型を共有できるので、型安全にコーディング可能 • 関数型プログラミングでバグり難い開発を!