2

I am trying to use Bob Buzzard approach to get Lightning Component Polymorphism working, so I have method

myAction: function(component) {
    component.getConcreteComponent().getDef().getHelper().callHelperMethod();
}

however, I receive an error

TypeError: Action failed: c:MyComponent$controller$myAction [component.getConcreteComponent(...).getDef is not a function] Callback failed: apex://c:MyComponentController/ACTION$myAction

Why getDef is no longer available in Lightning? I can see that it is still present in Aura framework code

  • 1
    You can access the aura doc using: https://your-org.lightning.force.com/auradocs/reference.app#reference?topic=api:Component. There is no getDef() method. Neither getHelper() method. – Martin Lezer Oct 2 '17 at 12:26
  • Yeah, getDef() was never a documented method. However, due to Bob Buzzard article it used to be accessible – Patlatus Oct 2 '17 at 15:49
  • I describe a solution using aura:method there : salesforce.stackexchange.com/questions/118270/… – Nicolas Vuillamy Oct 5 '17 at 0:08
0

I ended up using

if ( !component.isConcrete() ) return;

code in the parent component helper.

So my parent component looks like this

<aura:component extensible="true">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="importantAttribute" type="Object"/>
    <aura:handler name="change" value="{!v.importantAttribute}" action="{!c.myAction}"/>
</aura:component>

my parent component controller

({
    doInit: function(component, event, helper) {
        // do a lot of stuff and set importantAttribute
    },

    myAction: function(component, event, helper) {
        helper.callImportantMethod(component);
    }
})

my parent component helper

({
    callImportantMethod: function(component) {
        if ( !component.isConcrete() ) return;
        // Execute Important logic in parent
    }, //other important methods
})

So my child component looks like this

<aura:component extends="c:ParentComponent">
    <aura:handler name="change" value="{!v.importantAttribute}" action="{!c.myAction}"/>
</aura:component>

my child component controller

({
    myAction: function(component, event, helper) {
        helper.callImportantMethod(component);
    }
})

my child component helper

({
    callImportantMethod: function(component) {
        // Execute DIFFERENT Important logic in child
    }, //other important methods
})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.