Hello everyone! I am trying to find some useful re...
# multiplatform
m
Hello everyone! I am trying to find some useful resources about how to handle “events” in Compose Multiplatform. I am currently developing app for android/ios using moko for ViewModels and Voyager for navigation. I am especially interested if there are some examples of how to handle events that originate from ViewModel. So for example: • user presses a button -> function in VM is called to save something to db -> depending on the result fail/success you either show an error or trigger navigation via event.
y
dont use moko use precompose viewModel its way simpler and better also they precompose koin fo DI, you can also use precompose for navigation
👍 1
m
Do you have any example how event triggered from ViewModel is handled?
p
I think you are talking about an old MVVM problem. If it is what I think is not related to Moko or Voyager but a general View and VM interaction. Long story short, represent your events as state if you want 100% delivery/consumption guaranteed
👍 1
There's a good article from Manuel Vivo talking about that
m
Correct! It is nothing directly connected to the libraries. I am just trying to hear people’s opinions and see some examples.
Yeah here is the article I think you are talking about: https://medium.com/androiddevelopers/viewmodel-one-off-event-antipatterns-16a1da869b95 But there is a lot of discussion going on whether this is the right way or not. Here is an article that does not agree with using events as a state: https://proandroiddev.com/viewmodel-events-as-state-are-an-antipattern-35ff4fbc6fb6
p
So who's right 🤷🏻‍♂️ welcome to Android 😄
😅 4
🤣 2