Skip to content

Instantly share code, notes, and snippets.

@iamsonal
Created June 28, 2017 08:31
Show Gist options
  • Save iamsonal/9cf33f7f80ec7d284ae5ad5231e1f871 to your computer and use it in GitHub Desktop.
Save iamsonal/9cf33f7f80ec7d284ae5ad5231e1f871 to your computer and use it in GitHub Desktop.
<!--c:eventsHandler-->
<aura:component>
<aura:attribute name="name" type="String"/>
<aura:attribute name="mostRecentEvent" type="String" default="Most recent event handled:"/>
<aura:attribute name="numComponentEventsHandled" type="Integer" default="0"/>
<aura:attribute name="numApplicationEventsHandled" type="Integer" default="0"/>
<aura:handler event="c:appEvent" action="{!c.handleApplicationEventFired}"/>
<aura:handler name="componentEventFired" event="c:compEvent" action="{!c.handleComponentEventFired}"/>
<div>
<h3>This is {!v.name}</h3>
<p>{!v.mostRecentEvent}</p>
<p># component events handled: {!v.numComponentEventsHandled}</p>
<p># application events handled: {!v.numApplicationEventsHandled}</p>
<c:eventsNotifier parentName="{#v.name}" />
</div>
</aura:component>
/* eventsHandlerController.js */
{
handleComponentEventFired : function(cmp, event) {
var context = event.getParam("context");
cmp.set("v.mostRecentEvent",
"Most recent event handled: COMPONENT event, from " + context);
var numComponentEventsHandled =
parseInt(cmp.get("v.numComponentEventsHandled")) + 1;
cmp.set("v.numComponentEventsHandled", numComponentEventsHandled);
},
handleApplicationEventFired : function(cmp, event) {
var context = event.getParam("context");
cmp.set("v.mostRecentEvent",
"Most recent event handled: APPLICATION event, from " + context);
var numApplicationEventsHandled =
parseInt(cmp.get("v.numApplicationEventsHandled")) + 1;
cmp.set("v.numApplicationEventsHandled", numApplicationEventsHandled);
}
}
/* eventsHandler.css */
.cEventsHandler {
display: block;
margin: 10px;
padding: 10px;
border: 1px solid black;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment