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
Model View Intent - An Introduction
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Jossi Wolf
August 16, 2017
Programming
160
0
Share
Model View Intent - An Introduction
Jossi Wolf
August 16, 2017
More Decks by Jossi Wolf
See All by Jossi Wolf
Understanding Recomposition Performance Pitfalls
jossiwolf
3
270
DC SF - Hitchhiking Through Jetpack Compose
jossiwolf
2
400
[DC SF 2022] Hitchhiking through Jetpack Compose
jossiwolf
2
430
[Berlin 2021] Hitchhiker's Guide to Compose
jossiwolf
4
690
From LiveData to Coroutines & Flow - DevFest ZA
jossiwolf
2
210
From LiveData to Coroutines & Flow - Android Summit
jossiwolf
2
190
From LiveData to Coroutines & Flow
jossiwolf
1
710
Experimenting with the Kotlin Compiler
jossiwolf
0
490
From Java to Kotlin Multiplatform - DevFest Nuremberg
jossiwolf
0
150
Other Decks in Programming
See All in Programming
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
3
440
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
190
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
540
Codex CLI でつくる、Issue から merge までの開発フロー
amata1219
0
320
生成 AI 時代のスナップショットテストってやつを見せてあげますよ(α版)
ojun9
0
340
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
1
330
モダンOBSプラグイン開発
umireon
0
200
Go_College_最終発表資料__外部公開用_.pdf
xe_pc23
0
130
事業会社でのセキュリティ長期インターンについて
masachikaura
0
230
一度始めたらやめられない開発効率向上術 / Findy あなたのdotfilesを教えて!
k0kubun
4
2.8k
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
120
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
220
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
77
5.3k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.8k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.6k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
250
GitHub's CSS Performance
jonrohan
1032
470k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.1k
Unsuck your backbone
ammeep
672
58k
How STYLIGHT went responsive
nonsquared
100
6k
How to train your dragon (web standard)
notwaldorf
97
6.6k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
210
Abbi's Birthday
coloredviolet
2
6.4k
Transcript
Model View Intent An Introduction
Jossi Wolf Android Developer About Me
MVI MVP MVC MVVM Redux Flux God-like Activities
Model View Intent
None
A B C data data Unidirectional Data Flow D data
data
A B C data data Unidirectional Data Flow D data
data
someModel.set(…) Immutability
someModel.set(…) Immutability
String calendar = "calendar"; System.out.println(calendar.toUpperCase()); // CALENDAR Pure Functions
public class SchoolsViewState { boolean loading; Throwable error; List<SchoolsModel> schools;
} State Model
Data Flow in MVI View Intents (User Actions) Business Logic
emits Presenter Model
public interface SchoolsViewPresenterContract { interface SchoolsViewActions { } interface SchoolsPresenterActions
{ } }
interface SchoolsPresenterActions { void loadSchools(); }
interface SchoolsViewActions { void showLoading(); void showSuccess(); void showError(); }
interface SchoolsViewActions { void render(SchoolsViewState state); }
public class SchoolsActivity implements SchoolsViewActions { @Override public void render(SchoolsViewState
state) { // The view decides how to render the state } }
@Override public void render(SchoolsViewState state) { if (state.getError() != null)
{ showError(state.getError().getMessage()); } if (state.isLoading()) { showLoader(); clearAdapter(); } else if (!state.isLoading()) { hideLoader(); } if (state.getSchools() != null) { showSchools(state.getSchools()); } }
public class ExampleStateModel { private boolean loading; private Throwable error;
private List<SchoolsModel> data; ExampleStateModel(boolean loading, Throwable error, List<SchoolsModel> data) { // set everything } }
public class ExampleStateModel { private boolean loading; private Throwable error;
private List<SchoolsModel> data; private ExampleStateModel( boolean loading, Throwable error, List<SchoolsModel> data) { // set everything } }
public static SchoolsViewState LoadingState() { return new SchoolsViewState(true, null, null);
} public static SchoolsViewState ErrorState(Throwable error) { return new SchoolsViewState(false, error, null); } public static SchoolsViewState DataLoadedState(List<SchoolsModel> schools) { return new SchoolsViewState(false, null, schools); }
State Reducer
HomeViewState { loading = false error = null data =
[…] }
HomeViewState { loading = false error = null data =
[a, b, c] } HomeViewState { loading = false error = null data = [x, y, z] } [a, b, c, x, y, z]
@Test public void loadSchoolsSuccessful() { when(api.getHamburgSchools()) .thenReturn(Observable.just(generateFakeList())); schoolsPresenter.loadSchools(); verify(schoolsView).render(SchoolsViewState.LoadingState()); verify(schoolsView).render(SchoolsViewState.DataLoadedState(generateFakeList()));
}
@Test public void loadSchoolsNotSuccessful() { Throwable throwable = new Throwable();
when(api.getHamburgSchools()) .thenReturn(Observable.error(throwable)); schoolsPresenter.loadSchools(); verify(schoolsView).render(SchoolsViewState.LoadingState()); verify(schoolsView).render(SchoolsViewState.ErrorState(throwable)); }
Predictability = = + ?
Predictability = = =
Predictability LoadingState DataLoadedState ErrorState
Readable Code Presenter View Interactor Database Network void a( )
void b( )
None
Reading on https://github.com/jossiwolf/MVI-Example https://www.youtube.com/watch?v=0IKHxjkgop4 http://hannesdorfmann.com/android/mosby3-mvi-1 https://github.com/oldergod/android-architecture
public MainViewState reduce(MainViewState previous, MainViewState next) { MainViewState computedViewState =
MainViewState.Companion.ErrorState(new Throwable("No State")); if (next.getLoading()) { computedViewState = MainViewState.Companion.LoadingState(); } else if (next.getError() != null) { computedViewState = MainViewState.Companion.ErrorState(next.getError()); } else if (next.getData() != null) { List<String> data = new ArrayList<>(); if (previous.getData() != null) { data.addAll(previous.getData()); } data.addAll(next.getData()); computedViewState = MainViewState.Companion.DataLoadedState(data); } return computedViewState; }