Skip to content

Commit

Permalink
vgi: Use computed for filtering of variable names
Browse files Browse the repository at this point in the history
This passed to Vue the responsability over updating the variable state, which result in a better performance, as well as a cleaner code.
  • Loading branch information
rafaellehmkuhl authored and ArturoManzoli committed Jun 4, 2024
1 parent c616aad commit 69afe03
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/components/mini-widgets/VeryGenericIndicator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -324,25 +324,19 @@ watchThrottled(
// Search for variable using fuzzy-finder
const variableNameSearchString = ref('')
const variableNamesToShow = ref<string[]>([])
const allVariablesNames = ref<string[]>([])
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
Expand Down

0 comments on commit 69afe03

Please sign in to comment.