1.

Explain how a component event propagates in the context of Salesforce Lightning.

Answer»

For component event propagation, the framework offers capture and BUBBLE phases. These phases are similar to DOM handling patterns in that they allow interested components to engage with an event and maybe impact how future handlers behave.

The source component is the component that fires an event. The framework enables you to manage the event in stages. These phases provide you with the freedom to decide how to handle the event in your application.

The phases are as follows:

  • Capture: The event is caught and passed down to the source component from the application ROOT. A component in the containment hierarchy that receives the captured event can handle the event. From the application root down to the source component that triggered the event, event handlers are called in succession. Any registered handler in this stage can prevent the event from propagating, at which point neither this phase nor the bubble phase will call any additional handlers.
  • Bubble: The event can be HANDLED by the component that triggered it. The event then PROPAGATES up to the application root from the source component. A component in the containment hierarchy that gets the BUBBLED event can handle the event.
    The event handlers are called in the order that they were triggered, starting with the source component that fired the event and ending with the application root.
    In this phase, any registered handler can stop the event from propagating, at which point no more handlers are called.


Discussion

No Comment Found