11import { Component , Input , OnDestroy , OnInit } from '@angular/core' ;
22import { ActivatedRoute } from '@angular/router' ;
33
4- import { BehaviorSubject , combineLatest as observableCombineLatest } from 'rxjs' ;
4+ import { BehaviorSubject , combineLatest as observableCombineLatest , Subscription } from 'rxjs' ;
55
66import { RemoteData } from '../../core/data/remote-data' ;
77import { Collection } from '../../core/shared/collection.model' ;
@@ -50,6 +50,8 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
5050 */
5151 subCollectionsRDObs : BehaviorSubject < RemoteData < PaginatedList < Collection > > > = new BehaviorSubject < RemoteData < PaginatedList < Collection > > > ( { } as any ) ;
5252
53+ subscriptions : Subscription [ ] = [ ] ;
54+
5355 constructor (
5456 protected cds : CollectionDataService ,
5557 protected paginationService : PaginationService ,
@@ -77,7 +79,7 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
7779 const pagination$ = this . paginationService . getCurrentPagination ( this . config . id , this . config ) ;
7880 const sort$ = this . paginationService . getCurrentSort ( this . config . id , this . sortConfig ) ;
7981
80- observableCombineLatest ( [ pagination$ , sort$ ] ) . pipe (
82+ this . subscriptions . push ( observableCombineLatest ( [ pagination$ , sort$ ] ) . pipe (
8183 switchMap ( ( [ currentPagination , currentSort ] ) => {
8284 return this . cds . findByParent ( this . community . id , {
8385 currentPage : currentPagination . currentPage ,
@@ -87,11 +89,12 @@ export class CommunityPageSubCollectionListComponent implements OnInit, OnDestro
8789 } )
8890 ) . subscribe ( ( results ) => {
8991 this . subCollectionsRDObs . next ( results ) ;
90- } ) ;
92+ } ) ) ;
9193 }
9294
9395 ngOnDestroy ( ) : void {
94- this . paginationService . clearPagination ( this . config . id ) ;
96+ this . paginationService . clearPagination ( this . config ?. id ) ;
97+ this . subscriptions . map ( ( subscription : Subscription ) => subscription . unsubscribe ( ) ) ;
9598 }
9699
97100}
0 commit comments