# decompose

Pavel S

10/20/2023, 1:49 PM
How do you make features communicate with each other without duplicating the application state (especially when using MVI or similar patterns)? For example I have a list of items, one of which can be selected, and when it is selected its data should be displayed in the UI of another feature. Sure, it is easy to just have a common dependency in both of them which exposes a kotlin
and an update method, or something like that, but with this approach you have to duplicate the state in both of them and also duplicate the boilerplate of subscribing to changes. Is there a more elegant option?

Arkadii Ivanov

10/20/2023, 2:58 PM
I think there could be different ways. One of the ways you can find in the Confetti app. • SessionsComponent - a list of sessions. When a session is clicked, the
is called. • SessionDetailsComponent - shows the clicked session. The presentation depends on the type of the device. E.g. on a phone device, there is stack navigation, handled by ConferenceComponent. On a large (e.g. tablet) device, there is MultiPaneComponent. It stores the navigation state, and calls
to highlight the selected item. Indeed, the selection state is kinda duplicated (i.e.
stores the navigation state, plus
stores the selected session id. If you really want to avoid the duplication, you can pass a Flow/Observable to
and just
it to the final component state. But from my point of view it's not a big deal. Regardless of the duplication, every component is reusable.
👍 2