It’s a good idea to bind the entire viewModel clas...
# android
f
It’s a good idea to bind the entire viewModel class to a view instead specifics properties? In some cases not all property and methods of the viewModel are used by the view
🤔 1
l
I think it's not proper English, I have trouble understanding your question
f
Sorry, the English is not my native language, i edit the question, now should is more clear
e
What do you mean by bind the entire viewModel to a view instead of specific properties?
f
For example: I need a liveData User for my view and the User is in the viewModel class, with other method and properties. Now i can bind the entire viewModel to view and get the user or bind only the user
g
And what is question? it’s really depends on your case and about level of encapsulation that you expect. Of course if View depends on own ViewModel with only required properties and methods this sounds like a better approach, but sometimes it’s just overkill, it’s just a matter of practical approach But what is embarrasses me, is that you mentioned ViewModel, so this is MVVM, but in MVVM your view should know nothing about ViewModel, your binding should know how to apply VM state to View or update VM according to View state, so not sure what is your case when View has dependency on ViewModel
f
In the official doc of data binding the entire viewModel is attached to the view, so i think is not a violation of the architecture, my questions is only about the “performance”
g
Could you show an example of official doc where view that have dependency on ViewModel? Maybe we are talking about different things I don't think there is any measurable performance difference, it's more about architecture
The first example of xml have the dependency of viewModel, but probably I’m wronging something, show me the truth, man 😅
g
It's big documentation page, any particular examples?
View doesn't have any dependency on View model in this example
It's Binding layout not a view. View in this case is TextView class
Binding connects View and ViewModel (using binding adapters), but view know nothing about view model or even bindings library, ViewModel also don't know about view
So what do you mean when talking about binding of "entire viewmodel"?
f
Mh, so i missing something, for me the dependency is “<data name”viewModel” type=“com.data.viewModel” />”, the dependency is the type of the viewModel
and with “bind the entire viewModel” I mean this core, instead to bind specifics properties of the viewModel
so what is the real dependency to avoid?
g
No, I'm just talking about dependency like "some class uses another class"
f
Ahh, so you mean to avoid call a dependency of viewModel from the view, right?
g
As we already figure out I was confused because you called binding "view", but binding is not view
f
yes man, I confuse the terminology, thx for your patience
g
So could you show some sample code that shows binding that uses "entire viewmodel" and properties. Just to be clear and understand which options do you concider