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.
31 lines
1000 B
31 lines
1000 B
|
4 months ago
|
/**
|
||
|
|
* 节流修饰器
|
||
|
|
* @param delay 节流时间
|
||
|
|
*/
|
||
|
|
export 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
|