Skip to content

Commit

Permalink
115046: Fixed issue where relationsToItems would never emit when an e…
Browse files Browse the repository at this point in the history
…mpty array was passed to it
  • Loading branch information
alexandrevryghem committed Jun 7, 2024
1 parent 3253e0e commit 4ccd459
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { InjectionToken } from '@angular/core';
import {
combineLatest as observableCombineLatest,
Observable,
of as observableOf,
zip as observableZip,
} from 'rxjs';
import {
Expand Down Expand Up @@ -53,17 +54,19 @@ export const compareArraysUsingIds = <T extends { id: string }>() =>
/**
* Operator for turning a list of relationships into a list of the relevant items
* @param {string} thisId The item's id of which the relations belong to
* @returns {(source: Observable<Relationship[]>) => Observable<Item[]>}
*/
export const relationsToItems = (thisId: string) =>
export const relationsToItems = (thisId: string): (source: Observable<Relationship[]>) => Observable<Item[]> =>
(source: Observable<Relationship[]>): Observable<Item[]> =>
source.pipe(
mergeMap((rels: Relationship[]) =>
observableZip(
...rels.map((rel: Relationship) => observableCombineLatest(rel.leftItem, rel.rightItem)),
),
),
map((arr) =>
mergeMap((relationships: Relationship[]) => {
if (relationships.length === 0) {
return observableOf([]);
}
return observableZip(
...relationships.map((rel: Relationship) => observableCombineLatest([rel.leftItem, rel.rightItem])),
);
}),
map((arr: [RemoteData<Item>, RemoteData<Item>][]) =>
arr
.filter(([leftItem, rightItem]) => leftItem.hasSucceeded && rightItem.hasSucceeded)
.map(([leftItem, rightItem]) => {
Expand Down

0 comments on commit 4ccd459

Please sign in to comment.