UNPKG

react-wired-elements

Version:

Wired Elements as React components. TypeScript types included.

17 lines (16 loc) 446 B
export function debounce(func: any, wait: number, immediate?: boolean) { let timeout: any; return function() { // @ts-ignore var context = this, args = arguments; var later = function() { timeout = null; if (!immediate) func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); if (callNow) func.apply(context, args); }; }