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
複雑なアプリを Redux + MVVMで 完璧に制御する
Search
ANDPAD inc
April 07, 2021
Programming
3
320
複雑なアプリを Redux + MVVMで 完璧に制御する
2021/03/24 ANDPAD TechLive #8 iOS/AndroidアプリエンジニアTalk!!
ANDPAD inc
April 07, 2021
Tweet
Share
More Decks by ANDPAD inc
See All by ANDPAD inc
プロダクト開発を支えるデータ利活用:中央集権から「民主化」までの軌跡
andpad
0
110
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
350
読もう! Android build ドキュメント
andpad
1
430
アンドパッドにおける CocoaPods ライブラリ群の SwiftPackageManager への移行戦略
andpad
0
200
Flutter は DCM が 9 割
andpad
1
340
Amplify で SPA をホスティングする際の注意点
andpad
1
270
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
andpad
0
130
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
580
本編では話さない Zig の話
andpad
2
390
Other Decks in Programming
See All in Programming
オホーツクでコミュニティを立ち上げた理由―地方出身プログラマの挑戦 / TechRAMEN 2025 Conference
lemonade_37
2
460
Google I/O Extended Incheon 2025 ~ What's new in Android development tools
pluu
1
270
DataformでPythonする / dataform-de-python
snhryt
0
160
JetBrainsのAI機能の紹介 #jjug
yusuke
0
200
11年かかって やっとVibe Codingに 時代が追いつきましたね
yimajo
1
260
Dart 参戦!!静的型付き言語界の隠れた実力者
kno3a87
0
190
#QiitaBash TDDで(自分の)開発がどう変わったか
ryosukedtomita
1
360
Amazon Q CLI開発で学んだAIコーディングツールの使い方
licux
3
180
パスタの技術
yusukebe
1
350
実践!App Intents対応
yuukiw00w
1
230
Scale out your Claude Code ~自社専用Agentで10xする開発プロセス~
yukukotani
9
1.9k
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
120
Featured
See All Featured
Building Applications with DynamoDB
mza
96
6.5k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
283
13k
YesSQL, Process and Tooling at Scale
rocio
173
14k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
KATA
mclloyd
32
14k
The Pragmatic Product Professional
lauravandoore
36
6.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
8
450
4 Signs Your Business is Dying
shpigford
184
22k
RailsConf 2023
tenderlove
30
1.2k
Being A Developer After 40
akosma
90
590k
Building Adaptive Systems
keathley
43
2.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
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を前提にするとメリット。