UNPKG

@progress/kendo-angular-common

Version:
70 lines (69 loc) 2.63 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2020 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var core_1 = require("@angular/core"); var rxjs_1 = require("rxjs"); /* tslint:disable:align */ /** * @hidden */ var ResizeBatchService = /** @class */ (function () { function ResizeBatchService(ngZone) { this.ngZone = ngZone; this.scheduled = []; this.resolvedPromise = Promise.resolve(null); this.flush = this.flush.bind(this); } ResizeBatchService.prototype.schedule = function (instance, method) { var _this = this; this.scheduled.push({ instance: instance, method: method }); if (!this.subscription) { this.ngZone.runOutsideAngular(function () { _this.subscription = rxjs_1.from(_this.resolvedPromise) .subscribe(_this.flush); }); } }; ResizeBatchService.prototype.isScheduled = function (instance) { return Boolean(this.scheduled.find(function (item) { return item.instance === instance; })); }; ResizeBatchService.prototype.cancel = function (instance) { var scheduled = this.scheduled; var count = scheduled.length; for (var idx = 0; idx < count; idx++) { if (scheduled[idx].instance === instance) { scheduled.splice(idx, 1); if (!scheduled.length) { this.unsubscribe(); } return; } } }; ResizeBatchService.prototype.ngOnDestroy = function () { this.unsubscribe(); }; ResizeBatchService.prototype.unsubscribe = function () { if (this.subscription) { this.subscription.unsubscribe(); this.subscription = null; } }; ResizeBatchService.prototype.flush = function () { this.scheduled.forEach(function (item) { item.method.call(item.instance); }); this.scheduled = []; this.unsubscribe(); }; ResizeBatchService = tslib_1.__decorate([ core_1.Injectable(), tslib_1.__metadata("design:paramtypes", [core_1.NgZone]) ], ResizeBatchService); return ResizeBatchService; }()); exports.ResizeBatchService = ResizeBatchService;