Is there a reason why I shouldn’t put the `Snackba...
# compose
a
Is there a reason why I shouldn’t put the
SnackbarHostState
in the
ViewModel
? Seems like an unnecessary dance to from event -> state -> lambda in compose -> snackbarhoststate (which internally converts the event into a state again) -> callback to viewmodel that the state was “consumed”. Using
viewModelScope
to launch the snackbar would just suspend the launch call until the view is available it seems.. which is fine?
s
Just do it. It’s not uncommon to hoist some state holder classes up there, like TextFieldState for example.
f
the way I think about it is, "does the viewmodel need to know about this?" If so, put it in the viewmodel, otherwise leave it in the compostable usually as a stateholder.
👍 3
t
Testing?
a
It will live behind an injected interface @Tobias Preuss so testing won’t be an issue
My intention is to avoid the dance from viewmodel -> state“event“ -> event -> back to state in snackbarhoststate
t
😶‍🌫️ I can't really judge. I have not used SnackbarHostState myself.
a
You will cross paths with it I promise you haha
🏃 1