You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.throttle = throttle;
|
|
/**
|
|
* 节流修饰器
|
|
* @param delay 节流时间
|
|
*/
|
|
function throttle(delay, rightNow) {
|
|
if (delay === void 0) { delay = 0; }
|
|
if (rightNow === void 0) { rightNow = false; }
|
|
return function (target, propertyKey, descriptor) {
|
|
var func = descriptor.value;
|
|
var timeout;
|
|
if (typeof func === 'function') {
|
|
// eslint-disable-next-line
|
|
descriptor.value = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (timeout)
|
|
return;
|
|
var context = this;
|
|
if (rightNow)
|
|
func.apply(context, args);
|
|
timeout = window.setTimeout(function () {
|
|
func.apply(context, args);
|
|
timeout = null;
|
|
}, delay);
|
|
};
|
|
}
|
|
};
|
|
}
|
|
//# sourceMappingURL=throttle.js.map
|