From a6c420b54f476d1f34d7e48a961ac3282e23030d Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 22 Oct 2018 11:06:13 +0100 Subject: [PATCH] remove memory leak for mobile screens (#744) --- src/app/components/layout/layout.component.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/app/components/layout/layout.component.ts b/src/app/components/layout/layout.component.ts index 0a1a81689..2498cf768 100644 --- a/src/app/components/layout/layout.component.ts +++ b/src/app/components/layout/layout.component.ts @@ -56,6 +56,8 @@ export class LayoutComponent implements OnInit, OnDestroy { layout: SidenavLayoutComponent; onDestroy$: Subject = new Subject(); + isSmallScreen$: Observable; + expandedSidenav: boolean; currentFolderId: string; canUpload = false; @@ -76,6 +78,10 @@ export class LayoutComponent implements OnInit, OnDestroy { ) {} ngOnInit() { + this.isSmallScreen$ = this.breakpointObserver + .observe(['(max-width: 600px)']) + .pipe(map(result => result.matches)); + this.hideSidenav = this.hideConditions.some(el => this.router.routerState.snapshot.url.includes(el) ); @@ -96,11 +102,12 @@ export class LayoutComponent implements OnInit, OnDestroy { this.router.events .pipe( - withLatestFrom(this.isSmallScreen()), + withLatestFrom(this.isSmallScreen$), filter( ([event, isSmallScreen]) => isSmallScreen && event instanceof NavigationEnd - ) + ), + takeUntil(this.onDestroy$) ) .subscribe(() => { this.layout.container.toggleMenu(); @@ -170,10 +177,4 @@ export class LayoutComponent implements OnInit, OnDestroy { return expand; } - - private isSmallScreen(): Observable { - return this.breakpointObserver - .observe(['(max-width: 600px)']) - .pipe(map(result => result.matches)); - } }