Last active
March 9, 2020 13:17
-
-
Save vspruyt-sol/b534efd3acd1feb1c2d4c43e4a437083 to your computer and use it in GitHub Desktop.
Computed property vs overhead
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@track arrayHasItems = false | |
@track theArray = []; | |
//Computed | |
get arrayHasItemsComputed() | |
{ | |
return this.theArray.length > 0; | |
} | |
//Not computed | |
addArrayItem(item) | |
{ | |
this.theArray.push(item); | |
this.arrayHasItems = true; //Overhead | |
} | |
removeArrayItem(item) | |
{ | |
//.. Do the actual find and remove | |
if(this.theArray.length > 0) | |
{ | |
this.arrayHasItems = true; //Overhead | |
} | |
else | |
{ | |
this.arrayHasItems = false; //Overhead | |
} | |
} | |
someLogicWhichMightOrMightNotAddOrRemoveArrayItems(items) | |
{ | |
//.. Do some logic | |
// Depending on what happened in this method, this.arrayHasItems needs to be manually updated //Overhead | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment