@@ -10,6 +10,7 @@ import {
1010 Component ,
1111 HostListener ,
1212 Inject ,
13+ OnDestroy ,
1314 OnInit ,
1415 PLATFORM_ID ,
1516} from '@angular/core' ;
@@ -31,13 +32,15 @@ import { TranslateService } from '@ngx-translate/core';
3132import {
3233 BehaviorSubject ,
3334 Observable ,
35+ Subject ,
3436} from 'rxjs' ;
3537import {
3638 delay ,
3739 distinctUntilChanged ,
3840 map ,
3941 switchMap ,
4042 take ,
43+ takeUntil ,
4144 withLatestFrom ,
4245} from 'rxjs/operators' ;
4346
@@ -78,10 +81,15 @@ import { SocialService } from './social/social.service';
7881 SocialComponent ,
7982 ] ,
8083} )
81- export class AppComponent implements OnInit , AfterViewInit {
84+ export class AppComponent implements OnInit , AfterViewInit , OnDestroy {
8285 notificationOptions ;
8386 models ;
8487
88+ /**
89+ * Subject to signal component destruction and clean up subscriptions
90+ */
91+ private destroy$ : Subject < void > = new Subject < void > ( ) ;
92+
8593 /**
8694 * Whether or not the authentication is currently blocking the UI
8795 */
@@ -172,6 +180,7 @@ export class AppComponent implements OnInit, AfterViewInit {
172180 take ( 1 ) ,
173181 map ( ( currentUrl ) => [ currentUrl , event ] ) ,
174182 ) ) ,
183+ takeUntil ( this . destroy$ ) ,
175184 ) . subscribe ( ( [ currentUrl , event ] : [ string , any ] ) => {
176185 if ( event instanceof NavigationStart ) {
177186 const nextUrl = event . url ;
@@ -188,6 +197,11 @@ export class AppComponent implements OnInit, AfterViewInit {
188197 } ) ;
189198 }
190199
200+ ngOnDestroy ( ) : void {
201+ this . destroy$ . next ( ) ;
202+ this . destroy$ . complete ( ) ;
203+ }
204+
191205 @HostListener ( 'window:resize' , [ '$event' ] )
192206 public onResize ( event ) : void {
193207 this . dispatchWindowSize ( event . target . innerWidth , event . target . innerHeight ) ;
@@ -202,7 +216,10 @@ export class AppComponent implements OnInit, AfterViewInit {
202216 private trackIdleModal ( ) {
203217 const isIdle$ = this . authService . isUserIdle ( ) ;
204218 const isAuthenticated$ = this . authService . isAuthenticated ( ) ;
205- isIdle$ . pipe ( withLatestFrom ( isAuthenticated$ ) )
219+ isIdle$ . pipe (
220+ withLatestFrom ( isAuthenticated$ ) ,
221+ takeUntil ( this . destroy$ ) ,
222+ )
206223 . subscribe ( ( [ userIdle , authenticated ] ) => {
207224 if ( userIdle && authenticated ) {
208225 if ( ! this . idleModalOpen ) {
0 commit comments