Hi, I am doing a practice project involving Decomp...
# mvikotlin
c
Hi, I am doing a practice project involving Decompose and MVIKotlin, and I got a design question about the proper way to call a callback from a`Store` . So I have a
ScreenAComponent
that receive a callback to navigate to screen B like the following:
Copy code
interface ScreenAComponent {
  val state: Value<ScreenAState>
  fun sendIntent(intent: ScreenAIntent)
}

class DefaultScreenAComponent(
  private val componentContext: ComponentContext,
  private val storeFactory: StoreFactory,
  val onScreenBNavigate: (String) -> Unit
) : ScreenAComponent, ComponentContext by componentContext
The
DefaultScreenAComponent
is created by the root component which basically just does the stack navigation, and the
onScreenBNavigate
callback passed into
ScreenAComponent
is basically just
stackNavigation.push()
function call. Now, I don't know which is the right place to call
onScreenBNavigate
, should I do it by subscribing the labels? Or should I call it in Reducer? Or in Executor? Or create a dedicated state for representing that the callback should be called?
a
As usual, it depends. If you just need to call the callback from sendIntent, you can just do that, there is no need to involve the store. In fact, in this case you don't need to involve intents either. Just create a function in your component and call the callback from there. If the decision is made in the store, then Labels is the preferred way. This is how I would implement it.
1
c
Right, things can be simplified and the entire store can just not be involved if I just want to call the callback. But I think I personally prefer using the labels, because this fits the MVI paradigm nicely, and is also test friendly. Anyways thank you for the delightful answer and maintaining such a well designed library.
🙌 1