Skip to content

Commit

Permalink
fix: remove old debounce usages
Browse files Browse the repository at this point in the history
  • Loading branch information
patzick committed Feb 2, 2023
1 parent b3e1bce commit ece79b0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
6 changes: 6 additions & 0 deletions .changeset/few-beans-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"vue-demo-store": patch
"@shopware-pwa/cms-base": patch
---

Removed old `_debounce` usage, we should use `useDebounceFn` from Vueuse
39 changes: 18 additions & 21 deletions packages/cms-base/components/listing-filters/SwFilterPrice.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { ListingFilter } from "@shopware-pwa/types";
import { _debounce } from "@shopware-pwa/helpers-next";
import { reactive, ref, watch } from "vue";
const emits = defineEmits<{
(e: "select-value", value: { code: string; value: unknown }): void;
Expand All @@ -22,27 +21,25 @@ const toggle = () => {
const dropdownElement = ref(null);
onClickOutside(dropdownElement, () => (isFilterVisible.value = false));
watch(
() => prices.min,
_debounce((newPrice: number, oldPrice: number) => {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "min-price",
value: newPrice,
});
}, 1000)
);
function onMinPriceChange(newPrice: number, oldPrice: number) {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "min-price",
value: newPrice,
});
}
const debounceMinPriceUpdate = useDebounceFn(onMinPriceChange, 1000);
watch(() => prices.min, debounceMinPriceUpdate);
watch(
() => prices.max,
_debounce((newPrice: number, oldPrice: number) => {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "max-price",
value: newPrice,
});
}, 1000)
);
function onMaxPriceChange(newPrice: number, oldPrice: number) {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "max-price",
value: newPrice,
});
}
const debounceMaxPriceUpdate = useDebounceFn(onMaxPriceChange, 1000);
watch(() => prices.max, debounceMaxPriceUpdate);
</script>

<template>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { RouterLink } from "vue-router";
import { getProductUrl, _debounce } from "@shopware-pwa/helpers-next";
import { getProductUrl } from "@shopware-pwa/helpers-next";
import { onClickOutside, useFocus, useMagicKeys } from "@vueuse/core";
Expand Down Expand Up @@ -37,7 +37,7 @@ watch(typingQuery, (value) => {
});
// Defer the search request to prevent the search from being triggered too after typing
const performSuggestSearch = _debounce((value) => {
const performSuggestSearch = useDebounceFn((value) => {
searchTerm.value = value;
search();
}, 300);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { ListingFilter } from "@shopware-pwa/types";
import { _debounce } from "@shopware-pwa/helpers-next";
const emits = defineEmits<{
(e: "select-value", value: { code: string; value: unknown }): void;
Expand All @@ -20,27 +19,25 @@ const isOpen = ref<boolean>(false);
const dropdownElement = ref(null);
onClickOutside(dropdownElement, () => (isOpen.value = false));
watch(
() => prices.min,
_debounce((newPrice: number, oldPrice: number) => {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "min-price",
value: newPrice,
});
}, 1000)
);
function onMinPriceChange(newPrice: number, oldPrice: number) {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "min-price",
value: newPrice,
});
}
const debounceMinPriceUpdate = useDebounceFn(onMinPriceChange, 1000);
watch(() => prices.min, debounceMinPriceUpdate);
watch(
() => prices.max,
_debounce((newPrice: number, oldPrice: number) => {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "max-price",
value: newPrice,
});
}, 1000)
);
function onMaxPriceChange(newPrice: number, oldPrice: number) {
if (newPrice == oldPrice) return;
emits("select-value", {
code: "max-price",
value: newPrice,
});
}
const debounceMaxPriceUpdate = useDebounceFn(onMaxPriceChange, 1000);
watch(() => prices.max, debounceMaxPriceUpdate);
</script>

<template>
Expand Down

0 comments on commit ece79b0

Please sign in to comment.