Blame view

common/utils/debounce.js 422 Bytes
c293da23   刘淇   新园林init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  export function debounce(fn, delay = 500) {
    let timer = null;
    return function (...args) {
      if (timer) clearTimeout(timer);
      timer = setTimeout(() => fn.apply(this, args), delay);
    };
  }
  
  export function throttle(fn, interval = 500) {
    let lastTime = 0;
    return function (...args) {
      const now = Date.now();
      if (now - lastTime >= interval) {
        fn.apply(this, args);
        lastTime = now;
      }
    };
  }