How many times have you had to bind some visual object to more than one property? Many times we have to show, for example, a label with the full name that depends on the First name and the second name, or maybe we need a getFullAdress() method that returns the house number, street, city, postcode and country...
When we come across this problem we tend to do the following:
However, this will not work as desired; if we change the firstName or the familyName property, the binding events will not be dispatched and our Label object will not be updated with the new values.
Our next thought will be to use the following code:
This will work as we whant, but it doesn´t have a good performance as it will trigger too many events for doing what we need.
There is a much better way of doing the same thing (and more elegant also!) which consists on making the function Bindable and assign an event to it, then, we can dispatch that event whenever any of the values invoved change and all the function listeners will automaticaly be updated.
Here we can see a very simple example:
And here you can see the example running:
Hope it helps :)