MCPcopy Create free account
hub / github.com/Autodesk/react-base-table / throttle

Function throttle

src/utils.js:194–213  ·  view source on GitHub ↗
(fn, wait)

Source from the content-addressed store, hash-verified

192
193// copied from https://www.30secondsofcode.org/js/s/throttle
194export const throttle = (fn, wait) => {
195 let inThrottle, lastFn, lastTime;
196 return function() {
197 const context = this,
198 args = arguments;
199 if (!inThrottle) {
200 fn.apply(context, args);
201 lastTime = Date.now();
202 inThrottle = true;
203 } else {
204 clearTimeout(lastFn);
205 lastFn = setTimeout(function() {
206 if (Date.now() - lastTime >= wait) {
207 fn.apply(context, args);
208 lastTime = Date.now();
209 }
210 }, Math.max(wait - (Date.now() - lastTime), 0));
211 }
212 };
213};
214
215// copied from https://github.com/react-bootstrap/dom-helpers
216let scrollbarSize;

Callers 1

constructorMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected