https://kotlinlang.org logo
#orbit-mvi
Title
# orbit-mvi
e

Eric Ampire [MOD]

08/05/2021, 3:19 PM
I want to have something like that sealed class ProfileViewState object Loading : ProfileViewState() object Error : ProfileViewState() data class ProfileLoaded( val name: String, val email: String ) : ProfileViewState()
m

miqbaldc

08/06/2021, 2:57 AM
For
Loading
and
Error
, looks like it is recommended to be defined as
Effect
instead of
State
m

Mikolaj Leszczynski

08/06/2021, 7:26 AM
Can you give a source @miqbaldc? Can’t remember giving that advice 😉
@Eric Ampire [MOD] you can use this sort of state without any issues - can you elaborate what problems you are facing?
m

miqbaldc

08/06/2021, 7:41 AM
afaik, the
Loading
&
Error
considered as one-off events(?) cmiiw, but yes, I’m also forgot where, is it orbit-mvi or others references 😄
m

Mikolaj Leszczynski

08/06/2021, 7:42 AM
I would treat them as states, personally - but I don’t know what your use case is.
✍️ 1
m

miqbaldc

08/06/2021, 8:09 AM
found it here: https://github.com/pedroql/mvflow/issues/30#issuecomment-799411710 if using states for
Loading
or
Error
we have to modify/mutate our previous state (to allow calling
Loading
or
Error
again) but, if the OP didn’t have the similar usecase/situtaion, using states for
Loading
or
Error
was a good pick
m

Mikolaj Leszczynski

08/06/2021, 8:17 AM
Right, now I have the context. Pedro’s answer in the link is spot on. State is not meant for repeatable, one off events. In terms of LCE (Loading-Content-Error) these states are not repeatable (e.g. you don’t need to invoke loading twice in a row) and mutually exclusive - it makes sense to make then part of the state.
✍️ 1
Unless e.g. you wanted to display errors as one-off toasts that dismiss with time - then sure - use an effect
best way to think about it is that if the components on the screen need to stick around forever or until some sort of action is taken then their state should be part of MVI state. If they don’t stick around, like toasts or timed snackbars use an effect
1
a modal dialog is a great example - a lot of people use an effect for this, but I disagree with that approach
m

miqbaldc

08/06/2021, 10:14 AM
Nice, thanks for the insight! Agreed with you, for LCE,
State
is preferred a modal dialog or navigation (e.g: start an activity), should be use
State
, instead of
Effect
? cmiiw
m

Mikolaj Leszczynski

08/06/2021, 10:17 AM
Modal dialog -> State (unless you don’t care about e.g. losing the dialog on rotation) Navigation -> Always
effect
, otherwise you get a sticky navigation - every time you subscribe to the view model again (e.g. coming back to the screen) would instantly trigger navigation
🙏 1
m

miqbaldc

08/06/2021, 11:08 AM
(e.g. coming back to the screen)
ooops, agreed, forgot the above use cases 🤣. thanks again K 🙏
👍 2
e

Eric Ampire [MOD]

08/06/2021, 12:00 PM
This discussion has answered my question, thank you very much
😄 2
🙇 2
2 Views