This commit is contained in:
Art Lowel
2018-05-30 10:57:33 +02:00
parent 82977ce5cf
commit f1b35577b2

View File

@@ -27,6 +27,9 @@ const compareArraysUsing = <T>(mapFn: (t: T) => any) =>
bIds.every((e) => aIds.includes(e)); bIds.every((e) => aIds.includes(e));
}; };
const compareArraysUsingIds = <T extends { id: string }>() =>
compareArraysUsing((t: T) => hasValue(t) ? t.id : undefined);
const filterRelationsByTypeLabel = (label: string) => const filterRelationsByTypeLabel = (label: string) =>
(source: Observable<[Relationship[], RelationshipType[]]>): Observable<Relationship[]> => (source: Observable<[Relationship[], RelationshipType[]]>): Observable<Relationship[]> =>
source.pipe( source.pipe(
@@ -36,7 +39,7 @@ const filterRelationsByTypeLabel = (label: string) =>
relTypesCurrentPage[idx].rightLabel === label) relTypesCurrentPage[idx].rightLabel === label)
) )
), ),
distinctUntilChanged(compareArraysUsing((e: Relationship) => hasValue(e) ? e.id : undefined)) distinctUntilChanged(compareArraysUsingIds())
); );
const relationsToItems = (thisId: string, ids: ItemDataService) => const relationsToItems = (thisId: string, ids: ItemDataService) =>
@@ -57,7 +60,7 @@ const relationsToItems = (thisId: string, ids: ItemDataService) =>
arr arr
.filter((d: RemoteData<Item>) => d.hasSucceeded) .filter((d: RemoteData<Item>) => d.hasSucceeded)
.map((d: RemoteData<Item>) => d.payload)), .map((d: RemoteData<Item>) => d.payload)),
distinctUntilChanged(compareArraysUsing((rdi: Item) => hasValue(rdi) ? rdi.uuid : undefined)), distinctUntilChanged(compareArraysUsingIds()),
); );
@@ -82,7 +85,7 @@ export class PersonPageFieldsComponent implements OnInit {
filter((rd: RemoteData<PaginatedList<Relationship>>) => rd.hasSucceeded), filter((rd: RemoteData<PaginatedList<Relationship>>) => rd.hasSucceeded),
getRemoteDataPayload(), getRemoteDataPayload(),
map((pl: PaginatedList<Relationship>) => pl.page), map((pl: PaginatedList<Relationship>) => pl.page),
distinctUntilChanged(compareArraysUsing((e: Relationship) => hasValue(e) ? e.id : undefined)) distinctUntilChanged(compareArraysUsingIds())
); );
const relTypesCurrentPage$ = relsCurrentPage$.pipe( const relTypesCurrentPage$ = relsCurrentPage$.pipe(
@@ -93,7 +96,7 @@ export class PersonPageFieldsComponent implements OnInit {
arr.map((d: RemoteData<RelationshipType>) => d.payload) arr.map((d: RemoteData<RelationshipType>) => d.payload)
) )
), ),
distinctUntilChanged(compareArraysUsing((e: RelationshipType) => hasValue(e) ? e.id : undefined)) distinctUntilChanged(compareArraysUsingIds())
); );
const resolvedRelsAndTypes$ = Observable.combineLatest( const resolvedRelsAndTypes$ = Observable.combineLatest(