Behaviour of when the containing object is set

I have a component with this change handler in it:

<aura:attribute name="amount" type="Decimal"/>
<aura:handler name="change" value="{!v.amount}" action="{!c.handleChange}"/>

and this debug code added:

handleChange : function(component, event, helper) {
                + ' old ' + JSON.stringify(event.getParam('oldValue'))
                + ' new ' + JSON.stringify(event.getParam('value'))

The amount value is one of the fields of an object – lets call it x – that is presented by the parent component.

What I am not expecting – probably too used to Angular’s $watch – but getting is that when x is set again in the parent component as the result of an application event, the above change handler fires with x as the changed value. (The oldValue and value are the same as the content of x has not changed, it is just that x has been set again on the component.)

The aura:valueChange documentation isn’t too detailed in its definition of change. Looks like a change of an object will fire handlers on any field of the object and I guess that makes some sense. Any deeper insight or document references appreciated.


Source : Link , Question Author : Keith C , Answer Author : Community

Leave a Comment