UNPKG

react-simple-channel

Version:

Lightweight and reactive tab-to-tab communication tool for React & non-React contexts. 一个轻量的 React 多标签页通信工具,支持传统函数和 Hook 两种方式。

27 lines (26 loc) 602 B
// 防抖 export function debounce(fn, delay) { var timer = null; return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (timer) { clearTimeout(timer); } timer = setTimeout(function () { return fn.apply(void 0, args); }, delay); }; } // 节流 export function throttle(fn, interval) { var lastTime = 0; return function () { var now = Date.now(); if (now - lastTime >= interval) { lastTime = now; fn.apply(void 0, arguments); } }; }