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
1k
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
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
GraphQLとの向き合い方2022年版
quramy
44
13k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
30
2.1k
How STYLIGHT went responsive
nonsquared
96
5.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
11
900
The Cult of Friendly URLs
andyhume
78
6.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
How to Ace a Technical Interview
jacobian
276
23k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.3k
KATA
mclloyd
29
14k
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 はコンパイルの段階で、 副作用に伴う状態の変化と副作用 を分離