https://kotlinlang.org logo
Title
m

miqbaldc

01/03/2022, 3:03 PM
Any recommendation to pass a
State
&
Side-Effect
to a Composable screen, instead of passing the
ViewModel
?
ViewModel
ref based on: https://github.com/orbit-mvi/orbit-sample-stocklist-jetpack-compose/blob/main/app/[…]otlin/org/orbitmvi/orbit/sample/stocklist/list/ui/ListScreen.kt Code in 🧵 1️⃣ , 2️⃣ or 3️⃣ ?
b

Benoît

01/04/2022, 11:27 AM
1️⃣ 2️⃣ : I don't like the idea of passing the container to my composables, as it tight them to Orbit which isn't a good thing. Wether you pass a Container or a ContainerHost is roughly the same thing 3️⃣ Not sure where that
snapshotFlow
comes from what about 4️⃣ : Passing a
state: StateFlow
and a
sideEffect: Flow
?
:today-i-learned: 1
:thank-you: 1
m

miqbaldc

01/04/2022, 11:46 AM
the 4️⃣ approach seems nice, as loosely coupled from both Orbit-MVI & Android ViewModel this ways.
👍 1
b

Benoît

01/04/2022, 12:37 PM
I wouldn't call
launch
in LaunchedEffect, as you're already in a coroutine
:thank-you: 1
:today-i-learned: 1
✍️ 1
a

appmattus

01/05/2022, 8:25 AM
Why pass the state flow when you can simply pass an UpdateEmailState? Side effects in compose are a funny one. Take a bottom sheet for example, the way compose is setup you are probably better off this being part of the state flow. It's worth reading https://proandroiddev.com/sending-view-model-events-to-the-ui-eef76bdd632c and Google's updated documentation.
:thank-you: 1
m

miqbaldc

01/05/2022, 8:54 AM
thanks, our first try was to use
UpdateEmailState
directly, until we implement side-effect