Application v Component Events
In these two posts examples of application and component events are shown.
These two things should be pretty similar to each other but in this post I will provide a comparison of the differences.
Area | Application Event | Component Event |
Example Lightning Event |
<aura:event type=”APPLICATION” description=”Event template”> |
<aura:event type=”COMPONENT” description=”Event template”> <aura:attribute name=”message” type=”string”/> </aura:event> |
Event Register |
<aura:registerEvent name=”x’ type=”c:EvntMessage”/> |
<aura:registerEvent name=”sendMessage” type=”c:CompEvntMessage”/> |
Event Handler |
<aura:handler event=”c:EvntMessage” action=”{!c.handleMessage}”/> |
<aura:handler name=”sendMessage” event=”c:CompEvntMessage” action=”{!c.handleMessage}”/> |
Code to fire Event |
var appEvent = $A.get(“e.c:EvntMessage”); |
var compEvent = component.getEvent(“sendMessage”); |
Where fires |
Across all components on the page |
Bubbles up to a high level component within the same lightning component |