UNPKG

@6thquake/react-material

Version:

React components that implement Google's Material Design.

26 lines (23 loc) 582 B
const debounce = (handler, wait) => { let timeout = null; return () => { if (timeout !== null) clearTimeout(timeout); timeout = setTimeout(handler, wait); }; }; const throttle = (handler, delay) => { let timer = null; let startTime = Date.now(); return () => { const curTime = Date.now(); const remaining = delay - (curTime - startTime); clearTimeout(timer); if (remaining <= 0) { handler(...arguments); startTime = Date.now(); } else { timer = setTimeout(handler, remaining); } }; }; export { debounce, throttle };