From f1b35577b2da9deeaa885d9536a5dac01f34f5f8 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 30 May 2018 10:57:33 +0200 Subject: [PATCH] refactor --- .../person/person-page-fields.component.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/+item-page/simple/entity-types/person/person-page-fields.component.ts b/src/app/+item-page/simple/entity-types/person/person-page-fields.component.ts index 7e93f7a007..058ca8a7cc 100644 --- a/src/app/+item-page/simple/entity-types/person/person-page-fields.component.ts +++ b/src/app/+item-page/simple/entity-types/person/person-page-fields.component.ts @@ -27,6 +27,9 @@ const compareArraysUsing = (mapFn: (t: T) => any) => bIds.every((e) => aIds.includes(e)); }; +const compareArraysUsingIds = () => + compareArraysUsing((t: T) => hasValue(t) ? t.id : undefined); + const filterRelationsByTypeLabel = (label: string) => (source: Observable<[Relationship[], RelationshipType[]]>): Observable => source.pipe( @@ -36,7 +39,7 @@ const filterRelationsByTypeLabel = (label: string) => relTypesCurrentPage[idx].rightLabel === label) ) ), - distinctUntilChanged(compareArraysUsing((e: Relationship) => hasValue(e) ? e.id : undefined)) + distinctUntilChanged(compareArraysUsingIds()) ); const relationsToItems = (thisId: string, ids: ItemDataService) => @@ -57,7 +60,7 @@ const relationsToItems = (thisId: string, ids: ItemDataService) => arr .filter((d: RemoteData) => d.hasSucceeded) .map((d: RemoteData) => 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>) => rd.hasSucceeded), getRemoteDataPayload(), map((pl: PaginatedList) => pl.page), - distinctUntilChanged(compareArraysUsing((e: Relationship) => hasValue(e) ? e.id : undefined)) + distinctUntilChanged(compareArraysUsingIds()) ); const relTypesCurrentPage$ = relsCurrentPage$.pipe( @@ -93,7 +96,7 @@ export class PersonPageFieldsComponent implements OnInit { arr.map((d: RemoteData) => d.payload) ) ), - distinctUntilChanged(compareArraysUsing((e: RelationshipType) => hasValue(e) ? e.id : undefined)) + distinctUntilChanged(compareArraysUsingIds()) ); const resolvedRelsAndTypes$ = Observable.combineLatest(