Ok so I think the answer to this is yes but is it ...
# android
d
Ok so I think the answer to this is yes but is it unsafe to have a
ViewModel
collect from a
Flow<T>
given to it by a
View
,
Activity
or
Fragment
? I.E.
Copy code
// MyView.kt
val events: Flow<Event> = flowOf(Event1, Event2)

viewModel.handleEvents(events)
a
Yes, it is possible, but I am more curious to know how you'll be publishing your even't via flow
d
I wanted to keep the example simple but in fact it would be more like this:
Copy code
// MyView.kt
val _events = MutableSharedFlow<Event>()
val events: SharedFlow<Event> = _events.asSharedFlow()
...
viewModel.handleEvents(events)
If the View gets destroyed there should be no problem no?
I guess I could just try it.
a
So, SharedFlow then, that seems doable. Please do let me know how that goes . . .