Breaking Up with Big ViewModels
summary
Breaks a 1,376-line ViewModel into multiple, screen-scoped ViewModels backed by a shared Mediator that holds only transient UI state; a gallery example uses three ViewModels (grid, top bar, bottom bar) and shows selection updates flowing via the Mediator, not direct VM-to-VM calls. Uses Jetpack Compose, Hilt or Koin scoping for one mediator per navigation destination, tests with Kotest behavior specs, and enforces the pattern with lint-as-tests via Consist (and Harmonize for iOS). Mediator pattern 1,376-line ViewModel
AI-written summary · about
chapters (7)
- 0:00Introduction
- 8:06Why ViewModels become too large
- 13:24Mediator pattern
- 20:28Implementing mediators
- 25:48Testing ViewModels
- 30:43Lint rules enforcement
- 33:51Summary
related talks
41mBreaking ViewModels into smaller self-contained UI models
40mComposing ViewModels:Breaking ViewModels into smaller self-contained UI models
40mComposing ViewModels: Breaking ViewModels into smaller self-contained UI models
43mHelp! ViewModel
22mBloated ViewModels? What Next
29mModern Android Development using MVI architecture
35mBreaking Up with WebViews: Server-Driven UI with KMP + Compose
30mArchitecting an app with MVP and ViewModels
