From 038199c4478afe5c7032494cffaa229f2fde6f25 Mon Sep 17 00:00:00 2001 From: Bram Kragten Date: Tue, 1 Jun 2021 20:53:45 +0200 Subject: [PATCH] Change the type of debounce, use arrow functions (#9328) --- src/common/entity/domain_icon.ts | 4 +--- src/common/util/debounce.ts | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/common/entity/domain_icon.ts b/src/common/entity/domain_icon.ts index 836c5024dc..adfb8873b4 100644 --- a/src/common/entity/domain_icon.ts +++ b/src/common/entity/domain_icon.ts @@ -89,8 +89,6 @@ export const domainIcon = ( } // eslint-disable-next-line - console.warn( - "Unable to find icon for domain " + domain + " (" + stateObj + ")" - ); + console.warn(`Unable to find icon for domain ${domain}`); return DEFAULT_DOMAIN_ICON; }; diff --git a/src/common/util/debounce.ts b/src/common/util/debounce.ts index 557d596540..70aaddf2e0 100644 --- a/src/common/util/debounce.ts +++ b/src/common/util/debounce.ts @@ -4,29 +4,25 @@ // be triggered. The function will be called after it stops being called for // N milliseconds. If `immediate` is passed, trigger the function on the // leading edge, instead of the trailing. -// eslint-disable-next-line: ban-types -export const debounce = unknown>( - func: T, - wait, + +export const debounce = ( + func: (...args: T) => void, + wait: number, immediate = false -): T => { - let timeout; - // @ts-ignore - return function (...args) { - // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-this-alias - const context = this; +) => { + let timeout: number | undefined; + return (...args: T): void => { const later = () => { - timeout = null; + timeout = undefined; if (!immediate) { - func.apply(context, args); + func(...args); } }; const callNow = immediate && !timeout; clearTimeout(timeout); - timeout = setTimeout(later, wait); + timeout = window.setTimeout(later, wait); if (callNow) { - func.apply(context, args); + func(...args); } }; };