jeudi 30 août 2018

use getters in ViewModel instead of subscribing to Model

That week I learn that we can use getters/setters in javascript. So I tried to use it in my current code.

For now my ViewModel register to the Model in order to get notified when Model has changed.

Using getters I can get RID of that and simply returns the value of the field in model to the viewModel.

ex:

Model = {
field: aValue
}

ViewModel = {}
 Object.defineProperty(ViewModel , aField{
      get: function () {
        return Model.field;
             });
         }
    });

Am I right? is it ok?

Aucun commentaire:

Enregistrer un commentaire