I'm having issues with a very simple use case. namely display a lightning component upon a button click via refreshing an output panel, then hiding the component via rendered=false on the same output panel. then showing the component again. It appears as if another 'instance' of the component is created. What is the proper way to 'destroy' the component and remove it from the DOM without having to refresh the entire page? Thanks so much.
<apex:page id="vfLightningRefreshTest" controller="ctrlLightningRefreshTest">
<html>
<head>
<apex:stylesheet value="{!URLFOR($Resource.SLDS203_SCOPED_CARPLS, 'assets/styles/salesforce-lightning-design-system-vf.css')}" />
<apex:includeLightning />
<script>
function fRefreshlComp() {
afRefreshlComp();
}
</script>
</head>
<body>
<div class="carpls">
<div style="margin-top:20px;margin-bottom:20px;margin-left:20px">
<apex:outputPanel layout="block" id="buttons">
<button type="button"
class="slds-button slds-button--brand"
onclick="fRefreshlComp();return false;">
<apex:outputText value="Show it" rendered="{!!showComp}" />
<apex:outputText value="Hide it" rendered="{!showComp}" />
</button>
</apex:outputPanel>
</div>
<apex:form>
<apex:actionFunction name="afRefreshlComp" action="{!doRefreshlComp}"
reRender="{!$Component.lComp},{!$Component.buttons}"
oncomplete="console.log('oncomplete refreshLComp');" />
</apex:form>
<apex:outputPanel id="lComp" layout="block">
<apex:outputPanel layout="block" rendered="{!showComp}">
The below simply contains a RTE using ticyMCE but will help with debugging refreshing
Last Refreshed = {!now()}
<br/>
<script>
$Lightning.use("c:DebugServices", function() {
$Lightning.createComponent(
"c:TinyMCE",
{},
"lCompContent",
function(cmp) {
//lCmp = cmp;
});
});
</script>
<div id="lCompContent">
</div>
</apex:outputPanel>
</apex:outputPanel>
</div>
</body>
$A.componentService.countComponents()
when the outputpanel is rerendered, the count increases everytime it is shown.