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
TCAにおける副作用の分離
Search
Yuya Okuse
March 18, 2024
0
1.2k
TCAにおける副作用の分離
2024/03/18開催の【iOS】TCAでわいわいLT会における発表資料です。
https://uzabase-tech.connpass.com/event/309323/
Yuya Okuse
March 18, 2024
Tweet
Share
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
94
14k
Git: the NoSQL Database
bkeepers
PRO
430
65k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
470
How to Ace a Technical Interview
jacobian
276
23k
Automating Front-end Workflow
addyosmani
1370
200k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
650
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
770
4 Signs Your Business is Dying
shpigford
183
22k
How to train your dragon (web standard)
notwaldorf
92
6.1k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Practical Orchestrator
shlominoach
188
11k
Transcript
1 Yuya Okuse TCAにおける副作用の分離 TCAでわいわいLT会 Yuya Okuse Yuya Okuse 2024/03/18
自己紹介 2 • Yuya Okuse • 株式会社ディー・エヌ・エー23新卒 • SWET 第二グループ
• iOS アプリエンジニア(Swift) ◦ 2023/07 ~ • TCA ◦ 2024/02 ~
お話すること 3 TCA における副作用の分離
TCA • The Composable Architecture • 以下の課題を解決: ◦ State management
◦ Composition ◦ Side effect ◦ Testing ◦ Ergonomics 4 https://github.com/pointfreeco/swift-composable-architecture
TCA • The Composable Architecture • 以下の課題を解決: ◦ State management
◦ Composition ◦ Side effect ◦ Testing ◦ Ergonomics 5 https://github.com/pointfreeco/swift-composable-architecture
Personal Access Token による GitHub ログイン 6
非同期処理が実行できない 7 Cannot pass function of type '(inout LoginFeature.State, LoginFeature.Action)
async -> Effect<LoginFeature.Action>' to parameter expecting synchronous function type Error:
非同期処理が実行できない 8 クロージャでは非同期関数が使用できない
非同期処理を実行するために 9 クロージャ内で非同期関数を実行可能
可変な変数をキャプチャできない 10 Mutable capture of 'inout' parameter 'state' is not
allowed in concurrently-executing code Error:
Reduce struct と static func run 定義 11 inout 引数
@Sendable
可変な変数をキャプチャできない 12 Mutable capture of 'inout' parameter 'state' is not
allowed in concurrently-executing code Error:
13 成功時 失敗時
状態(State)の変化 14
副作用 15
16 TCA はコンパイルの段階で、 副作用に伴う状態の変化と副作用を分離 副作用の分離
副作用が分離されたことによる利点 17 • 副作用に対する状態変化の把握が容易 • Reducer 内に状態管理を限定することで、 意図しない(未知の)状態変化が起きない 状態管理が容易
状態(State)の変化 18
副作用が分離されたことによる利点 19 • 副作用に伴う 状態の更新(UI 変更)ロジックが 疎結合であるため、テストが容易 ◦ https://github.com/pointfreeco/swift-dependencies •
副作用を含むロジックは、独立して単体テスト が可能。 テスト容易性の向上
まとめ 20 TCA はコンパイルの段階で、 副作用に伴う状態の変化と副作用 を分離