MCPcopy Create free account
hub / github.com/ReactTooltip/react-tooltip / debounced

Function debounced

src/utils/debounce.ts:16–39  ·  view source on GitHub ↗
(this: T, ...args: A)

Source from the content-addressed store, hash-verified

14 let currentFunc = func
15
16 const debounced = function debounced(this: T, ...args: A): void {
17 const later = () => {
18 timeout = null
19 if (!immediate) {
20 currentFunc.apply(this, args)
21 }
22 }
23
24 if (immediate && !timeout) {
25 /**
26 * there's no need to clear the timeout
27 * since we expect it to resolve and set `timeout = null`
28 */
29 currentFunc.apply(this, args)
30 timeout = setTimeout(later, wait)
31 }
32
33 if (!immediate) {
34 if (timeout) {
35 clearTimeout(timeout)
36 }
37 timeout = setTimeout(later, wait)
38 }
39 }
40
41 debounced.cancel = () => {
42 /* c8 ignore start */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected