cashapp / molecule

Build a StateFlow stream using Jetpack Compose
https://cashapp.github.io/molecule/docs/1.x/
Apache License 2.0
1.9k stars 81 forks source link

Relationship between molecule and Compose UI #172

Open eygraber opened 1 year ago

eygraber commented 1 year ago

Considering the common confusion around Compose / Compose UI it might be helpful to add a small section to the README explaining the relationship between molecule and Compose UI:

ganfra commented 1 year ago

To the question : Are there any cons to using molecule in this scenario? I found using rememberSaveable wasn't working when the instance holding the moleculeScope is destroyed/recreated. But maybe I did something wrong with my config.

StylianosGakis commented 1 year ago

Using molecule also gives you the power to scope that work to whatever class you're going to be holding it in. For example, as the PR here https://github.com/cashapp/molecule/pull/274 shows, you can scope your molecule presenter to your AAC ViewModel, meaning that if the UI for whatever reason gets destroyed, like in a config change situation, your molecule presenter would persist for until the new UI comes on the screen after the config change.

So don't think it's as simple as, you're using compose UI -> No need for molecule.

ganfra commented 1 year ago

Using molecule also gives you the power to scope that work to whatever class you're going to be holding it in. For example, as the PR here #274 shows, you can scope your molecule presenter to your AAC ViewModel, meaning that if the UI for whatever reason gets destroyed, like in a config change situation, your molecule presenter would persist for until the new UI comes on the screen after the config change.

So don't think it's as simple as, you're using compose UI -> No need for molecule.

If you have a full compose UI app, most of the config changes are already handled at the Compose level, so you can avoid destroying the activity. Plus this is more the responsability of the data/domain layer to handle this properly instead of AAC ViewModel...

StylianosGakis commented 1 year ago

If you have a full compose UI app, most of the config changes are already handled

The key word here is "most", not all of them. So still relevant.