In Aurelia binding if in a component we use observable decoration on a property, and if the property being an object, then we will subscribe to all properties of that object.
For example:
import { observable } from 'aurelia-framework';
export class Car {
@observable color = {rgb: '', hex: ''};
colorChanged(newValue, oldValue) {
// this will fire whenever the 'color' property changes
}
}
So if one of the color properties changes, then it will fire colorChanged. But in custom elements we have bindables like this:
import {bindable, bindingMode} from 'aurelia-framework';
export class SecretMessageCustomElement {
@bindable data;
dataChanged () {
// -------
}
}
then dataChanged won't be called on its properties change. How can this be solved?
With some tries, I have written some lines of code that fixed my issue and hope helping others. I have subscribed and unsubscribed on every data change occuring and made this subscription to be done on every field every time. So here is the solution:
although this is part of code, it has the main idea. TG.