Skip to content

Instantly share code, notes, and snippets.

@vspruyt-sol
Last active March 9, 2020 13:17
Show Gist options
  • Save vspruyt-sol/b534efd3acd1feb1c2d4c43e4a437083 to your computer and use it in GitHub Desktop.
Save vspruyt-sol/b534efd3acd1feb1c2d4c43e4a437083 to your computer and use it in GitHub Desktop.
Computed property vs overhead
@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