Events | Lightning Aura Components

4 minute read
0

How do we develop Lightning components?

Using two programming models, we can develop the lightning components;

1.Native Aura Components model (Aura)

2.Lightning web components model(LWC)

Within Aura components we can use any of the basic data types, e.g. String, Boolean, Date, Object etc and arrays of those datatypes. We can also define Aura attributes to hold SObjects and move advanced datatypes such as functions, Apex defined datatypes and we can define an attribute which can store other components.

In LWC, things are a lot more straightforward, since we do not need to define data types on our attributes. This means that an attribute of an LWC can hold any JavaScript data type – for example, we can hold all the standard data types, functions, HTML Nodes, Promises and anything else that we may require.

What is Aura, and what is the use of aura: namespace?

The Lightning Component framework is a UI framework for developing web apps for mobile and desktop devices. It’s a modern framework for building single-page applications with dynamic, responsive user interfaces for Lightning Platform apps. It uses JavaScript on the client-side and Apex on the server-side.

With JavaScript being used at the client-side as well as the involvement of Apex on the server side, the Lightning framework is known as a new app-centric model that provides business and data logic to develop dynamic web applications meant for desktop and mobile devices. This framework does not entirely replace a page at a time, rather, it leverages JavaScript to create, transform, and animate the user interface. Lightning Components and Applications use “Bundles” to store necessary files.

Aura is a freeware technology that powers the lighting components. Aura: namespace comprises all the main building blocks to define applications and components.

Explain different types of events of Salesforce lightning components?

Following are the different types of events of salesforce lightning components:

System Events: During the lightning app lifecycle, salesforce fires the system events.

Application Event: The application event extent is across the lightning application, and any element that has enrolled for his event will get an alert.

Component Event: The component event scope is within itself, or within the parent component of this event, all the parent components will get an alert.

Differentiate between component events and application events

The following table lists the differences between component events and application events :

Component Event Application Event
The component that instantiates or contains the component can handle component events. Any component with an event handler is able to handle application events. These events follow the usual publish-subscribe format.
Only child components can register component events, which are then handled by the parent component. The application event can be utilised anywhere in the app.
For a component event, we utilise the aura:event tag's type="COMPONENT" property. For an application event, we utilise the aura:event tag's type="APPLICATION" property.
When processing component events, the name property in aura:handler must be specified. The name attribute in aura:handler must match the name attribute in the aura:registerEvent tag in the event-firing Child Component. There is no need to give the name attribute in aura:handler when handling application events.
In JavaScript, we use cmp.getEvent("eventName") to get an instance of the Component type event. In JavaScript, we acquire an instance of the Application type event by calling $A.get("e.myNamespace:myAppEvent").

Post a Comment

0Comments
Post a Comment (0)