[DURACOM-234] Replace Observable with BehaviorSubject

This commit is contained in:
Giuseppe Digilio
2024-04-02 18:54:39 +02:00
parent 660cf7e4dd
commit aba04913ce

View File

@@ -11,6 +11,7 @@ import { Router } from '@angular/router';
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { import {
BehaviorSubject,
Observable, Observable,
of as observableOf, of as observableOf,
Subscription, Subscription,
@@ -67,7 +68,7 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy {
/** /**
* TRUE if the page is initialized * TRUE if the page is initialized
*/ */
public initialized$: Observable<boolean>; public initialized$: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
/** /**
* Array to track all subscriptions and unsubscribe them onDestroy * Array to track all subscriptions and unsubscribe them onDestroy
@@ -88,7 +89,6 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy {
* Initialize entity type list * Initialize entity type list
*/ */
ngOnInit() { ngOnInit() {
this.initialized$ = observableOf(false);
this.moreThanOne$ = this.entityTypeService.hasMoreThanOneAuthorizedImport(); this.moreThanOne$ = this.entityTypeService.hasMoreThanOneAuthorizedImport();
this.singleEntity$ = this.moreThanOne$.pipe( this.singleEntity$ = this.moreThanOne$.pipe(
mergeMap((response: boolean) => { mergeMap((response: boolean) => {
@@ -98,21 +98,23 @@ export class MyDSpaceNewExternalDropdownComponent implements OnInit, OnDestroy {
currentPage: 1, currentPage: 1,
}; };
return this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe( return this.entityTypeService.getAllAuthorizedRelationshipTypeImport(findListOptions).pipe(
map((entities: RemoteData<PaginatedList<ItemType>>) => {
this.initialized$ = observableOf(true);
return entities.payload.page[0];
}),
take(1), take(1),
map((entities: RemoteData<PaginatedList<ItemType>>) => {
this.initialized$.next(true);
return entities?.payload?.page[0];
}),
); );
} else { } else {
this.initialized$ = observableOf(true); this.initialized$.next(true);
return observableOf(null); return observableOf(null);
} }
}), }),
take(1), take(1),
); );
this.subs.push( this.subs.push(
this.singleEntity$.subscribe((result) => this.singleEntity = result ), this.singleEntity$.subscribe((result) => {
this.singleEntity = result;
} ),
); );
} }