Skip to content

Instantly share code, notes, and snippets.

@pchittum
Last active July 30, 2018 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pchittum/548020cb6cb291b161dc61f9ef58c20e to your computer and use it in GitHub Desktop.
Save pchittum/548020cb6cb291b161dc61f9ef58c20e to your computer and use it in GitHub Desktop.
Test for singleton helper in Lightning Component
Initialized compProperty value in 3:0 to 1
Initialized helperProperty value in 3:0 to 1
Initialized compProperty value in 5:0 to 1
Incremented helperProperty value in 5:0 to 2
Initialized compProperty value in 7:0 to 1
Incremented helperProperty value in 7:0 to 3
Initialized compProperty value in 9:0 to 1
Incremented helperProperty value in 9:0 to 4
Initialized compProperty value in 11:0 to 1
Incremented helperProperty value in 11:0 to 5
<aura:component >
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
</aura:component>
<aura:application access="GLOBAL" >
<c:TestSingletonHelper />
<c:TestSingletonHelper />
<c:TestSingletonHelper />
<c:TestSingletonHelper />
<c:TestSingletonHelper />
</aura:application>
({
doInit : function(component, event, helper) {
let id = component.getGlobalId();
if (!component.compProperty){
component.compProperty = 1;
console.log("Initialized compProperty value in " + id + " to 1");
} else {
component.compProperty += 1;
console.log("Incremented compProperty value in " + id + " to " + helper.helperProperty);
}
if (!helper.helperProperty) {
helper.helperProperty = 1;
console.log("Initialized helperProperty value in " + id + " to 1 ");
} else {
helper.helperProperty += 1;
console.log("Incremented helperProperty value in " + id + " to " + helper.helperProperty);
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment