For anyone looking to do an MVI ViewModel implemen...
# coroutines
b
For anyone looking to do an MVI ViewModel implemented just with Flow, I swapped in Flow for Rx from a pure Rx implementation. Rx version: https://github.com/kaushikgopal/movies-usf-android Flow version: https://github.com/brendanw/graphql-viewmodel/pull/1/files#diff-f7b91eff2ca316133c697563510a0e91 Flow is still missing a multicast operator, so I copied an implementation from some WIP open source lib by Yigit and Mike N. There is another multicast operator implementation by one of the Rx contributors; I tried it and experienced some heisenbugs -- Yigit and Mike's multicast flow operator has more comprehensive test coverage.
l
Nice. This is similar to what we are doing. I noticed you are using
ConflatedBroadcastChannel
for things like
val viewStateChannel: ConflatedBroadcastChannel<MainViewState>
We are hiding ours behind flows by doing stuff like:
Copy code
private val statesChannel: ConflatedBroadcastChannel<ProfileState> = ConflatedBroadcastChannel()
    val states: Flow<ProfileState> = statesChannel.asFlow()
ultimately we would like to use DataFlows ( https://github.com/Kotlin/kotlinx.coroutines/pull/1354 ) and do away with channels entirely. However data flow is still in draft status
I also notice you are not closing your
ConflatedBroadcastChannel
- we don't
close
either, but I feel kind of bad, and wonder if not closing it is somehow wrong 🤷‍♂️
e
As long as you know that all subscriptions to the CBC will get closed anyway it does not really matter if you close it or not.
👍 1
l
Thanks for that, its really helpful to know! BTW @elizarov do you have any any ideas on how the
DataFlow
stuff is progressing? I would really like to be able to move everything away from channels to flows - they seem a lot "safer" as they are not hot like channels. However we need that
DataFlow
as a replacement for CBC to make it all work 😁
e
The prototype that I currently have is a CBC replacement. As a bonus it is also allocation-free. Expect it to land early next year.
l
Wow, thats fantastic news 😁 🎉
m
We moved multicaster to its own module/maven artifact. I'd recommend using the artifact rather than copying as we just fixed a race condition few days ago that I believe you are missing