Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
複雑なアプリを Redux + MVVMで 完璧に制御する
Search
ANDPAD inc
April 07, 2021
Programming
3
330
複雑なアプリを 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
Go コードベースの構成と AI コンテキスト定義
andpad
0
130
「もっと正確に、もっと効率的に」ANDPADの写真書き込み機能における、 現場の声を形にしたエンハンス
andpad
0
510
複数チーム並行開発下でのコード移行アプローチ ~手動 Codemod から「生成AI 活用」への進化
andpad
0
220
Building the Real World with Ruby
andpad
0
49
Catch Up: Go Style Guide Update
andpad
0
300
OSS開発者という働き方
andpad
5
1.8k
Vue・React マルチプロダクト開発を支える Vite
andpad
0
170
プロダクト開発を支えるデータ利活用:中央集権から「民主化」までの軌跡
andpad
0
230
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
440
Other Decks in Programming
See All in Programming
【CA.ai #3】ワークフローから見直すAIエージェント — 必要な場面と“選ばない”判断
satoaoaka
0
270
Graviton と Nitro と私
maroon1st
0
110
Python札幌 LT資料
t3tra
5
910
マスタデータ問題、マイクロサービスでどう解くか
kts
0
110
ゲームの物理 剛体編
fadis
0
360
MAP, Jigsaw, Code Golf 振り返り会 by 関東Kaggler会|Jigsaw 15th Solution
hasibirok0
0
250
AIコーディングエージェント(NotebookLM)
kondai24
0
210
AIコーディングエージェント(skywork)
kondai24
0
180
認証・認可の基本を学ぼう後編
kouyuume
0
240
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.1k
ハイパーメディア駆動アプリケーションとIslandアーキテクチャ: htmxによるWebアプリケーション開発と動的UIの局所的適用
nowaki28
0
430
Socio-Technical Evolution: Growing an Architecture and Its Organization for Fast Flow
cer
PRO
0
380
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
1.8k
The browser strikes back
jonoalderson
0
63
ラッコキーワード サービス紹介資料
rakko
0
1.7M
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
98
sira's awesome portfolio website redesign presentation
elsirapls
0
87
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
180
Thoughts on Productivity
jonyablonski
73
5k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
87
The Cult of Friendly URLs
andyhume
79
6.7k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
94
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
250
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.4k
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を前提にするとメリット。