As explained in my previous post, application events are the easiest to fire and handle. But as they said, with great power comes great responsibility. Application events while being easy to implement, can cause your application channels to get clogged if used unwisely and relentlessly. So lets see the basic structure of an application event.
<aura:event type=”APPLICATION” description=”Event template”>
<aura:attribute name=”student” type=”Student__c”></aura:attribute>
This is what an application event looks like in its definition. The type determines whether this is an application event or a component event. In this case it is an application event. Every event can carry a payload within itself. That way an event becomes even more useful because it is carrying information that could be useful to other components. In this case the component has a payload of type Student__c.
Before we can fire an event, the firing component needs to register the event to let the framework know that it may fire an event of that type. Without registering an event you can’t fire it. This is not true about system events though. The framework already knows about them, you just need to fire them. Let’s see how you can register an event.
<aura:registerevent name=”updStudEvent” type=”c:updateStudents”></aura:registerevent>