Colton Idle
05/27/2021, 9:27 PMclass DomainToComposeConverter {
@Composable
fun from(domainModel: MyDomainModel) {
Now I don't think this is really idiomatic kotlin/compose because 1. from
breaks the rule "Composable functions that return Unit should start with an uppercase letter" 2. Would this be better as an "object"/singleton or do you all think that this should just be an extension function on MyDomainModel
?dimsuz
05/27/2021, 9:35 PMComposable
? Isn't the architecture layer mapping functions simply... mappers?
Like one data class is the input, another is the output -> plain old function 🙂Colton Idle
05/27/2021, 9:36 PMdimsuz
05/27/2021, 9:42 PMfun SomeStorageDbModel.toDomainModel() = SomeDomanModel(field1 = this.fieldX + 3)
and call where appropriate.
Our UI module has
fun SomeDomainModel.toUiModel() = SomeUiModel(text = this.field1.format())
In each place where we call those functions we know input layer and output layer, so no need for "clever" tricks.
But maybe I'm driving this conversation in different direction, sorry. You didn't ask about architecture.Adam Powell
05/27/2021, 9:48 PMMyDomainModel
?Colton Idle
05/27/2021, 9:53 PMclass DomainToComposeConverter {
@Composable
fun from(domainModel: MyDomainModel) {
when (domainModel) {
is Type1 -> { return MyComposable1(it.value)}
is Type2 -> { return MyComposable2(it.value)}
is Type3 -> { return MyComposable3(it.value)}
so basically in my fragment I have things = List<MyDomainModel>,
and then I have a
Column {
things.forEach{
DomainToComposeConverter().from(it)
}
}
Adam Powell
05/27/2021, 9:55 PMreturn MyComposable1
etc.return
part anyway since this is all Unit
@Composable
fun MyDomain(domainModel: MyDomainModel) {
when
statement.Adam Powell
05/27/2021, 10:00 PMColton Idle
05/27/2021, 10:08 PM