A component event is fired from the instance of a component. It can be handled either by the component who has fired this event or any other component in the hierarchy that receives the component event and has a handler defined to handle that component event.
By default, the component events traverse in Bubble Phase.
In this post, you learned about the Component Events in lightning. You got answers to queries like:- What are component events ? How these events propagate through our application ? Which path they follow ? In the next post, we are going to jump on to code to see a live demo of Component Events in Lightning and there will be a youtube video too showing the whole demo which I'll upload to SFDC Stop Youtube Channel. You can directly go to the next post by clicking here. Stay tuned and post your feedback in the comments section below. Also share this blog if you liked it.
Happy Trailblazing..!!
Propagation of Component Event
There are mainly two phases in component event propagation :-
- Bubble Phase
- Capture Phase
Bubble Phase
In this phase, when an event is fired, it'll traverse up in the hierarchy and will end at the application root. In this phase, any component in the hierarchy in which we have defined a handler for that event can handle that event or even stop it from propagating further towards application root.
In this phase, the event traverses from source component to top by traversing the components in hierarchy and will stop finally at the application root. The source component who fired the event, can easily handle that event without any restrictions as the propagation starts from itself.
Component Event Propagation in Bubble Phase |
Capture Phase
In this phase, when an event is fired, it'll move directly to the application root and then from the application root it will move through the path that ends at the component who fired this event. While traversing this path, any other component in which we have defined a handler for that event can handle that event and even stop that event from propagating further in the hierarchy.
In this phase, the event traverses directly from source component to top and then move towards bottom by traversing the components in hierarchy back to source component. The event cannot be handled by the source component which fired the event if it's propagation is stopped by any other component in the hierarchy while traversing down from application root to source component.
Component Event Propagation in Capture Phase |
By default, the component events traverse in Bubble Phase.
In this post, you learned about the Component Events in lightning. You got answers to queries like:- What are component events ? How these events propagate through our application ? Which path they follow ? In the next post, we are going to jump on to code to see a live demo of Component Events in Lightning and there will be a youtube video too showing the whole demo which I'll upload to SFDC Stop Youtube Channel. You can directly go to the next post by clicking here. Stay tuned and post your feedback in the comments section below. Also share this blog if you liked it.
Happy Trailblazing..!!
Nice explanation!!
ReplyDeleteHappy to see that you liked it Krishnakumari. Do share it among others too :-)
DeleteThis comment has been removed by a blog administrator.
ReplyDeletePlease don't spam Javed. I am going to delete this right now.
DeleteThis comment has been removed by a blog administrator.
ReplyDeletePlease don't spam. I am going to remove it right now
DeleteThis comment has been removed by a blog administrator.
ReplyDeletePlease don't spam. I am going to remove it right now
DeleteVery nice post my doubts on bubble and capture phase got clear with the diagram
ReplyDeleteThank you for the feedback Smriti. Do share it in your network too :-)
DeleteHi Rahul,
ReplyDeleteVery nice explanation. I have nice my depended pick list are not updating/ displaying properly. Can you please fix the issue. My code as follows:
Hi Pramod, I think I already got your message from messenger. Stuck in festive season, will reply you there :-) Thanks for reaching out.
Deletehow can i repeat a component multiple times based on user input. for example there is a number field which can have a maximum value of 5, if a user select 5 it should create 4 new components
ReplyDeleteYou can do that by javascript. You can also create lightning components dynamically using js or repeat the form in a single component for each record.
DeleteGreat one !!!
ReplyDeleteThank You. Make sure to share it in your network too :-)
DeleteNice explanation!!
ReplyDeleteThank You Garvita. Make sure to share it in your network too :-)
DeleteSuperb Rahul, You are simply star. I love you.
ReplyDeleteThanks a lot..!! Make sure to share it in your network too :-)
DeleteSuperb Rahul, you are simply great, so helpful. I Love you.
ReplyDeleteThanks a lot Khalid :-) Make sure to share it in your network too :-)
Deletegood post!
ReplyDeleteGood to see that you liked it Fernanda, make sure to share it in your network too :-)
DeleteThanks Rahul
ReplyDeleteNice Explanation! Thank you
ReplyDeleteThis has been the most clear explanation in written form. THANKYOU
ReplyDelete