From 27535801578d380a8aa891dc23ac70dbc4f79468 Mon Sep 17 00:00:00 2001 From: PavlovVasil Date: Fri, 23 Nov 2018 12:09:17 +0200 Subject: [PATCH 1/4] fix(igxGrid): preventing a potential memory leak #3033 --- .../src/lib/grids/grid-base.component.ts | 36 ++++++++++++++----- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index 18161506b57..169b704b263 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -1968,6 +1968,22 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements * @hidden */ protected _columnPinning = false; + /** + * @hidden + */ + protected __keydownListener = null; + /** + * @hidden + */ + protected __vScrollListener = null; + /** + * @hidden + */ + protected __hScrollListener = null; + /** + * @hidden + */ + protected _wheelListener = null; protected _allowFiltering = false; private _filteredData = null; private resizeHandler; @@ -2143,7 +2159,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements public ngAfterViewInit() { this.zone.runOutsideAngular(() => { this.document.defaultView.addEventListener('resize', this.resizeHandler); - this.nativeElement.addEventListener('keydown', this.keydownHandler.bind(this)); + this.__keydownListener = this.nativeElement.addEventListener('keydown', this.keydownHandler.bind(this)); }); this.calculateGridWidth(); this.initPinning(); @@ -2189,11 +2205,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements ); this.zone.runOutsideAngular(() => - this.verticalScrollContainer.getVerticalScroll().addEventListener('scroll', this.verticalScrollHandler.bind(this)) + this.__vScrollListener = this.verticalScrollContainer + .getVerticalScroll() + .addEventListener('scroll', this.verticalScrollHandler.bind(this)) ); this.zone.runOutsideAngular(() => - this.parentVirtDir.getHorizontalScroll().addEventListener('scroll', this.horizontalScrollHandler.bind(this)) + this.__hScrollListener = this.parentVirtDir + .getHorizontalScroll() + .addEventListener('scroll', this.horizontalScrollHandler.bind(this)) ); this._horizontalForOfs = this._dataRowList.map(row => row.virtDirRow); const vertScrDC = this.verticalScrollContainer.dc.instance._viewContainer.element.nativeElement; @@ -2206,9 +2226,9 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements public ngOnDestroy() { this.zone.runOutsideAngular(() => { this.document.defaultView.removeEventListener('resize', this.resizeHandler); - this.nativeElement.removeEventListener('keydown', this.keydownHandler); - this.verticalScrollContainer.getVerticalScroll().removeEventListener('scroll', this.verticalScrollHandler); - this.parentVirtDir.getHorizontalScroll().removeEventListener('scroll', this.horizontalScrollHandler); + this.nativeElement.removeEventListener('keydown', this.__keydownListener); + this.verticalScrollContainer.getVerticalScroll().removeEventListener('scroll', this.__vScrollListener); + this.parentVirtDir.getHorizontalScroll().removeEventListener('scroll', this.__hScrollListener); const vertScrDC = this.verticalScrollContainer.dc.instance._viewContainer.element.nativeElement; vertScrDC.removeEventListener('scroll', (evt) => { this.scrollHandler(evt); }); }); @@ -4305,7 +4325,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this.configureRowEditingOverlay(cell.rowID); this.rowEditingOverlay.open(this.rowEditSettings); this.rowEditPositioningStrategy.isTopInitialPosition = this.rowEditPositioningStrategy.isTop; - this.rowEditingOverlay.element.addEventListener('wheel', this.rowEditingWheelHandler.bind(this)); + this._wheelListener = this.rowEditingOverlay.element.addEventListener('wheel', this.rowEditingWheelHandler.bind(this)); } /** @@ -4313,7 +4333,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements */ public closeRowEditingOverlay() { this.gridAPI.set_edit_row_state(this.id, null); - this.rowEditingOverlay.element.removeEventListener('wheel', this.rowEditingWheelHandler); + this.rowEditingOverlay.element.removeEventListener('wheel', this._wheelListener); this.rowEditPositioningStrategy.isTopInitialPosition = null; this.rowEditingOverlay.close(); this.rowEditingOverlay.element.parentElement.style.display = ''; From cae3c36e8d6d8c496b6b77939f0b8b3849377c42 Mon Sep 17 00:00:00 2001 From: PavlovVasil Date: Fri, 23 Nov 2018 15:49:14 +0200 Subject: [PATCH 2/4] fix(igxGrid): fixing variable names #3033 --- .../src/lib/grids/grid-base.component.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index 169b704b263..00597cf8272 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -1971,15 +1971,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements /** * @hidden */ - protected __keydownListener = null; + protected _keydownListener = null; /** * @hidden */ - protected __vScrollListener = null; + protected _vScrollListener = null; /** * @hidden */ - protected __hScrollListener = null; + protected _hScrollListener = null; /** * @hidden */ @@ -2159,7 +2159,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements public ngAfterViewInit() { this.zone.runOutsideAngular(() => { this.document.defaultView.addEventListener('resize', this.resizeHandler); - this.__keydownListener = this.nativeElement.addEventListener('keydown', this.keydownHandler.bind(this)); + this._keydownListener = this.nativeElement.addEventListener('keydown', this.keydownHandler.bind(this)); }); this.calculateGridWidth(); this.initPinning(); @@ -2205,13 +2205,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements ); this.zone.runOutsideAngular(() => - this.__vScrollListener = this.verticalScrollContainer + this._vScrollListener = this.verticalScrollContainer .getVerticalScroll() .addEventListener('scroll', this.verticalScrollHandler.bind(this)) ); this.zone.runOutsideAngular(() => - this.__hScrollListener = this.parentVirtDir + this._hScrollListener = this.parentVirtDir .getHorizontalScroll() .addEventListener('scroll', this.horizontalScrollHandler.bind(this)) ); @@ -2226,9 +2226,9 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements public ngOnDestroy() { this.zone.runOutsideAngular(() => { this.document.defaultView.removeEventListener('resize', this.resizeHandler); - this.nativeElement.removeEventListener('keydown', this.__keydownListener); - this.verticalScrollContainer.getVerticalScroll().removeEventListener('scroll', this.__vScrollListener); - this.parentVirtDir.getHorizontalScroll().removeEventListener('scroll', this.__hScrollListener); + this.nativeElement.removeEventListener('keydown', this._keydownListener); + this.verticalScrollContainer.getVerticalScroll().removeEventListener('scroll', this._vScrollListener); + this.parentVirtDir.getHorizontalScroll().removeEventListener('scroll', this._hScrollListener); const vertScrDC = this.verticalScrollContainer.dc.instance._viewContainer.element.nativeElement; vertScrDC.removeEventListener('scroll', (evt) => { this.scrollHandler(evt); }); }); From 538456e269fdd854cb33748a10d457160d66f085 Mon Sep 17 00:00:00 2001 From: PavlovVasil Date: Mon, 26 Nov 2018 17:05:28 +0200 Subject: [PATCH 3/4] fix(igxGrid): fixing reference to bound function #3033 --- .../src/lib/grids/grid-base.component.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index 00597cf8272..f63059841c4 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -2159,7 +2159,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements public ngAfterViewInit() { this.zone.runOutsideAngular(() => { this.document.defaultView.addEventListener('resize', this.resizeHandler); - this._keydownListener = this.nativeElement.addEventListener('keydown', this.keydownHandler.bind(this)); + this._keydownListener = this.keydownHandler.bind(this); + this.nativeElement.addEventListener('keydown', this._keydownListener); }); this.calculateGridWidth(); this.initPinning(); @@ -2204,17 +2205,15 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements .map(row => row.virtDirRow) ); - this.zone.runOutsideAngular(() => - this._vScrollListener = this.verticalScrollContainer - .getVerticalScroll() - .addEventListener('scroll', this.verticalScrollHandler.bind(this)) - ); + this.zone.runOutsideAngular(() => { + this._vScrollListener = this.verticalScrollHandler.bind(this); + this.verticalScrollContainer.getVerticalScroll().addEventListener('scroll', this._vScrollListener); + }); - this.zone.runOutsideAngular(() => - this._hScrollListener = this.parentVirtDir - .getHorizontalScroll() - .addEventListener('scroll', this.horizontalScrollHandler.bind(this)) - ); + this.zone.runOutsideAngular(() => { + this._hScrollListener = this.horizontalScrollHandler.bind(this); + this.parentVirtDir.getHorizontalScroll().addEventListener('scroll', this._hScrollListener); + }); this._horizontalForOfs = this._dataRowList.map(row => row.virtDirRow); const vertScrDC = this.verticalScrollContainer.dc.instance._viewContainer.element.nativeElement; vertScrDC.addEventListener('scroll', (evt) => { this.scrollHandler(evt); }); From 8bc2e9fdac8b99b77a360fad8f018593cc852b49 Mon Sep 17 00:00:00 2001 From: PavlovVasil Date: Tue, 27 Nov 2018 15:56:31 +0200 Subject: [PATCH 4/4] fix(igxGrid): fixing the wheel listener #3033 --- projects/igniteui-angular/src/lib/grids/grid-base.component.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts index f63059841c4..2aa0ff79c1b 100644 --- a/projects/igniteui-angular/src/lib/grids/grid-base.component.ts +++ b/projects/igniteui-angular/src/lib/grids/grid-base.component.ts @@ -4324,7 +4324,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements this.configureRowEditingOverlay(cell.rowID); this.rowEditingOverlay.open(this.rowEditSettings); this.rowEditPositioningStrategy.isTopInitialPosition = this.rowEditPositioningStrategy.isTop; - this._wheelListener = this.rowEditingOverlay.element.addEventListener('wheel', this.rowEditingWheelHandler.bind(this)); + this._wheelListener = this.rowEditingWheelHandler.bind(this); + this.rowEditingOverlay.element.addEventListener('wheel', this._wheelListener); } /**