Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
複雑なアプリを Redux + MVVMで 完璧に制御する
Search
ANDPAD inc
April 07, 2021
Programming
360
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
複雑なアプリを Redux + MVVMで 完璧に制御する
2021/03/24 ANDPAD TechLive #8 iOS/AndroidアプリエンジニアTalk!!
ANDPAD inc
April 07, 2021
More Decks by ANDPAD inc
See All by ANDPAD inc
R8 の設定見直しでアプリサイズ削減
andpad
0
190
Go 探無比ワークショップ開催レポート
andpad
0
87
self-service-infrastructure-with-argocd-and-atlantis
andpad
0
12
実行場所を意識させない i18n API を作った話
andpad
1
240
Go 1.27 における memory allocation の高速化
andpad
0
430
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
220
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
160
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
620
ANDPAD Ruby sponsor session in RubyKaigi 2026
andpad
0
300
Other Decks in Programming
See All in Programming
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
460
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
210
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
120
Are APIs Still Relevant in the AI Era?
soyuka
0
440
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
570
速習iPhone Duo対応
yuukiw00w
2
970
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
120
[2026-09-26]空論ジェネリックプロセス~テスト資産とAIで紡ぐ、再現可能なパフォーマンスチューニングの話~
tosite
0
260
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
500
コードで差別化できない時代の ソフトウェアエンジニアリング / Software Engineering in an Era Where Code Doesn’t Differentiate
kishida
2
100
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.9k
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.6k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
550
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
How STYLIGHT went responsive
nonsquared
100
6.3k
A designer walks into a library…
pauljervisheath
211
25k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Exploring anti-patterns in Rails
aemeredith
4
520
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
510
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
580
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
510
Transcript
複雑なアプリを Redux + MVVMで 完璧に制御する Android/iOS/Flutter
自己紹介 柿森 隆生(Kakimori Takao) 2021/03/01 join Qiita: Urotea github: Urotea
興味のあるもの: rust, go, Flutter, Android, iOS, k8s, GCP, react 最近のトレンド: Flutter2.0面白そう 一言で表すなら: Redux芸人
宣伝 Android + Reduxアーキテクチャで状態管理が容易になった話 https://qiita.com/Urotea/items/8cbc8f55406b6ff32bbd Reduxの記事 on Qiita 本日の話でReduxに興味を持った方は是非
今回のお話 1 複雑なアプリはなぜ複雑なのか 2 複雑なものは抽象化して簡単にする 3 複雑なものをReduxで制御する 4 MVVMとReduxでアプリを制御する
結論 Reduxを使うと... - テストがしやすい - 複雑なアプリが整理される - 保守しやすくなる - レビューしやすい
0 Reduxって何?
アプリの状態管理に特化 したフレームワーク
引用: https://www.webopixel.net/javascript/1601.html 1. アプリ外部からのイベントが発火 2. 状態を書き換える 3. 状態が新しくなる 4. 画面に反映される
1 複雑なアプリはなぜ複雑なのか
複雑なアプリはなぜ複雑なのか 画面が多いから? 通信が多いから? 入力項目が多いから? 権限等ルールが多いから?
複雑なアプリはなぜ複雑なのか アプリの状態が複雑 画面が多いから 通信が多いから 入力項目が多いから? 権限等ルールが多いから
2 複雑なものは抽象化して簡単にする
アプリを抽象化して考える
アプリを抽象化して考える
これがアプリ
これがアプリ Action Action Action Action Action Reducer Reducer Reducer Reducer
Reducer State State State
3 複雑なものをReduxで制御する
Reduxで状態遷移を考える まずは簡単な状態遷移 State State Action Reducer
Reduxで状態遷移を考える まずは簡単な状態遷移 State State Action Reducer
これがRedux fun main(args: Array<String>) { val oldState = AppState(loggedIn =
false) val newState = loginReducer(oldState, Action.LoginCompleted) print(newState) } sealed class Action { object LoginCompleted: Action() {} } data class AppState(val loggedIn: Boolean) fun loginReducer(oldState: AppState, action: Action): AppState { return when(action) { is Action.LoginCompleted -> oldState.copy(loggedIn = true) } } State State Action Reducer
Reduxはテストが容易 fun main(args: Array<String>) { val oldState = AppState(loggedIn =
false) val newState = loginReducer(oldState, Action.LoginCompleted) print(newState) } sealed class Action { object LoginCompleted: Action() {} } data class AppState(val loggedIn: Boolean) fun loginReducer(oldState: AppState, action: Action): AppState { return when(action) { is Action.LoginCompleted -> oldState.copy(loggedIn = true) } } ただのオブジェクト ただのオブジェクト ただの純関数
まとめ アプリとは状態遷移機械である
まとめ Reduxは状態遷移機械を 記述するフレームワーク middlewareなどの細かい話は別の機会に
あれ?Viewはどこにいった?
Reduxは状態遷移機械を 記述するフレームワーク
Viewは専門外 別の仕組みでなんとかする!
4 MVVMとReduxでアプリを制御する
MVVM Model-View-ViewModel
MVVM 引用: https://developer.android.com/jetpack/guide?hl=ja View ViewModel Model
MVVM View ViewModel Model 画面を操作する場所 画面の状態を管理する場所 それ以外 - API通信 -
DB永続化 - ビジネスロジック
MVVM Viewを跨ぐ状態はどうする?
MVVM Viewに現れない状態はどうする?
MVVM View以外は専門外 別の仕組みでなんとかする!
MVVM + Redux Redux
MVVM Reduxを抽象化 oldState newState Action Reducer subscribe(Rx or coroutine) data
binding Redux
MVVM Reduxの具体例 oldState newState Action Reducer subscribe(Rx, coroutine) data binding
Redux View ViewModel Reducer ログインボタン クリック ログイン Action ログイン 完了状態 ・ボタンAを非表示 ・テキストBを表示
実際の言語ではどうする? iOS: ReSwift, RxSwift, RxCocoa Android: ReKotlin, Coroutine, DataBinding Flutter:
flutter_redux
詳しくは こんな所にReduxの記事とリポジトリが! Qiita: https://qiita.com/Urotea/items/8cbc8f55406b6ff32bbd Github: https://github.com/Urotea/flutter_template, https://github.com/Urotea/flutter_nfc_sample, https://github.com/Urotea/android-sample-app
で、実際のところどうなの? Q: プロダクションでの活用事例は? A: 開発人数2人。期間3カ月。WebViewやセンサに触りまくるアプリで実績あります。 Reduxに助けられっぱなしでした(ので、今話してます)。 Q: どのくらいの規模から使用したほうがよい? A: 保守しないなら不要。それ以外では検討価値あり。
Q: メリットは分かった。デメリットは? A: 初期学習コストが少々高い。Redux + Rx + モバイル特有の知識が要求される。 Q: Reduxって記述量やファイル数が増えて大変じゃない? A: 記述量が多いことはコーディングにおいて大した問題じゃない。 役割ごとにファイルが分割されることは gitを前提にするとメリット。