jeudi 1 juin 2017

Curious behavior when observing Ember's dirtyType property

I try to observe (in my controller) if my Ember model has changed.

personChanged: function() {
    // do stuff
}.observes('person.dirtyType'),

This observer is never triggerd unless I will access the isDirty property before. For example if I get the property in the route (where the model is fetched) the observer is triggerd exactly 1 time.

model.people.get('firstObject').get('dirtyType');
controller.set('person', model.people.get('firstObject'));

If I want to get the observer triggered every time the model changed I need to access dirtyType within the observer again.

personChanged: function() {
    this.get('person.dirtyType');
    // do stuff
}.observes('person.dirtyType'),

The value of dirtyType in the observer is always as expected.

Maybe I'm doing it completely wrong but I can't follow the behavior above.




Aucun commentaire:

Enregistrer un commentaire