Event Handling Life-cycle:-
Mainly we will see how events fire and handling of events in lightning.
1.) Detect Firing of Event
This framework first detects the firing of an event. Just an example, the event can be triggered by way of a button click on in a notifier lightning component. In simple words we can say It detects firing of events in the re-render page on the client.
Don't forget to check out: Boost productivity with the Salesforce Inspector Chrome Extension
2.) Determine the Event Type:-
The connection between components are dealt with by using events.There are basically two sorts of custom activities inside the Lightning Framework this is Component Event and Application Event.
2.1) Component Event
The discern or container aspect instance that fired the event is recognised. This field component locates all relevant event handlers for in addition processing. Component Events can be handled via equal aspect or a thing that instantiates or consists of the aspect. The component events always be registered in the child component and it is handled by the parent component.
2.2) Application Event
Any component can have an event handler for this event. All applicable or relevant event handlers are positioned. Basically it follows a traditional publish-subscribe model. An application event is fired from an example of a component. Basically all components that provide a handler for the various events are notified.
3.) Executing the Component type Event Handler:-
Each of the event handlers characterized within the holder(container) component for the event are executed by the handler controller, which can also: Set attributes or adjust data/information on the component (causing a re-rendering of the component).
Fire another event or conjure/invoke a server-side or client-side action.
3.1) Executing an Application type Event Handler
All of the events handlers are executed. When the event handler is executed, the event occasion is passed into the event-handler.
4.) Re-render Component (it is optional)
After the event handlers and any callback activities/action are executed, a component could be naturally re-rendered in case it was adjusted amid the event taking care of preparation.
A component is instantiated, rendered, and re-rendered amid its life-cycle. A component is re-rendered as it were when there’s an automatic or esteem alter that would require a re-render, such as when a browser event triggers an activity that upgrades its information. Component life-cycle begins with making an HTTP request to the server for the component setup on the off chance that it's not cached from a past request. It begins with making the component definition, its whole parent progression, and after that makes the aspects inside those components. The framework moreover makes any component dependencies on the server, counting definitions for attributes, interfacing, controllers, and actions. Custom rendered is valuable once you need to connect with the DOM tree after the framework’s rendering benefit has embedded DOM components. In the event that you need to customize rendering behavior and you can’t do it in markup or by utilizing the init occasion, you'll make a client-side renderer.
Check out another amazing blog by Ratnesh here: Things to Consider Before Deactivating a Salesforce Trigger
For an example, simply we have an app( myApp.app ) that contains a component ( myCmp.cmp ) with a ( ui:button ) component. Nested components are rendered in a certain order. During initialization, the init() event is let go in this arrangement: ui:button, ui:myCmp, and myApp.app.
Note:- Continuously attempt to utilize a component event rather than an application event, in the event that conceivable. Component events can as it were be handled by components over them within the control progression so their usage is more localized to the components that have to be compelled to know almost them. Application events are best utilized for something that ought to be handled at the application level, such as exploring to a particular record. Application events permit communication between components that are in partitioned parts of the application and have no coordinate control relationship.