SFDC Stop - Always the latest about Salesforce


Full Tutorial Series with videos, free apps, live sessions, salesforce consulting and much more.


Telegram logo   Join our Telegram Channel

Saturday, 31 March 2018

Salesforce Lightning Events Part 1 - Component Events Introduction

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.

Propagation of Component Event

There are mainly two phases in component event propagation :-
  1. Bubble Phase
  2. 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..!!

27 comments:

  1. Replies
    1. Happy to see that you liked it Krishnakumari. Do share it among others too :-)

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Please don't spam Javed. I am going to delete this right now.

      Delete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Please don't spam. I am going to remove it right now

      Delete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
    Replies
    1. Please don't spam. I am going to remove it right now

      Delete
  5. Very nice post my doubts on bubble and capture phase got clear with the diagram

    ReplyDelete
    Replies
    1. Thank you for the feedback Smriti. Do share it in your network too :-)

      Delete
  6. Hi Rahul,

    Very nice explanation. I have nice my depended pick list are not updating/ displaying properly. Can you please fix the issue. My code as follows:

    ReplyDelete
    Replies
    1. Hi Pramod, I think I already got your message from messenger. Stuck in festive season, will reply you there :-) Thanks for reaching out.

      Delete
  7. how 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

    ReplyDelete
    Replies
    1. You 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.

      Delete
  8. Replies
    1. Thank You. Make sure to share it in your network too :-)

      Delete
  9. Replies
    1. Thank You Garvita. Make sure to share it in your network too :-)

      Delete
  10. Superb Rahul, You are simply star. I love you.

    ReplyDelete
    Replies
    1. Thanks a lot..!! Make sure to share it in your network too :-)

      Delete
  11. Superb Rahul, you are simply great, so helpful. I Love you.

    ReplyDelete
    Replies
    1. Thanks a lot Khalid :-) Make sure to share it in your network too :-)

      Delete
  12. Replies
    1. Good to see that you liked it Fernanda, make sure to share it in your network too :-)

      Delete
  13. Nice Explanation! Thank you

    ReplyDelete
  14. This has been the most clear explanation in written form. THANKYOU

    ReplyDelete