Skip to content

Instantly share code, notes, and snippets.

@kmesic
Last active September 19, 2019 19:08
Show Gist options
  • Save kmesic/020a8c8e5efa703b319e0f14ac9a4b69 to your computer and use it in GitHub Desktop.
Save kmesic/020a8c8e5efa703b319e0f14ac9a4b69 to your computer and use it in GitHub Desktop.
import { LightningElement } from 'lwc';
export default class ComponentA extends LightningElement {
fireEvent() {
// Fire DOM custom event
const customEvt = new CustomEvent('custom');
this.dispatchEvent(customEvt);
}
}
<aura:component
access="global"
implements="flexipage:availableForAllPageTypes, forceCommunity:availableForAllPageTypes">
<aura:handler event="c:appEvent" action="{!c.handleApplicationEvent}"/>
</aura:component>
({
handleApplicationEvent : function(component, event) {
// Handle the event in your Aura component (component B)
}
})
<aura:component
access="global"
implements="flexipage:availableForAllPageTypes, forceCommunity:availableForAllPageTypes">
<aura:registerEvent name="eventofComponentB" type="c:appEventt"/>
<c:component-a oncustom="{!c.handleCustom}"/>
</aura:component>
({
handleCustom : function(component, event) {
var appEvent = cmp.getEvent("eventofComponentB");
// data from lwc event to pass to the aura event
appEvent.setParams({"lwcEvent" : event });
appEvent.fire();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment