Hi all - anyone have some prod experince with MVI ...
# android
a
Hi all - anyone have some prod experince with MVI and Unidirectional data flow with Kotlin Flow/Coroutines?
I found a pretty great project here https://github.com/brewin/mvi-coroutines
The trouble I'm having is what always happens with UDF. How do you handle side effects like navigation
t
Yup! Used it for small to mid size projects. It’s great!
a
how did you end up dealing with navigation that you don't want to replay?
it's super clean for any state update: EVENT->UPDATE->STATE but when it comes to nav, it just doesn't fit as part of state
t
This was my rationale for handling things that don’t need to be replayed:
event/intent
+
state
=
new state
which means the primary purpose of `event`s / `intent`s is to update state. if “something else” needs to act on these `event`s , a
flow
of these events must be siphoned off to that component
a
so you're speaking of a separate stand-alone flow for these cases?
t
kind of like:
Copy code
fun reduce(event) {
      externalEventNotifier(event)
      updateState(event)
 }
a
Ah ok 👍 . Thanks for the insight - do you perhaps have some play code up on Github with this approach I might check out?
👍🏼 1
t
Yes. If needed, it could be made more flexible with something like this that differentiates between
pre-reduce
and
post-reduce
Copy code
fun reduce(event) {
      preReduceEventNotifier(event)
      updateState(event)
      postReduceEventNotifier(event)
 }
@Andy Gibel No problem. There is an MVI sample that I had created: https://github.com/drinkthestars/pizza-flow/blob/master/mvi/src/main/kotlin/com/goofy/goober/ui/viewmodel/CurrentPizzaUIState.kt#L8 At the moment it has not been updated to use
Flow
to siphon off the events per se (hoping I have time to update it in the future). Right now, it invokes a simple lamba/listener.
a
nice 👍 Thanks!