attrs
in ember hooks JS-0777In 2.0.0, didReceiveAttrs
and didUpdateAttrs
hooks were introduced. These hooks are called whenever the references of arguments to a component change. These hooks receive arguments, however one should not use them as they can be very costly when you have a lot of components on the page.
import Component from '@ember/component';
export default Component({
init(...args) {
this._super(...args);
this.updated = false;
},
didReceiveAttrs(attrs) {
const { newAttrs, oldAttrs } = attrs;
if (newAttrs && oldAttrs && newAttrs.value !== oldAttrs.value) {
this.set('updated', true);
} else {
this.set('updated', false);
}
}
});
import Component from '@ember/component';
export default Component({
init(...args) {
this._super(...args);
this._valueCache = this.value;
this.updated = false;
},
didReceiveAttrs() {
if (this._valueCache !== this.value) {
this._valueCache = this.value;
this.set('updated', true);
} else {
this.set('updated', false);
}
}
});