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
Use MVI Architecture in Kotlin × Android
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
itome
November 15, 2018
Technology
1.6k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Use MVI Architecture in Kotlin × Android
itome
November 15, 2018
More Decks by itome
See All by itome
今日始め るCloudflare Browser Rendering
itome
2
340
Android accessibility and automated check tools
itome
1
5.1k
Accessibility in CATS
itome
4
2.6k
Introduce_Owl.pdf
itome
0
120
Introducing Android Accessibility Test with Accessibility Testing Framework
itome
1
800
Introduction of accessibility for mobile development
itome
0
260
Architecture_for_mobile_development.pdf
itome
0
280
Android_Accessibility_Suite.pdf
itome
0
170
Introducing Owl
itome
0
1.2k
Other Decks in Technology
See All in Technology
依頼文化をやめる日 EM視点で語るPlatform EngineeringとInclusive SRE / Discussing Platform Engineering and Inclusive SRE from an EM's Perspective
shin1988
4
4.2k
SRE依存からの脱却 運用を開 発チームへ移す、 フルサイ クル開 発体制の実践
joooee0000
0
1.9k
Oracle Exadata Database Service on Cloud@Customer X11M (ExaDB-C@C) サービス概要
oracle4engineer
PRO
2
8.4k
生成AI活用によるODC欠陥分析の分類高速化の実践と導入効果 / 20260703 Suguru Ishii
shift_evolve
PRO
2
100
“ID沼入口” - 基本とセキュリティから始める、考え続けるためのID管理技術勉強会 告知&イントロ
ritou
0
440
テスト設計の本質を改めて考えてみる~生成AIを活用する時代だからこそ、作ったテストの説明性を高めよう~
yamasaki696
1
390
デジタル・デザイン:次の50年を描く「進化する青写真」
y150saya
0
840
Control Planeで育てるBtoB SaaSの認証基盤 - SRE NEXT 2026
pokohide
1
1.6k
デジタル・デザイン構想 by Sayaka Ishizuka
y150saya
0
200
Text-to-SQLをAgentCoreで実現し、生成されるSQLの精度を定量的に評価する
yakumo
2
670
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
11k
アカウントが増えてからでは遅い? ~ マルチアカウント統制の勘所 ~
kenichinakamura
0
190
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
63
55k
Agile that works and the tools we love
rasmusluckow
331
22k
Deep Space Network (abreviated)
tonyrice
0
220
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
180
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Optimizing for Happiness
mojombo
378
71k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.3k
Un-Boring Meetings
codingconduct
0
330
Mobile First: as difficult as doing things right
swwweet
225
10k
Tell your own story through comics
letsgokoyo
1
990
Transcript
Koin×AndroidͰMVI ΞʔΩςΫνϟΛ࠾༻͢Δ #potatetips #56
ࣗݾհ 0min
ࣗݾհ 0min ௩ຊࢤ ! https://twitter.com/itometeam " https://github.com/itome # https://medium.com/@itometeam cyberagent/cats
MVI Architectureͱʁ 1min
MVI Architectureͱʁ 1min ୯ํσʔλϑϩʔ • Model • View • Intent(≠android.content.Intent)
ViewModelͰ Intent → Action → Result → Result ͱσʔλΛม͍ͯ͘͜͠ͱͰ ঢ়ଶΛมߋ͢Δ
RxʹΑΔ࣮ྫ 2min
RxʹΑΔ࣮ྫ 2min sealed class EventsIntent : MviIntent { object FetchFirstPageIntent
: EventsIntent() data class FetchPageIntent(val pageNum: Int) : EventsIntent() object FetchLoginUserIntent : EventsIntent() } sealed class EventsAction : MviAction { object FetchFirstPageAction : EventsAction() data class FetchEventsPageAction( val pageNum: Int ) : EventsAction() object FetchLoginUserAction : EventsAction() }
RxʹΑΔ࣮ྫ 2min private fun actionFromIntent(intent: EventsIntent): EventsAction { return when
(intent) { FetchFirstPageIntent -> FetchFirstPageAction is FetchPageIntent -> FetchEventsPageAction(intent.pageNum) FetchLoginUserIntent -> FetchLoginUserAction } }
RxʹΑΔ࣮ྫ 2min sealed class EventsResult : MviResult { sealed class
FetchFirstPageResult : EventsResult() { data class Success(val events: List<Event>) : FetchFirstPageResult() data class Failure(val error: Throwable) : FetchFirstPageResult() object InFlight : FetchFirstPageResult() } sealed class FetchEventsPageResult : EventsResult() { data class Success(val events: List<Event>) : FetchEventsPageResult() data class Failure(val error: Throwable) : FetchEventsPageResult() object InFlight : FetchEventsPageResult() } sealed class FetchLoginUserResult : EventsResult() { data class Success(val user: User) : FetchLoginUserResult() data class Failure(val error: Throwable) : FetchLoginUserResult() object InFlight : FetchLoginUserResult() } }
RxʹΑΔ࣮ྫ 2min override val actionProcessor = mergeProcessor( fetchFirstPageProcessor to FetchFirstPageAction::class,
fetchEventsPageProcessor to FetchEventsPageAction::class, fetchLoginUserProcessor to FetchLoginUserAction::class ) private val fetchFirstPageProcessor = createProcessor<FetchFirstPageAction, FetchFirstPageResult> { repository.getEvents(1) .toObservable() .map { user -> FetchFirstPageResult.Success(user) } .cast(FetchFirstPageResult::class.java) .onErrorReturn(FetchFirstPageResult::Failure) .subscribeOn(schedulerProvider.io()) .observeOn(schedulerProvider.ui()) .startWith(FetchFirstPageResult.InFlight) }
RxʹΑΔ࣮ྫ 2min data class EventsViewState( val loginUser: User?, val events:
List<Event>, val error: Throwable?, val nextPage: Int, val isLoading: Boolean ) : MviViewState { companion object { fun idle(): EventsViewState { return EventsViewState( loginUser = null, events = emptyList(), error = null, nextPage = 1, isLoading = false ) } } }
RxʹΑΔ࣮ྫ 2min private val reducer = { previousState: EventsViewState, result:
EventsResult -> when (result) { is FetchFirstPageResult -> when (result) { is FetchFirstPageResult.Success -> previousState.copy( events = result.events, error = null, isLoading = false, nextPage = 2 ) is FetchFirstPageResult.Failure -> previousState.copy(error = result.error, isLoading = false) FetchFirstPageResult.InFlight -> previousState.copy(isLoading = true) }
RxʹΑΔ࣮ྫ 2min private fun compose(): Observable<EventsViewState> { return intentsSubject .map(this::actionFromIntent)
.compose(actionProcessorHolder.actionProcessor) .scan(EventsViewState.idle(), reducer) .replay(1) .autoConnect(0) }
RxʹΑΔ࣮ྫ 2min ιʔείʔυ https://github.com/itome/GithubMVI
ϝϦοτ / σϝϦοτ 2min
ϝϦοτ 2min ϓϩάϥϚʔʹର͢Δ੍͕ڧ͍ ςετ͕༰қ ɾਓʹΑ࣮͕ͬͯมΘΔ෦ΛͰ͖Δ͚ͩ͑ΒΕΔ ɾ֤ॲཧͰೖྗͱग़ྗ͕ඞͣ̍ΧॴʹͳΔͨΊɺ ɹςετ͖͢͜ͱ͕໌֬ ΤϥʔϋϯυϦϯά͕༰қ ɾViewͷΠϕϯτ͔ΒViewͷߋ৽·Ͱ͕ҰຊͷετϦʔϜʹ ɹͳ͍ͬͯΔͨΊɺྫ֎ॲཧ͕Θ͔Γ͍͢
σϝϦοτ 2min ̍ճ͖ΓͷΠϕϯτΛ͑Δͷ͕͍͠ ෳࡶͳϨΠΞτͰViewStateͷߋ৽ͷॲཧ͕ॏ͘ͳΔ ɾViewModelͷग़ྗ͕ViewStateͷΈͰ͋ΔͨΊɺҰճ͖ΓͷΠϕϯτΛ ɹViewModelଆ͔Βى͍ͨ࣌͜͠ɺflagΛ࣋ͨͤΔͳͲͷ͕ඞཁ ɾAndroidʹReactͷࠩߋ৽ͷΑ͏ͳΈ͕ଘࡏ͠ͳ͍ͨΊɺ ɹViewStateͷҰ෦Λߋ৽͚ͨͩ͠ͰɺViewStateʹؔ࿈͢Δ ɹશͯͷView͕ߋ৽͞Εͯ͠·͏ ʹͳΓ͍͢
ɾίʔυͷϘΠϥʔϓϨʔτ͕ଟ͍ͨΊɺখ͞ͳॲཧͰ͔ͳΓͷ ɹίʔυΛॻ͘ඞཁ͕͋Δɻ
·ͱΊ 0.5min
͋Γ͕ͱ͏͍͟͝·ͨ͠ ! https://twitter.com/itometeam " https://github.com/itome # https://medium.com/@itometeam Takeshi Tsukamoto cyberagent/cats