feat: add debounce function
This commit is contained in:
parent
2c4c07441b
commit
c77854667b
1 changed files with 15 additions and 0 deletions
|
@ -1,3 +1,17 @@
|
||||||
|
const debounce = (fn: Function, delay: number = 300): any => {
|
||||||
|
let timer = 0;
|
||||||
|
const debounced = (...args: Array<any>): void => {
|
||||||
|
if (!args) args = [];
|
||||||
|
clearTimeout(timer);
|
||||||
|
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
fn.apply(fn, args);
|
||||||
|
}, delay);
|
||||||
|
};
|
||||||
|
|
||||||
|
return debounced;
|
||||||
|
};
|
||||||
|
|
||||||
const getClientLocale = (): string => {
|
const getClientLocale = (): string => {
|
||||||
return navigator.languages.length > 0 ? navigator.languages[0] : "en-US";
|
return navigator.languages.length > 0 ? navigator.languages[0] : "en-US";
|
||||||
};
|
};
|
||||||
|
@ -51,6 +65,7 @@ const dateFormat = new Intl.DateTimeFormat(getClientLocale(), {
|
||||||
});
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
debounce,
|
||||||
getClientLocale,
|
getClientLocale,
|
||||||
getAge,
|
getAge,
|
||||||
toImperial,
|
toImperial,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue