Cash App Jake Wharton Nov 11, 2021

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

Critical Insight

Molecule separates Compose's state management superpowers from UI rendering, making business logic dramatically more readable.

The article includes actual code showing how a simple counter composable transforms into a StateFlow with just one function call.

About This Article

Problem

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.

Solution

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.

Impact

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.