How would you model a state emited from viewmodel/...
# compose
u
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
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
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
yes, long, or DateTime is logic.. but formatted date is presentation layer..
u
you dont consider viewmodel a presentation layer?
a
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, ...