From 69afe035dd10f689f47e2096a99cc379ddc1e95e Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Tue, 4 Jun 2024 15:35:31 -0300 Subject: [PATCH] vgi: Use computed for filtering of variable names This passed to Vue the responsability over updating the variable state, which result in a better performance, as well as a cleaner code. --- .../mini-widgets/VeryGenericIndicator.vue | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/components/mini-widgets/VeryGenericIndicator.vue b/src/components/mini-widgets/VeryGenericIndicator.vue index 26702c0f5..14bf1aac9 100644 --- a/src/components/mini-widgets/VeryGenericIndicator.vue +++ b/src/components/mini-widgets/VeryGenericIndicator.vue @@ -324,25 +324,19 @@ watchThrottled( // Search for variable using fuzzy-finder const variableNameSearchString = ref('') -const variableNamesToShow = ref([]) const allVariablesNames = ref([]) const showVariableChooseModal = ref(false) const showIconChooseModal = ref(false) -watchThrottled( - [variableNameSearchString, allVariablesNames], - () => { - if (variableNameSearchString.value === '') { - variableNamesToShow.value = allVariablesNames.value - return - } +const variableNamesToShow = computed(() => { + if (variableNameSearchString.value === '') { + return allVariablesNames.value + } - const variableNameFuse = new Fuse(allVariablesNames.value, fuseOptions) - const filteredVariablesResult = variableNameFuse.search(variableNameSearchString.value) - variableNamesToShow.value = filteredVariablesResult.map((r) => r.item) - }, - { throttle: 300 } -) + const variableNameFuse = new Fuse(allVariablesNames.value, fuseOptions) + const filteredVariablesResult = variableNameFuse.search(variableNameSearchString.value) + return filteredVariablesResult.map((r) => r.item) +}) const chooseVariable = (variable: string): void => { miniWidget.value.options.variableName = variable