@progress/kendo-angular-common
Version:
Kendo UI for Angular - Utility Package
75 lines (74 loc) • 3.18 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2020 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var core_1 = require("@angular/core");
var operators_1 = require("rxjs/operators");
var compat_service_1 = require("./compat.service");
var observer_service_1 = require("./observer.service");
var resize_batch_service_1 = require("./resize-batch.service");
/**
* Emit up to 10 resize events per second by default.
* Chosen as a compromise between responsiveness and performance.
*/
var DEFAULT_RATE_LIMIT = 10;
/**
* Resize Sensor Component
*
* Triggers a "resize" event whenever the parent DOM element size changes.
*/
var ResizeSensorComponent = /** @class */ (function () {
function ResizeSensorComponent(resizeBatchService, element, ngZone) {
var _this = this;
/**
* The maximum number of resize events to emit per second.
*
* Defaults to 10.
*/
this.rateLimit = DEFAULT_RATE_LIMIT;
/**
* Fires when the parent DOM element has been resized.
*/
this.resize = new core_1.EventEmitter();
var serviceType = observer_service_1.ResizeObserverService.supported() ? observer_service_1.ResizeObserverService : compat_service_1.ResizeCompatService;
this.resizeService = new serviceType(resizeBatchService, element, ngZone);
var throttleTime = 1000 / (this.rateLimit || DEFAULT_RATE_LIMIT);
this.subscription = this.resizeService.resize
.pipe(operators_1.auditTime(throttleTime))
.subscribe(function () {
if (!_this.resizeService.acceptedSize) {
_this.resize.emit();
}
});
}
ResizeSensorComponent.prototype.ngAfterViewChecked = function () {
this.resizeService.checkChanges();
};
ResizeSensorComponent.prototype.ngOnDestroy = function () {
this.subscription.unsubscribe();
this.resizeService.destroy();
};
ResizeSensorComponent.prototype.acceptSize = function (size) {
this.resizeService.acceptSize(size);
};
tslib_1.__decorate([
core_1.Input(),
tslib_1.__metadata("design:type", Number)
], ResizeSensorComponent.prototype, "rateLimit", void 0);
tslib_1.__decorate([
core_1.Output(),
tslib_1.__metadata("design:type", core_1.EventEmitter)
], ResizeSensorComponent.prototype, "resize", void 0);
ResizeSensorComponent = tslib_1.__decorate([
core_1.Component({
selector: 'kendo-resize-sensor',
template: ''
}),
tslib_1.__metadata("design:paramtypes", [resize_batch_service_1.ResizeBatchService, core_1.ElementRef, core_1.NgZone])
], ResizeSensorComponent);
return ResizeSensorComponent;
}());
exports.ResizeSensorComponent = ResizeSensorComponent;