2

Need some advise. Following is the code for lightning app, where all components are included. I am running out of various governor limits when they execute together. Hence, I am planning to make their context separate. What would be the best solution to invoke/execute each lightning components in separate context by keeping all of them single app? Thanks in advance!

<aura:application extends="force:slds">
    <c:ComponentOne />
    <c:ComponentTwo />
    <c:ComponentThree />
    <c:ComponentFour />
    <c:ComponentFive />
    <c:ComponentSix />
     .
     .
     .
</aura:application>
  • Can you clarify what do you refer by this -- I am planning to make their context separate, as how are you planning to separate the context? I would imagine using aura:if here to load the other components only when required should be your approach. – Jayant Das Oct 31 '18 at 18:10
  • Not sure what you are doing in each of them but when u talk about lazyloading compoents you use aura:If as the the child dom would not be loaded in the first place. More on Best Practices for Conditional Markup – codeyinthecloud Oct 31 '18 at 18:10
  • @JayantDas I would like to load all components in single app, hence I can't use aura:if . Assuming I have VF page and different VF components, I would have used <apex:actionFunction> inside each VF component to perform lazy loading. Similarly, I am looking for a solution in case of lightning component. – Devendra Oct 31 '18 at 18:14
  • I would like to load all components in single app, hence I can't use aura:if -- you can still use aura:if to load all components in single app. Based on what you have in your snippet in your question, you just surround other components which you want to lazy load in an aura:if and load only based on the condition. – Jayant Das Oct 31 '18 at 18:15
  • @Devendra IF you are talking about loading one component after other you will have to implement some sort of custom time based mechanaism either by aura:if or $A.createcomponent by loading them dynamically in javascript either approach would not load the dom so all the onload functionalities(such as server calls which i why your'e probably talking about governer limits) are held untill they render. One other way would be to trigger $A.createComponent on after render of each component – codeyinthecloud Oct 31 '18 at 18:18
3

I thing you can do to make context different is use action.setBackground() action. So action call that is making use of most of apex limit can be used as background action.

Another solution can be using aura:if or dynamically creating components using $A.createcomponent.

Least preferred solution can be using enqueueAction

https://medium.com/manj-force/did-a-enqueueaction-action-grouped-your-actions-f33ce710f0e3

  • 1
    Background actions do not guarantee separate execution contexts, though, only that they are separate from foreground actions. But it can definitely alleviate problems. – sfdcfox Oct 31 '18 at 18:49
  • Yes all the background actions can be grouped again that's why I asked that only API call that is consuming more limits should be background action. – Manjot Singh Oct 31 '18 at 19:36
0

Just to get the flow you are looking for you have an app container loading multiple child and you wanted to load one child after the other child to make sure the server calls on each child wont throw you into risk of governor limits.

There are couple of ways you could try this. But the idea here is to delay server calls(Run them in some kind of series setup rather than parallel)

  1. Use aura:if or $A.CreateComponent and implement some sort of time lag mechsnism(this would still will not guarantee proper series mechanism as its hard to caluculate the time)
  2. Use the aura:if or $A.CreateComponent and fire an event from the first component success response of server call that will reach to the app and load the second component and so on until you load the subsequent components
  3. Use $A.CreateComponent and fire afterRender event in the first loaded component and capture it in the parent to load the next one and so on.

Note: This is theoretical

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.