Interview Questions – Lightning Framework – Part 4 – Application Event

Interview Questions – Lightning Framework – Part 4 – Application Event

Checkout earlier posts in interview question series to read previous questions.

27. What are application events?

Application events follow a traditional publish-subscribe model. An application event is fired from an instance of a component. All components that provide a handler for the event are notified.

Image source: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_application.htm?search_text=application%20event

Unlike component events, application events can be handled by any other component.

28. When we should use application event over component event?

If the event needs to be handled by other components which are not part of same component hierarchy, then only application events should be used. This widely used in components designed for app builder page.

Read Also: Interview Questions – Lightning Framework – Part 3 – Component Event

29. What are the steps to fire and handle an application event?

  • Create an application event.
  • Fire the application event using fire() method.
  • Declare an aura handler in your component where you intend to handle the event.

30. What are different phases for application event propagation?

The framework supports capturebubble, and default phases for the propagation of application events. The capture and bubble phases are similar to DOM handling patterns and provide an opportunity for interested components to interact with an event and potentially control the behavior for subsequent handlers. The default phase preserves the framework’s original handling behavior.

31. What is capture phase in application event propagation?

The event is captured and trickles down from the application root to the source component. The event can be handled by a component in the containment hierarchy that receives the captured event.

Event handlers are invoked in order from the application root down to the source component that fired the event.

Any registered handler in this phase can stop the event from propagating, at which point no more handlers are called in this phase or the bubble phase. If a component stops the event propagation using event.stopPropagation(), the component becomes the root node used in the default phase.

Any registered handler in this phase can cancel the default behavior of the event by calling event.preventDefault(). This call prevents execution of any of the handlers in the default phase.

Read Also: Code By Code – Lightning Framework – Chapter 17 – Application Events

32. What is bubble phase in application event propagation?

The component that fired the event can handle it. The event then bubbles up from the source component to the application root. The event can be handled by a component in the containment hierarchy that receives the bubbled event.

Event handlers are invoked in order from the source component that fired the event up to the application root.

Any registered handler in this phase can stop the event from propagating, at which point no more handlers will be called in this phase. If a component stops the event propagation using event.stopPropagation(), the component becomes the root node used in the default phase.

Any registered handler in this phase can cancel the default behavior of the event by calling event.preventDefault(). This call prevents execution of any of the handlers in the default phase.

33. What is default phase in application event propagation?

Event handlers are invoked in a non-deterministic order from the root node through its subtree. The default phase doesn’t have the same propagation rules related to component hierarchy as the capture and bubble phases. The default phase can be useful for handling application events that affect components in different sub-trees of your app.

If the event’s propagation wasn’t stopped in a previous phase, the root node defaults to the application root. If the event’s propagation was stopped in a previous phase, the root node is set to the component whose handler invoked event.stopPropagation().

34. What is the base aura tag for application event?

<aura:event type=“APPLICATION” />

35. Does application events need to be registered before firing?

Unlike component event, registering application event is optional. You can fire an application event even without registering it.

Read Also:

Manish Choudhari

I am a certified Salesforce Application & System Architect and Developer working on Salesforce Technology since 2014. Currently, I have 14 Salesforce certifications along with OCPJP (Oracle Certified Profession JavaSE6 Programmer) working in Salesforce.com Hyderabad as a Technical Engineer. Writing technical blogs, learning new technologies and frameworks and sharing knowledge is my hobby.

This Post Has 3 Comments

  1. Avatar

    Hi Manish,
    Can you share scenario based question series.
    Thanks.

Leave a Reply

Close Menu