Blame view

utils/utils.js 458 Bytes
20f33942   刘淇   反正多次提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  export function debounce(func, wait = 1000, immediate = true) {
    let timer;
    return function() {
      let context = this,
        args = arguments;
      if (timer) clearTimeout(timer);
      if (immediate) {
        let callNow = !timer;
        timer = setTimeout(() => {
          timer = null;
        }, wait);
        if (callNow) func.apply(context, args);
      } else {
        timer = setTimeout(() => {
          func.apply(context, args);
        }, wait)
      }
    }
  }