One Customer Platform to connect everything.
For any Salesforce related training (Admin,Apex,Advance Apex,Web Services,Lightening).
contact me at Mobile Number: +91-8050010804,9113835016
Email: grv.shukla2@gmail.com
Now if we need to understand in Lightning terms, then we create
different events which will be used by components to interact between
them. Below are different steps for this event handling:
Create a Lightning event and create different attributes in it which can be used to pass information between components.
Component which want to fire an event needs to first register for an
event by using <aura:registerEvent>. Then only it can fire an
event and other component can receive it.
Component which wants to receive information will handle the event
using <aura:handler> and type as Ligthning Event which we create.
Lightning framework is based on event-driven architecture which allows
to communicate between different events. Lightning events can be fired
or handled by javascript controller. Event are triggered by user action.
As we know that along with system events, there are 2 types of custom lightning events:
Application Events
Component Events
Here I am going to explain difference between them along with code sample.
Component Events
Components events can be handled by same component or component
which is present in containment hierarchy (component that instantiates
or contain component).
These events are fired automatically by the framework such as during
component initialization, attribute value change, rendering etc. All
Components can register for system events in their HTML markup.
Few examples of system events are init, aura:waiting, aura:doneWaiting, aura:doneRendering etc.
If app or component is rerendered, then init event is fired. If
server side call is made in init then, aura:waiting event is fired. Once
the server call is finished then aura:doneWaiting event is fired. After
this aura:doneRendering is fired.
Events Best Practices:
Always try to use component events. Component event usage is more
localized as these can be used by same component or component in
containment hierarchy.
If you use application events then it may fire system events.
Use Application events only if components are present in 2 different app or are not in containment hierarchy.
I have created GitHub project which contains example demo for
Application events and Component Events. You can download complete code
from below URL:
When you create a new Lightning component you create what Salesforce calls a bundle. Below is an image of a bundle generated in the Developer Console and a brief explanation describing the purpose of each file.
HELPER:
This contains functions that contain business logic and reusable code.
It is best practice to pass in component, event and helper but it is not
necessary.