⚔️MVVM vs MVI
Last updated
Last updated
On Android, MVVM can be drawn as the following:
The ViewModel keeps a persistent UiState in a StateFlow which is observed by the Screen to update its UI.
The Fragment (or Screen), on every trigger of an UI Event, calls directly a function to trigger some code that will update the UiState.
This is all good, but the number of functions to call from the Fragment to the ViewModel can become big and makes the class feel messy, so let's see what MVI adds to the table.
What we take from MVI on Android is just transforming all those UI Event functions into types and passing then to one only function, usually called handleEvent()
: