UNPKG

taro-material

Version:

Mini Program components that implement Google's Material Design.

37 lines (34 loc) 798 B
var _arguments = arguments; 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); } }; }; const identity = arr => { if (Array.isArray(arr)) { arr.forEach((item, index) => { if (!item.id) { item.id = index + 1; } }); } return arr; }; export { debounce, throttle, identity };