PDI · Question #16
Which two are best practices when it comes to component and application event handling? (Choose two.)
The correct answer is A. Reuse the event logic in a component bundle, by putting the logic in the helper. C. Handle low-level events in the event handler and re-fire them as higher-level events. Best practices for Lightning component and application event handling include reusing event logic in the helper and handling low-level events by re-firing them as higher-level events.
Question
Which two are best practices when it comes to component and application event handling? (Choose two.)
Options
- AReuse the event logic in a component bundle, by putting the logic in the helper.
- BUse component events to communicate actions that should be handled at the application level.
- CHandle low-level events in the event handler and re-fire them as higher-level events.
- DTry to use application events as opposed to component events.
How the community answered
(44 responses)- A89% (39)
- B5% (2)
- D7% (3)
Why each option
Best practices for Lightning component and application event handling include reusing event logic in the helper and handling low-level events by re-firing them as higher-level events.
Placing shared event handling logic in the component's helper JavaScript file promotes code reuse across multiple handlers or components and improves maintainability by centralizing business logic.
Component events are designed for contained communication within a component hierarchy, whereas application events are more appropriate for actions handled at the global or application level.
Handling granular, low-level events and encapsulating them by re-firing as more abstract, higher-level events simplifies component communication and reduces tight coupling between disparate components.
It is generally a best practice to prefer component events over application events because application events have a broader scope, which can make debugging and managing event flows more challenging.
Concept tested: Lightning Event Handling Best Practices
Source: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/events_best_practices.htm
Topics
Community Discussion
No community discussion yet for this question.