https://kotlinlang.org logo
#android
Title
# android
a

Andy Gibel

03/30/2020, 10:19 PM
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

Tash

03/30/2020, 10:21 PM
Yup! Used it for small to mid size projects. It’s great!
a

Andy Gibel

03/30/2020, 10:21 PM
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

Tash

03/30/2020, 10:23 PM
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

Andy Gibel

03/30/2020, 10:24 PM
so you're speaking of a separate stand-alone flow for these cases?
t

Tash

03/30/2020, 10:24 PM
kind of like:
Copy code
fun reduce(event) {
      externalEventNotifier(event)
      updateState(event)
 }
a

Andy Gibel

03/30/2020, 10:25 PM
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

Tash

03/30/2020, 10:25 PM
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

Andy Gibel

04/01/2020, 1:50 PM
nice 👍 Thanks!