miqbaldc
02/03/2022, 5:58 AMorbit-mvi/orbit-mvi
, compose effect are wrapped with LaunchedEffect
Strangely in our case, we were unable to observe same sideEffect twice tho
Does it compose LaunchedEffect
are not meant to observe same sideEffect, or maybe any other alternative?miqbaldc
02/03/2022, 5:59 AMMikolaj Leszczynski
02/03/2022, 9:44 AMmiqbaldc
02/03/2022, 12:34 PMviewmodel.observe
, in Activity
2. also subscription inside setContent
are considred two separate subscriptions?
---
here’s our snippet code attachment:
1. Compose Screen
2. ActivityMikolaj Leszczynski
02/03/2022, 2:48 PMdialogType
is remember
, which means that if this set to the exact same value, a recomposition won’t happen. Could this be the issue you’re seeing? I don’t see anything out of the ordinary otherwise.miqbaldc
02/03/2022, 3:01 PM2. if this set to the exact same value, a recomposition won’t happenShots, seems this is the culprit tho’. In our case, we changed from
LaunchedEffect
to use SideEffect
and able to show the dialog everytime (the same sideEffect
subscribed)miqbaldc
02/03/2022, 3:02 PM1. This will not cache the side effect emissions correctly when there are no subscribers. In the meantime you can subscribe in the way Matt outlined in the issue.That’s awesome. The extensions would be great! Will implement this later in our extensions as well
miqbaldc
02/03/2022, 3:03 PMLaunchedEffect
didn’t trigger any recomposition or whatsoever, and didn’t reach the sideEffectFlow.collect {}
part.miqbaldc
02/03/2022, 3:07 PMorbit-mvi
which why the reason we consider to use a Flow
or a plain data class <The State>
as a Composable argument thereMikolaj Leszczynski
02/04/2022, 8:23 AMSideEffect
is appropriate - it is executed on every successful recomposition which is not really what you want here? Rather you want collect
to be kept through the lifetime of the composition
https://developer.android.com/jetpack/compose/side-effects#sideeffect-publishMikolaj Leszczynski
02/04/2022, 8:25 AMLaunchedEffect
itself won’t cause recompositions, but your actions in collect
could, through altering the remembered State
objects for example.Mikolaj Leszczynski
02/04/2022, 8:33 AMShots, seems this is the culprit tho’.
In our case, we changed fromÂNot sure I follow. So the thing I outlined was the problem, but you decided to fix it via changing to to useÂLaunchedEffect
 and able to show the dialog everytime (the sameÂSideEffect
 subscribed)sideEffect
SideEffect
? Not sure this is the right solution.
If you’re handling the dialog as State
in Compose by using remember
, it should be part of the ViewModel’s State object as well IMHO. The dialog is either there or it isn’t - very stateful behaviour.
What you have currently introduces state in Compose that is decoupled from your ViewModel. Personally I think this piece of state belongs in the ViewModel’s State and Compose should bind to it. I’m firmly in the camp of the ViewModel being the source of truth - otherwise the state ownership is unclear and you can get subtle bugs like this.
Only use side effects if you don’t care about the dialog state in Compose. But personally I think it’s not really the right way.miqbaldc
02/04/2022, 10:57 AMNot sure I follow. So the thing I outlined was the problem, but you decided to fix it via changing toÂWe’re currently unsure as well if it due to? Not sure this is the right solution.SideEffect
dialogType by remember
or not, but we decide to leave it as-is, and change LaunchedEffect
to SideEffect
miqbaldc
02/04/2022, 10:57 AMWhat you have currently introduces state in Compose that is decoupled from your ViewModel. Personally I think this piece of state belongs in the ViewModel’s State and Compose should bind to it. I’m firmly in the camp of the ViewModel being the source of truth - otherwise the state ownership is unclear and you can get subtle bugs like this.We need to refactor a bit our composable screen for this use case tho’. 🙏
miqbaldc
02/08/2022, 2:35 AMcollectSideEffect
in our part, also doesn’t succeed tho’miqbaldc
02/08/2022, 2:36 AMOnly use side effects if you don’t care about the dialog state in Compose. But personally I think it’s not really the right way.If we understand you correctly, did you suggest to move
dialogType by remember
from Composable function, into dialogType by mutableStateOf
in ViewModel? cmiiwmiqbaldc
02/08/2022, 2:37 AM