The state of managing state (with Compose)
Article Summary
Cash App's Jake Wharton just open-sourced their solution to a problem every mobile team faces: state management code that's impossible to read.
After five years of iterating through RxJava and Kotlin Flow, Wharton realized the problem wasn't the streaming library. It was how state logic itself gets written. His answer? Molecule, a library that uses Compose for state production, not just UI rendering.
Key Takeaways
- Business logic was drowning in RxJava operator chains and nesting
- Molecule lets composable functions return state values as StateFlow
- Write plain conditionals and loops instead of complex operator combinations
- Compose compiler enables readable state logic with remember and effects
- Released publicly after five months of internal testing at Cash App
Molecule separates Compose's state management superpowers from UI rendering, making business logic dramatically more readable.
About This Article
Cash App's state management with RxJava and kotlinx.coroutines made the code hard to follow. Business logic got buried in the details, and Jake Wharton realized the real problem wasn't the streaming library itself. The issue was how the state-producing logic was actually structured.
Wharton built Molecule to fix this. It uses Compose's compiler plugin and state management tools like remember and LaunchedEffect. Developers can now write state logic with plain conditionals and loops instead of wrestling with complex operator chains.
Cash App tested Molecule internally for five months, then open-sourced it. The experiment showed that you can separate Compose's state management from UI rendering. When you do, business logic becomes much easier to read and maintain.