Spaces:
Running
Running
Download frontend/src/engine/utils.js from chesstb/explorer: direct link, hf CLI and curl.
- Browser
- Download file 705 Bytes
-
https://huggingface.co/spaces/chesstb/explorer/resolve/main/frontend/src/engine/utils.js
- Command line
-
hf download hf://spaces/chesstb/explorer/frontend/src/engine/utils.js
-
curl -L -o utils.js https://huggingface.co/spaces/chesstb/explorer/resolve/main/frontend/src/engine/utils.js
705 Bytes
| /** | |
| * utils.js: Shared helpers | |
| */ | |
| /** | |
| * Returns a debounced version of fn that fires after `delay` ms of inactivity. | |
| * The returned function also exposes cancel(), so a caller that's about to | |
| * issue an equivalent call immediately (bypassing the debounce) can drop any | |
| * pending trailing call instead of leaving it to fire later against a | |
| * position that's no longer current. | |
| * @param {Function} fn | |
| * @param {number} delay | |
| */ | |
| export function debounce(fn, delay) { | |
| let timer; | |
| const debounced = function (...args) { | |
| clearTimeout(timer); | |
| timer = setTimeout(() => fn.apply(this, args), delay); | |
| }; | |
| debounced.cancel = () => clearTimeout(timer); | |
| return debounced; | |
| } |