I have a component in ember like
{{some-setup-section
processingOfId=processingOfId
savingActivitySetUp=savingActivitySetUp
editingActivitySetUp=editingActivitySetUp}}
and in my components js file
didUpdateAttrs() {
this.updateDataOnChange();
this._super(...arguments);}
I make use of didUpdateAttrs to find when some attribute have changed. In my case I need to exectue a function only when processingOfId have changed. Is there any method like this.attrs('processingOfId').didChanged() to help me solve my issue.
I tried
didUpdateAttrs({oldAttr, newAttr})
and check to see if oldAttr.someAttrs !== newAttr.someAttrs value but in console it says ember doesn't encourage passing in attrs like that and soon its going to be depricated. Is there any way I can solve this scenario
To wrap up the question is there any way to find which attribute updated in the 'didUpdateAttrs' method inside a component
There is no in built way,
Refer this RFC for more information.
Ember.Component.extend({
didUpdateAttrs() {
let oldCoordinates = this.get('_previousCoordinates');
let newCoordinates = this.get('coordinates');
if (oldCoordinates && oldCoordinates !== newCoordinates) {
this.map.move({ from: oldCoordinates, to: newCoordinates });
}
this.set('_previousCoordinates', newCoordinates);
}
});
import diffAttrs from 'ember-diff-attrs';
export default Ember.Component.extend({
didReceiveAttrs: diffAttrs('email', 'isAdmin', function(changedAttrs, ...args) {
this._super(...args);
if(changedAttrs && changedAttrs.email) {
let oldEmail = changedAttrs.email[0],
newEmail = changedAttrs.email[1];
// Do stuff
}
})
});
Some quick notes:
Refer addon README for usage
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With