diff options
| author | Haishan <[email protected]> | 2020-03-20 22:19:56 +0800 |
|---|---|---|
| committer | Haishan <[email protected]> | 2020-03-21 13:33:43 +0800 |
| commit | 8e48c01e7aada6978e92a6da1d040f3ef0d37945 (patch) | |
| tree | 63cdf772b88d2cff340449ba98225bdbad526a19 /src/misc | |
| parent | c5d70b5236be5ce0fb067bab3c8eeb6e946a73dd (diff) | |
feat: remembers group collapse state
for https://github.com/haishanh/yacd/issues/480
Diffstat (limited to 'src/misc')
| -rw-r--r-- | src/misc/utils.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/misc/utils.js b/src/misc/utils.js new file mode 100644 index 0000000..66146c0 --- /dev/null +++ b/src/misc/utils.js @@ -0,0 +1,23 @@ +export function throttle(fn, timeout) { + let pending = false; + + return (...args) => { + if (!pending) { + pending = true; + fn(...args); + setTimeout(() => { + pending = false; + }, timeout); + } + }; +} + +export function debounce(fn, timeout) { + let timeoutId; + return (...args) => { + if (timeoutId) clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + fn(...args); + }, timeout); + }; +} |
