Browse Source

增加debounce

main
谢亚昕 3 months ago
parent
commit
bce718ba10
  1. 12
      packages/core/src/debounce/index.ts
  2. 1
      packages/core/src/index.ts

12
packages/core/src/debounce/index.ts

@ -0,0 +1,12 @@
export function debounce<T extends any[], R = void>(fn: (...argu: T) => R, duration: number = 1500) {
let timer: ReturnType<typeof setTimeout> | void;
return function f(this: void, ...argu: T) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(() => {
timer = undefined;
fn.apply(this, argu);
}, duration);
};
}

1
packages/core/src/index.ts

@ -1 +1,2 @@
export * from "./date";
export * from "./debounce";

Loading…
Cancel
Save