UNPKG

react-lazyload

Version:

Lazyload your components, images or anything where performance matters.

28 lines (26 loc) 632 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = throttle; /*eslint-disable */ function throttle(fn, threshhold, scope) { threshhold || (threshhold = 250); var last, deferTimer; return function () { var context = scope || this; var now = +new Date(), args = arguments; if (last && now < last + threshhold) { // hold on to it clearTimeout(deferTimer); deferTimer = setTimeout(function () { last = now; fn.apply(context, args); }, threshhold); } else { last = now; fn.apply(context, args); } }; }