Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CoreHome/vue/src/debounce.ts')
-rw-r--r--plugins/CoreHome/vue/src/debounce.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/plugins/CoreHome/vue/src/debounce.ts b/plugins/CoreHome/vue/src/debounce.ts
new file mode 100644
index 0000000000..b92fe93a62
--- /dev/null
+++ b/plugins/CoreHome/vue/src/debounce.ts
@@ -0,0 +1,19 @@
+interface Callable {
+ (...args: unknown[]): void;
+}
+
+const DEFAULT_DEBOUNCE_DELAY = 300;
+
+export default function debounce<F extends Callable>(fn: F, delayInMs = DEFAULT_DEBOUNCE_DELAY): F {
+ let timeout: ReturnType<typeof setTimeout>;
+
+ return (...args: Parameters<F>) => {
+ if (timeout) {
+ clearTimeout(timeout);
+ }
+
+ timeout = setTimeout(() => {
+ fn(...args);
+ }, delayInMs);
+ };
+}