I would like to find out which cases are appropriate for using inheritance in lightning components, particularly how can we use polymorphism by extending lightning componets or maybe implementing custom interfaces? As far as I know according to this article https://developer.salesforce.com/blogs/developer-relations/2015/03/salesforce-lightning-components-by-example-component-extension.html we can only inherit parent attributes and helper methods
e.g.
parent
<aura:component extensible="true" abstract="true" controller="ObjectPanelController">
<aura:attribute name="sObjectType" type="String" required="true" />
<aura:attribute name="maxRows" type="Integer" default="20" />
<aura:attribute name="fields" type="String" />
<aura:attribute name="records" type="Object[]" />
<aura:attribute name="sObjectInfo" type="Object" />
</aura:component>
helper:
navigateToRecord : function(component, event, helper) {
///
},
deleteRecord : function(component, event, helper) {
////
}
Child
<aura:component extends="c:objectPanel">
<aura:set attribute="sObjectType" value="Account" />
<aura:set attribute="fields" value="AccountNumber,Website" />
<a onclick="{!c.deleteRecord}">Del</a> |
<a onclick="{!c.navigateToRecord}">navigate</a>
</aura:component>
Controller
({
navigateToRecord : function(component, event, helper) {
helper.navigateToRecord(component);//calls parent helper
},
deleteRecord : function(component, event, helper) {
helper.deleteRecord(component); //calls parent helper
}
})
Could we have other reasonable use cases of inheritance with using polymorphism for instance something like this
<aura:attribute name="MainComponent" type="Object[]" />
<aura:iteration items="{!v.MainComponent}" var="main">
{!main}
// particular instance that extends MainComponent
</aura:iteration>