diff --git a/ui-ngx/src/app/modules/home/models/datasource/entity-datasource.ts b/ui-ngx/src/app/modules/home/models/datasource/entity-datasource.ts index 44a687ef35..168c56cef7 100644 --- a/ui-ngx/src/app/modules/home/models/datasource/entity-datasource.ts +++ b/ui-ngx/src/app/modules/home/models/datasource/entity-datasource.ts @@ -15,7 +15,7 @@ /// import { PageLink } from '@shared/models/page/page-link'; -import { BehaviorSubject, Observable, of, ReplaySubject } from 'rxjs'; +import { BehaviorSubject, Observable, of, ReplaySubject, Subscription } from 'rxjs'; import { emptyPageData, PageData } from '@shared/models/page/page-data'; import { BaseData, HasId } from '@shared/models/base-data'; import { CollectionViewer, DataSource, SelectionModel } from '@angular/cdk/collections'; @@ -28,6 +28,7 @@ export class EntitiesDataSource, P extends PageLink = private entitiesSubject = new BehaviorSubject([]); private pageDataSubject = new BehaviorSubject>(emptyPageData()); + private currentLoadSubscription: Subscription = null; public pageData$ = this.pageDataSubject.asObservable(); @@ -58,9 +59,12 @@ export class EntitiesDataSource, P extends PageLink = } loadEntities(pageLink: P): Observable> { + if (this.currentLoadSubscription) { + this.currentLoadSubscription.unsubscribe(); + } this.dataLoading = true; const result = new ReplaySubject>(); - this.fetchFunction(pageLink).pipe( + this.currentLoadSubscription = this.fetchFunction(pageLink).pipe( tap(() => { this.selection.clear(); }),