59695: Refactored getFirstItemFor

This commit is contained in:
Kristof De Langhe
2019-02-13 10:41:52 +01:00
parent 40342af029
commit 394a327611
4 changed files with 17 additions and 7 deletions

View File

@@ -88,3 +88,12 @@ export const getBrowseDefinitionLinks = (definitionID: string) =>
}
})
);
/**
* Get the first occurrence of an object within a paginated list
*/
export const getFirstOccurrence = () =>
<T extends DSpaceObject>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<RemoteData<T>> =>
source.pipe(
map((rd) => Object.assign(rd, { payload: rd.payload.page.length > 0 ? rd.payload.page[0] : undefined }))
);