Hi, I'm trying to see how Labels are used in this ...
# mvikotlin
l
Hi, I'm trying to see how Labels are used in this example: https://github.com/JetBrains/compose-jb/blob/master/examples/todoapp/common/edit/s[…]/kotlin/example/todo/common/edit/store/TodoEditStoreProvider.kt from what I see, both setText and setDone methods are doing a dispatch to send out the result but they are also publishing labels which don't seem to be consumed by anything in the app? What would be their purpose in the code?
a
Hmm. Seems like it is a leftover after moving the sample from Decompose library. Change are observed directly from the database. So this can be removed. Thanks for pointing on that.
f
So, labels can be observed from anywhere?
a
Labels are just side effects of Stores. It's up to you how to use them. Common use cases: • Show an error or a dialog • Navigate to another screen • Close the screen
f
Ok, I understood. The TodoEditComponent has one Output.Finished object which is used to navigation. Could this object be replaced by a label? Or was he left out of the store for not manipulating any state?
l
My guess is that it's left out of MVIKotlin/Store on purpose because there is no (store/state) manipulation happening in there. The user (from the UI) is calling the Decompose component
component::onCloseClicked()
directly to signal it's done with the screen, so
output(Output.Finished)
is then called which is then popping the
router
in the TodoRootComponent via this
Consumer(::onEditOutput)
a
@Francis Mariano Usually Stores are
internal
, which means they are implementation details of components. It is recommended to not expose
Labels
from components. You can map
Label
to
Output
, or just use normal callbacks in your components. E.g. pass
onFinished: () -> Unit
to the component, subscribe to
Store.labels
and call the callback manually.
f
thank you for your availability
❤️ 1
1