journey2salesforce

Method vs Component Event in Lightning

Already, we have studied about Method and Component Event in Lightning.Now, we will focus on the difference between Method and Component Event in Lightning.

 MethodComponent Event
WHENWhen the communication is needed from Parent Component to Child Component,we can use .

Method can be synchronous or asynchronous.
When the communication is needed from Child Component to Parent Component,we can use component event.

If you want to build reverse communication process, you can think about Component Event with Capture phase.

Component Event can be synchronous, but Application Event can be asynchronous.
WHYAt the time of component rendering, best practice to call the method with parameters in that component.

At the time of calling Child Component, you can call the method of Child Component explicitly to render/view the Child Component with certain attributes in proper.

At the time of extend the component, you can use the method and set the attribute directly from the inherited component.

Component Event basically occurs from bottom to top in the same containment hierarchy. In this model, at first you have to register the Component Event, fire the event and receiving the event from other immediate component present in the same containment hierarchy.
ADVANTAGEFast
Require less network bandwidth
communication speed depends on the level of containment hierarchy.

604 total views, 1 views today

Rating: 4.8/5. From 4 votes.
Please wait...

You may also like...