Know which among the dependent keys caused the com

2019-02-26 12:36发布

问题:

In Ember, is there a way to get which among the dependent keys caused a computed property to recalculate?

eg:

myProp: Ember.computed('dep1','dep2','dep3', function(){
    console.log('MyProp was recalculated due to a change in property :' <dep 1,2 or 3(get the value here)>);
    return ...;
}),

Kindly let me know if I should provide any additional details.

回答1:

Short answer: No, thats not possible.

Long answer: You could save away all dependency keys and compare them on recalculation.



回答2:

If you are in a component.js you can check didUpdateAttributes(options) where options contains the old and new values of updated attributes.