dimanche 26 janvier 2020

Communicate between View Models in MVVM

I am using MVVM pattern in my project. Here is the pseudo code.

class ViewModelA {
     propertyA;
     methodA(); // updates propertyA
}

class ViewModelB {
     methodB() {
     // update properties of ViewModelB
     // Needs to update propertyA of ViewModelA
     }
}

I have two view models ViewModelA and ViewModelB. MethodB of ViewModelB needs to update propertyA of ViewModelA.

I can keep a reference of an instance of ViewModelA inside ViewModelB and call methodA to update propertyA of ViewModelA. Is it a good practice to keep a reference of one view model inside another view model in MVVM pattern? Also, would like to know other ways in which View models can update properties of other view models.

Aucun commentaire:

Enregistrer un commentaire