all files / grid/actions/ virtual-scroll.js

87.18% Statements 34/39
75% Branches 9/12
100% Functions 10/10
87.18% Lines 34/39
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55   10× 10× 10×   7966×   10× 10×   10× 10×   10× 10× 10× 10× 10×   10×     10× 10×   10× 10×         68×         10×        
define(["require", "exports", "../base/constant", "../base/enum", "../renderer/virtual-content-renderer", "../base/constant"], function (require, exports, constant_1, enum_1, virtual_content_renderer_1, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var VirtualScroll = (function () {
        function VirtualScroll(parent, locator) {
            this.parent = parent;
            this.locator = locator;
            this.addEventListener();
        }
        VirtualScroll.prototype.getModuleName = function () {
            return 'virtualscroll';
        };
        VirtualScroll.prototype.instantiateRenderer = function () {
            var renderer = this.locator.getService('rendererFactory');
            if (this.parent.enableColumnVirtualization) {
                renderer.addRenderer(enum_1.RenderType.Header, new virtual_content_renderer_1.VirtualHeaderRenderer(this.parent, this.locator));
            }
            renderer.addRenderer(enum_1.RenderType.Content, new virtual_content_renderer_1.VirtualContentRenderer(this.parent, this.locator));
            this.ensurePageSize();
        };
        VirtualScroll.prototype.ensurePageSize = function () {
            var rowHeight = this.parent.getRowHeight();
            this.blockSize = ~~(this.parent.height / rowHeight);
            var height = this.blockSize * 2;
            var size = this.parent.pageSettings.pageSize;
            this.parent.setProperties({ pageSettings: { pageSize: size < height ? height : size } }, true);
        };
        VirtualScroll.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(constant_1.initialLoad, this.instantiateRenderer, this);
            this.parent.on(events.columnWidthChanged, this.refreshVirtualElement, this);
        };
        VirtualScroll.prototype.removeEventListener = function () {
            Eif (this.parent.isDestroyed) {
                return;
            }
            this.parent.off(constant_1.initialLoad, this.instantiateRenderer);
            this.parent.off(events.columnWidthChanged, this.refreshVirtualElement);
        };
        VirtualScroll.prototype.refreshVirtualElement = function (args) {
            Iif (this.parent.enableColumnVirtualization && args.module === 'resize') {
                var renderer = this.locator.getService('rendererFactory');
                renderer.getRenderer(enum_1.RenderType.Content).refreshVirtualElement();
            }
        };
        VirtualScroll.prototype.destroy = function () {
            this.removeEventListener();
        };
        return VirtualScroll;
    }());
    exports.VirtualScroll = VirtualScroll;
});