I want to detect whether a server feature is enabled in my component during init, set the response into a Boolean attribute, then, if so, not set that again.
This is with Platform Encryption. So technically the feature license can be provisioned, but not enabled as the org has not had a first Tenant Secret record generated.
So if the init query to populate the component data returns with no records, I know there is no TenantSecret record, Platform Encryption is not enabled, and my UI can respond.
If it is enabled, I set the flag to true, and never worry about it again in the component lifecycle.
Here's the rub
The function I'm using to populate the data should work fine for refreshing data at other points in the component lifecycle. I don't want to write one refresh function for init, and other for other times. But I'm having trouble detecting the "init" event in my controller/helper.
I'm using standard init event registration in the controller.
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
I would have expected to then be able to detect this is the init event as below in my controller, but all the pertinent calls return undefined or information that is not useful:
doInit : function(component, event, helper) {
console.log(event.getName()); //Undefined
console.log(event.getParams()); //returns only instance of component
console.log(event.getSource()); //tried this just for giggles, but also undefined
So if I want to run some code in a reusable method only during the init cycle and ignore it at all other times, how do I do this?
(I have found a workaround, but will wait and see what people come back with.)
event.Wb.g.name
will equal'valueInit'
if called from theinit
handler.init
handler pass a flag parameter to your reusable function, and make that flag determine whether the conditional code is executed.event.Wb.g.name
seems precarious. Especially with LCF's newness, these kinds of undocumented Properties could very well change. The the enabled state of the feature is not the worry. It is knowing the short period of time that any handler is executing in the init state versus all the other states (render, reRender, afterRender, etc.).