@kevinwin/

debounce

Nodejs

No description

fork
loading
Files
  • index.js

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.3137413009663461","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"ZnVuY3Rpb24gZGVib3VuY2UoZm4sIHdhaXQsIGltbWVkaWF0ZSA9IGZhbHNlKSB7CiAgICBsZXQgdGltZW91dDsKICAgIAogICAgcmV0dXJuIGZ1bmN0aW9uKC4uLmFyZ3MpIHsKICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dCk7CiAgICAgICAgY29uc3QgY2FsbE5vdyA9IGltbWVkaWF0ZSAmJiAhdGltZW91dDsKICAgICAgICB0aW1lb3V0ID0gc2V0VGltZW91dCgoKSA9PiB7IAogICAgICAgICAgdGltZW91dCA9IG51bGw7CiAgICAgICAgICBpZiAoIWltbWVkaWF0ZSkgZm4oYXJncykKICAgICAgICB9LCB3YWl0KTsKCQkgICAgaWYgKGNhbGxOb3cpIGZuKGFyZ3MpOwogICAgfQp9"},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
function debounce(fn, wait, immediate = false) {
    let timeout;
    
    return function(...args) {
        clearTimeout(timeout);
        const callNow = immediate && !timeout;
        timeout = setTimeout(() => { 
          timeout = null;
          if (!immediate) fn(args)
        }, wait);
		    if (callNow) fn(args);
    }
}
node v10.16.0