Skip to content

Instantly share code, notes, and snippets.

@sohalloran
Last active May 1, 2018 13:00
Show Gist options
  • Save sohalloran/9d2c6b53cf8fe510ba61a27a86e48b28 to your computer and use it in GitHub Desktop.
Save sohalloran/9d2c6b53cf8fe510ba61a27a86e48b28 to your computer and use it in GitHub Desktop.
<aura:application extends="force:slds">
<lightning:card title="bubbleApp">
<c:bubbleGrandParent/>
</lightning:card>
</aura:application>
<aura:component>
<aura:attribute name="message" type="String" default="Hi!"/>
<aura:attribute name="result" type="String"/>
<aura:registerEvent name="bubbleEvent" type="c:bubbleEvent"/>
<aura:handler name="bubbleEvent" event="c:bubbleEvent" action="{!c.showMessage}"/>
<lightning:layout verticalAlign ="center">
<lightning:layoutItem padding="around-large">
<lightning:input type="Text" name="message" label="message" value="{!v.message}"/>
</lightning:layoutItem>
<lightning:layoutItem padding="around-large">
<lightning:button label="OK" onclick="{!c.sendMessage}"/>
</lightning:layoutItem>
<lightning:layoutItem padding="around-large">
Child: <ui:outputText value="{!v.result}"/>
</lightning:layoutItem>
</lightning:layout>
</aura:component>
({
sendMessage : function(component, event, helper) {
console.log('send');
component.getEvent('bubbleEvent').setParams({'message':component.get('v.message')}).fire();
},
showMessage : function(component, event, helper) {
component.set('v.result',event.getParam('message'));
},
})
<aura:component >
<aura:attribute name="result" type="String"/>
<aura:handler name="bubbleEvent" event="c:bubbleEvent" action="{!c.showMessage}"/>
<lightning:layout verticalAlign ="center">
<c:bubbleParent/>
&nbsp;GrandParent: <ui:outputText value="{!v.result}"/>
</lightning:layout>
</aura:component>
({
showMessage : function(component, event, helper) {
component.set('v.result',event.getParam('message'));
},
})
<aura:component >
<aura:attribute name="result" type="String"/>
<aura:handler name="bubbleEvent" event="c:bubbleEvent" action="{!c.showMessage}"/>
<lightning:layout verticalAlign ="center">
<c:bubbleChild/>
Parent: <ui:outputText value="{!v.result}"/>
</lightning:layout>
</aura:component>
({
showMessage : function(component, event, helper) {
component.set('v.result',event.getParam('message'));
},
})
<aura:event type="COMPONENT">
<aura:attribute name="message" type="String"/>
</aura:event>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment