How would you model a state emited from viewmodel/presenter, if you need to render a "Hello Joe"?
Copy code
State(val greeting: String) and just render thr greeting
State(val name: String) render "Hello $state.name"
State(val user: User) render "Hello $state.user.name"
TLDR; do you format in viewmodel or in composables?
a
alorma
07/14/2021, 8:14 AM
I ALWAYS format on ViewModel / Presenter.
UI must be responsible of displaying content, but not define which content to show.
Think of it about dates... would you format the date on UI?
u
ursus
07/14/2021, 9:19 AM
Currently I do that yea. Trouble is that I often need to keep the User instance in state for some other parts to read it, like user.id and what not
And this way if timestamp: Long is part of your presenter state, formatted value doesnt really needs to be a backed val, since its a calculation, giving u a 1 source of truth
a
alorma
07/14/2021, 9:27 AM
yes, long, or DateTime is logic.. but formatted date is presentation layer..
u
ursus
07/14/2021, 11:38 AM
you dont consider viewmodel a presentation layer?
a
alorma
07/14/2021, 11:43 AM
it's a layer between domain and presentation.
it receive data form UseCases / dataspurces... but domain data,
Numbers
DateTime
boolean
enum
... and it maps them to the presentation data, strings with params, strings based on given param, ...