ng-zorro-antd-yj
Version:
An enterprise-class UI components based on Ant Design and Angular
86 lines • 6.02 kB
JavaScript
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
import * as tslib_1 from "tslib";
// tslint:disable:no-any typedef no-invalid-this
import { cancelRequestAnimationFrame, reqAnimFrame } from '../polyfill/request-animation';
/**
* @param {?} fn
* @return {?}
*/
export default function throttleByAnimationFrame(fn) {
/** @type {?} */
var requestId;
/** @type {?} */
var later = (/**
* @param {?} args
* @return {?}
*/
function (args) { return (/**
* @return {?}
*/
function () {
requestId = null;
fn.apply(void 0, tslib_1.__spread(args));
}); });
/** @type {?} */
var throttled = (/**
* @param {...?} args
* @return {?}
*/
function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
if (requestId == null) {
requestId = reqAnimFrame(later(args));
}
});
// tslint:disable-next-line:no-non-null-assertion
((/** @type {?} */ (throttled))).cancel = (/**
* @return {?}
*/
function () { return cancelRequestAnimationFrame((/** @type {?} */ (requestId))); });
return throttled;
}
/**
* @return {?}
*/
export function throttleByAnimationFrameDecorator() {
return (/**
* @param {?} target
* @param {?} key
* @param {?} descriptor
* @return {?}
*/
function (target, key, descriptor) {
/** @type {?} */
var fn = descriptor.value;
/** @type {?} */
var definingProperty = false;
return {
configurable: true,
get: /**
* @return {?}
*/
function () {
if (definingProperty || this === target.prototype || this.hasOwnProperty(key)) {
return fn;
}
/** @type {?} */
var boundFn = throttleByAnimationFrame(fn.bind(this));
definingProperty = true;
Object.defineProperty(this, key, {
value: boundFn,
configurable: true,
writable: true
});
definingProperty = false;
return boundFn;
}
};
});
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGhyb3R0bGVCeUFuaW1hdGlvbkZyYW1lLmpzIiwic291cmNlUm9vdCI6Im5nOi8vbmctem9ycm8tYW50ZC15ai8iLCJzb3VyY2VzIjpb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