https://kotlinlang.org logo
#compose
Title
# compose
x

xoangon

10/03/2023, 10:40 AM
Quick question regarding Ui models for compose. I have a scenario where I have a list column with cells. Each cell is represented by an instance of a
CellUiModel
data class. I want to hoist an action for cell click, and I'm torn between two approaches: • Add an
id
to the ui model and have an
onCellClick: (Int) -> Unit
passed to the Composable ◦ Feels more natural not having functional variables in models • Add a lambda property
onClick: () -> Unit
to the
CellUiModel
◦ Great for the type safety, but a bit weird How would you approach it? Is there any performance considerations here?
v

Vlad

10/03/2023, 10:57 AM
onCellClick: (Int) -> Unit
or even
onCellClick: (CellUiModel) -> Unit
to not bother at the controller side to find the clicked model by id
x

xoangon

10/03/2023, 11:14 AM
Could you give me PRO's vs CON's? I'd like something to support the decision
v

Vlad

10/03/2023, 11:16 AM
I just generally don't like idea putting callbacks into data classes.
h

Hrodrick

10/03/2023, 12:30 PM
I suggest
onCellClick: (CellUiModel) -> Unit
passed to the composable. It is easier to maintain and understand
👍 2
x

xoangon

10/03/2023, 1:45 PM
I'll go with that one then. Thanks folks! 🙏🏻
2 Views