mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 07:16:39 +00:00
Change the type of debounce, use arrow functions (#9328)
This commit is contained in:
parent
8a1eab7ceb
commit
038199c447
@ -89,8 +89,6 @@ export const domainIcon = (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.warn(
|
console.warn(`Unable to find icon for domain ${domain}`);
|
||||||
"Unable to find icon for domain " + domain + " (" + stateObj + ")"
|
|
||||||
);
|
|
||||||
return DEFAULT_DOMAIN_ICON;
|
return DEFAULT_DOMAIN_ICON;
|
||||||
};
|
};
|
||||||
|
@ -4,29 +4,25 @@
|
|||||||
// be triggered. The function will be called after it stops being called for
|
// be triggered. The function will be called after it stops being called for
|
||||||
// N milliseconds. If `immediate` is passed, trigger the function on the
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
||||||
// leading edge, instead of the trailing.
|
// leading edge, instead of the trailing.
|
||||||
// eslint-disable-next-line: ban-types
|
|
||||||
export const debounce = <T extends (...args) => unknown>(
|
export const debounce = <T extends any[]>(
|
||||||
func: T,
|
func: (...args: T) => void,
|
||||||
wait,
|
wait: number,
|
||||||
immediate = false
|
immediate = false
|
||||||
): T => {
|
) => {
|
||||||
let timeout;
|
let timeout: number | undefined;
|
||||||
// @ts-ignore
|
return (...args: T): void => {
|
||||||
return function (...args) {
|
|
||||||
// @ts-ignore
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
||||||
const context = this;
|
|
||||||
const later = () => {
|
const later = () => {
|
||||||
timeout = null;
|
timeout = undefined;
|
||||||
if (!immediate) {
|
if (!immediate) {
|
||||||
func.apply(context, args);
|
func(...args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const callNow = immediate && !timeout;
|
const callNow = immediate && !timeout;
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(later, wait);
|
timeout = window.setTimeout(later, wait);
|
||||||
if (callNow) {
|
if (callNow) {
|
||||||
func.apply(context, args);
|
func(...args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user