I’m looking at a pattern shown in the image below ...
# squarelibraries
t
I’m looking at a pattern shown in the image below from a very helpful talk on Molecule by Ash Davies and Bill Phillips. I understand these snippets aren’t meant to be taken literally, but I’m having difficulty filling in some of the blanks. 1. I get
A MonotonicFrameClock is not available in this CoroutineContext...
crash when I use
viewModelScope
to launch Molecule as it is bound to
Dispatchers.Main.immediate
. My solve was to simply launch with
AndroidUiDispatcher.Main
, since having the ViewModel hold the Presenter is enough to make it survive configuration changes. Am I missing something else here? 2. What is the recommendation for emitting events within a Composable screen (or any view, for that matter)? The snippet has
events
as a SharedFlow, but it does not successfully emit an event when I call
events.tryEmit(LoginEvent)
and calling
emit
directly won’t work outside a coroutine.
a
Ooooo, more molecule resources 🙂
a
Thanks!!
Also, 1 does use
AndroidUiDispatcher.Main
As for #2, I emit them from my viewmodel
I also keep my “presenter” separate, but this could easily be kept in the VM
My presenter takes these events and performs actions based on these events, and transforms the state that come from the repository
message has been deleted
EventsEffect
is just a shorthand I made to avoid lambda soup🙂
j

https://www.youtube.com/watch?v=TkQzAN-irAQ&list=PLY-K9deHTAW7w28X1RL1YKAk9gCrvVr54

I found this presentation is also very well explained
d
@andrew In that
EventsEffect
example, how do you launch new coroutines since the
CoroutineScope
provided by
LaunchedEffect
is no longer available?