正解:A,C
Component and application events are two types of events that can be used to communicate between components in Lightning. Component events are handled by the component that fired the event or a component in its containment hierarchy. Application events are handled by any component that is listening to the event, regardless of where it is in the DOM1. Some of the best practices when it comes to component and application event handling are:
* Reuse the event logic in a component bundle, by putting the logic in the helper. This practice allows the developer to avoid duplicating code and to maintain consistency and modularity. The helper class can contain common methods that can be invoked by the controller or the renderer of the component2.
* Handle low-level events in the event handler and re-fire them as higher-level events. This practice allows the developer to abstract away the details of the low-level events and provide a more meaningful and relevant event for the consumers. For example, a component can handle a mouse click event and re-fire it as a select event with additional data3.
The other options are not best practices because:
* Use component events to communicate actions that should be handled at the application level. This practice is not recommended, because component events are scoped to the component that fired them or its parents. If the action should be handled by a component that is not in the same containment hierarchy, the component event will not reach it. Application events are more suitable for cross-component communication1.
* Try to use application events as opposed to component events. This practice is not advisable, because application events are broadcast to all components that are listening to them, which can cause performance issues and unwanted side effects. Component events are more efficient and secure, as they are only handled by the relevant components1.
References:
* : Communicating with Events
* : Helper Functions
* : Advanced Events Example