Created
February 5, 2019 21:18
-
-
Save maujood/8f5ac8099c57a63a5f33d017877e9c08 to your computer and use it in GitHub Desktop.
Lighting Component Events Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:application extends="force:slds"> | |
<aura:attribute name="globalId" type="String" /> | |
<aura:registerEvent name="compEvent" type="c:LightningComponentEvent"></aura:registerEvent> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEvent}" phase="bubble"></aura:handler> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEventCapture}" phase="capture"></aura:handler> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}" /> | |
<lightning:layout multipleRows="true"> | |
<lightning:layoutItem size="12" padding="around-small"> | |
Application: {!v.globalId} | |
</lightning:layoutItem> | |
<lightning:layoutItem size="12" padding="around-small"> | |
<lightning:button aura:id="sendEvt" onclick="{!c.sendEvent}" label="Send Event"></lightning:button> | |
</lightning:layoutItem> | |
<lightning:layoutItem padding="around-small" size="6"> | |
<c:CompEventLifecycleComponentOuter></c:CompEventLifecycleComponentOuter> | |
</lightning:layoutItem> | |
<lightning:layoutItem padding="around-small" size="6"> | |
<c:CompEventLifecycleComponentOuter></c:CompEventLifecycleComponentOuter> | |
</lightning:layoutItem> | |
</lightning:layout> | |
</aura:application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit: function (component) { | |
component.set('v.globalId', component.getGlobalId()); | |
}, | |
sendEvent : function(component, event, helper) { | |
var evt = component.getEvent('compEvent'); | |
evt.fire(); | |
}, | |
handleEvent: function (component, event, helper) { | |
console.log('event in bubble phase received by application: ' + component.getGlobalId()); | |
}, | |
handleEventCapture: function (component, event, helper) { | |
console.log('event in capture phase received by application: ' + component.getGlobalId()); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component> | |
<aura:attribute name="globalId" type="String"/> | |
<aura:registerEvent name="compEvent" type="c:LightningComponentEvent"></aura:registerEvent> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEventCapture}" phase="capture"></aura:handler> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEvent}" phase="bubble"></aura:handler> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
<lightning:layout multipleRows="true"> | |
<lightning:layoutItem size="12" padding="around-small"> | |
Component: {!v.globalId} | |
</lightning:layoutItem> | |
<lightning:layoutItem size="12" padding="around-small"> | |
<lightning:button aura:id="sendEvt" onclick="{!c.sendEvent}" label="Send Event"></lightning:button> | |
</lightning:layoutItem> | |
</lightning:layout> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.THIS { | |
background-color: #999 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit: function (component, event, helper) { | |
component.set('v.globalId', component.getGlobalId()); | |
}, | |
sendEvent : function(component, event, helper) { | |
var evt = component.getEvent("compEvent"); | |
evt.fire(); | |
}, | |
handleEvent: function (component, event, helper) { | |
console.log('event in bubble phase received by inner controller: ' + component.getGlobalId()); | |
}, | |
handleEventCapture: function (component, event, helper) { | |
console.log('event in capture phase received by inner controller: ' + component.getGlobalId()); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:component> | |
<aura:attribute name="globalId" type="String"/> | |
<aura:registerEvent name="compEvent" type="c:LightningComponentEvent"></aura:registerEvent> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEvent}" phase="capture"></aura:handler> | |
<aura:handler name="compEvent" event="c:LightningComponentEvent" action="{!c.handleEventBubble}" phase="bubble"></aura:handler> | |
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> | |
<lightning:layout multipleRows="true"> | |
<lightning:layoutItem size="12" padding="around-small"> | |
Component: {!v.globalId} | |
</lightning:layoutItem> | |
<lightning:layoutItem size="12" padding="around-small"> | |
<lightning:button aura:id="sendEvt" label="Send Event" onclick="{!c.sendEvent}"></lightning:button> | |
</lightning:layoutItem> | |
<lightning:layoutItem size="6" padding="around-small"> | |
<c:CompEventLifecycleComponentInner></c:CompEventLifecycleComponentInner> | |
</lightning:layoutItem> | |
<lightning:layoutItem size="6" padding="around-small"> | |
<c:CompEventLifecycleComponentInner></c:CompEventLifecycleComponentInner> | |
</lightning:layoutItem> | |
</lightning:layout> | |
</aura:component> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.THIS { | |
background-color: #bbb | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
({ | |
doInit: function (component) { | |
component.set('v.globalId', component.getGlobalId()); | |
}, | |
sendEvent : function(component, event, helper) { | |
var evt = component.getEvent('compEvent'); | |
evt.fire(); | |
}, | |
handleEvent: function (component, event, helper) { | |
console.log('event in capture phase received by outer controller: ' + component.getGlobalId()); | |
event.stopPropagation(); | |
}, | |
handleEventBubble: function (component, event, helper) { | |
console.log('event in bubble phase received by outer controller: ' + component.getGlobalId()); | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<aura:event type="COMPONENT" description="Event template" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment