web-atoms-core
Version:
44 lines • 1.58 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Defers execution for given milliseconds. And previous pending
* execution is cancelled, so only the last execution will be executed.
*
* This is important when you want to watch multiple events and avoid multiple refresh
* @param n number of milliseconds to defer
*/
function Defer(n) {
if (n === void 0) { n = 100; }
return function (target, key, descriptor) {
// tslint:disable-next-line: ban-types
var old = descriptor.value;
descriptor.value = function () {
var _this = this;
var a = [];
for (var _i = 0; _i < arguments.length; _i++) {
a[_i] = arguments[_i];
}
var k = "_$_timeout_" + key;
var id = this[k];
if (id) {
clearTimeout(id);
}
this[k] = setTimeout(function () {
_this[k] = 0;
old.apply(_this, a);
}, n);
};
};
}
exports.default = Defer;
});
//# sourceMappingURL=Defer.js.map