You need to sign in to do that
Don't have an account?
Lightning Performance - Ternary IF over Standard IF
I am going through the premiere online course for Lightning Components right now and saw something I was curious about.
The particular module that I am watching is showing how tag attributes can by dynamically set using expression syntax. Nothing ground breaking there but what I found interesting was at instead of using a standard IF statement it used a ternary IF statment. At first I thought it was just a style preference by the developer who wrote the example, but I am also curious if there is some sort of efficiency gain in the lightning framework by doing so.
Basically he used:
Instead of:
I totally understand they are the exact same thing, but from an efficiency standpoint is there any benefit to doing it this way?
The particular module that I am watching is showing how tag attributes can by dynamically set using expression syntax. Nothing ground breaking there but what I found interesting was at instead of using a standard IF statement it used a ternary IF statment. At first I thought it was just a style preference by the developer who wrote the example, but I am also curious if there is some sort of efficiency gain in the lightning framework by doing so.
Basically he used:
class="{!(v.expenseSum != v.approvedSum ? 'alert-danger' : 'alert-success')}
Instead of:
class="{! IF(v.expenseSum != v.approvedSum , 'alert-danger' , 'alert-success')}
I totally understand they are the exact same thing, but from an efficiency standpoint is there any benefit to doing it this way?
Lightning Expressions are different than that of the VF expressions we are used so far .
Here is documentation of SFDC which explains this .
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/expr_conditional.htm?search_text=IF%20expression
You can use aura:if instead of the normal ternary operation but I believe aura:if is generally slower compared to ternary operations.