<@UHAJKUSTU> Hi. Can I ask about transfer some eve...
# mvikotlin
e
@Arkadii Ivanov Hi. Can I ask about transfer some events from one feature to another? For example: by clicking on the back button on screen A, I gonna go to the previous screen B, and the item list should be updated on screen B. Something like eventbus comes to mind. Create some SharedFlow, emit event from Store A and collect it in Store B. But where I should collect it? In custom Bootstrapper in Store B? How do you recommend implementing such logic?
a
Hi. I suppose you have a
Store
in the screen B. You can have an
Intent
like
StoreB.Refresh
, which you can send when the screen B is e.g. resumed. Or you can send
Intent.Refresh
when you navigate from A to B, e.g. in a parent Fragment/Controller/Whatever.
e
Okay, but how will FragmentA know that I clicked on FragmentB back button? (sorry for my English in advance) I see this situation like this: 1. I’m on the FragmentB. 2. I’m clicked on the back button and send the Intent to the StoreB. 3. I caught the Intent.Back in StoreB (in Executer) and … (by my version) I should emit some BusEvent. 4. Then I need to catch the BusEvent in the StoreA. Because I wanna say: “Hey, FragmentA, I gonna go back to you from FragmentB, please know about it and update my item list”. 5. So to implement №4 logic, I should subscribe to BusEvents in StoreB. If I using SharedFlow, I should call collect() method. Something like this…) please correct me if need to.
a
Your FragmentA can have outputs, so you can emit something like Output.Finished. The output should be handled by the parent Fragment, which actually does navigation. Check out this example: https://github.com/arkivanov/MVIKotlin/blob/85b6bc2343bedea4242817796728eb8f3ceb71ee/sample/todo-app-android/src/main/java/com/arkivanov/mvikotlin/sample/todo/android/root/RootFragment.kt#L62
e
thx! I’ll check it :)
👍 1
a
So you can emit Output.Finished directly from the back button click listener, or if you need additional logic in your StoreB, then you can bind it's Labels to Output.
e
sounds rock)