I'm trying learn event propagation in LWC. As per the documentation it says {bubble: true, composed: false}
means the event does not cross the shadow boundary, but it bubbles up the shadow boundary. I don't know where the shadow boundary ends?
This is my playground link and following my LWC related code:
parent.html
<template>
<div onnotify={handleNotifyOutter}>
<c-child onnotify={handleNotifyInner}></c-child>
</div>
</template>
parent.js
export default class App extends LightningElement {
handleNotifyOutter(event) {
console.log('handleNotifyOutter in parent');
}
handleNotifyInner(event) {
console.log('handleNotifyInner in parent');
}
}
child.html
<template>
<div onnotify={handleNotifyOutter}>
<c-grand-child onnotify={handleNotifyInner}></c-grand-child>
</div>
</template>
child.js
export default class Child extends LightningElement {
handleNotifyOutter(event) {
console.log('handleNotifyOutter in child');
}
handleNotifyInner(event) {
console.log('handleNotifyInner in child');
}
}
grandChild.html
<template>
<div onnotify={handleOnNotifyOutter}>
<button onclick={handleOnClick}> click here </button>
</div>
</template>
grnadChild.js
export default class GrandChild extends LightningElement {
handleNotifyOutter(event) {
console.log('handleNotifyOutter in grand child');
}
handleOnClick(event) {
console.log('handle click')
this.dispatchEvent(new CustomEvent('notify', { bubbles: true }));
}
}
Output for the console.log
statements:
handle click
handleNotifyInner in child
handleNotifyOutter in child
handleNotifyOutter in parent
I don't know what is happening. Can anyone explain? It will helpful for me to learn.