Home > Net >  Is Channels is the best choice to send/handle one time events from view models to fragments/activiti
Is Channels is the best choice to send/handle one time events from view models to fragments/activiti

Time:09-07

I'm trying to send events through using sealed class in view models to send events to fragments or activities like showing snack bar or toast and I was wondering, is channel the best choice over flows or shared flows?

CodePudding user response:

I suggest you read this article: ViewModel: One-off event antipatterns.

Basically, it argues why you should transform one-off events into state, and modify the state with functions from the ViewModel.

Example: State says that a snackbar is to be shown. The UI shows the snackbar and then tells the ViewModel that it was shown. The ViewModel updates the state accordingly, so the snackbar will not be shown again.

  • Related