1
0

refactored items, bundles and bitstreams, test builders

This commit is contained in:
Art Lowel
2019-12-11 17:18:08 +01:00
parent 8af72cb1d3
commit ad4e8eeb8c
58 changed files with 746 additions and 340 deletions

View File

@@ -59,10 +59,92 @@ export const getRemoteDataPayload = () =>
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
source.pipe(map((remoteData: RemoteData<T>) => remoteData.payload));
export const getPaginatedListPayload = () =>
<T>(source: Observable<PaginatedList<T>>): Observable<T[]> =>
source.pipe(map((list: PaginatedList<T>) => list.page));
export const getSucceededRemoteData = () =>
<T>(source: Observable<RemoteData<T>>): Observable<RemoteData<T>> =>
source.pipe(find((rd: RemoteData<T>) => rd.hasSucceeded));
/**
* Get the first successful remotely retrieved object
*
* You usually don't want to use this, it is a code smell.
* Work with the RemoteData object instead, that way you can
* handle loading and errors correctly.
*
* These operators were created as a first step in refactoring
* out all the instances where this is used incorrectly.
*/
export const getFirstSucceededRemoteDataPayload = () =>
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
source.pipe(
getSucceededRemoteData(),
getRemoteDataPayload()
);
/**
* Get the all successful remotely retrieved objects
*
* You usually don't want to use this, it is a code smell.
* Work with the RemoteData object instead, that way you can
* handle loading and errors correctly.
*
* These operators were created as a first step in refactoring
* out all the instances where this is used incorrectly.
*/
export const getAllSucceededRemoteDataPayload = () =>
<T>(source: Observable<RemoteData<T>>): Observable<T> =>
source.pipe(
getAllSucceededRemoteData(),
getRemoteDataPayload()
);
/**
* Get the first successful remotely retrieved paginated list
* as an array
*
* You usually don't want to use this, it is a code smell.
* Work with the RemoteData object instead, that way you can
* handle loading and errors correctly.
*
* You also don't want to ignore pagination and simply use the
* page as an array.
*
* These operators were created as a first step in refactoring
* out all the instances where this is used incorrectly.
*/
export const getFirstSucceededRemoteListPayload = () =>
<T>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
source.pipe(
getSucceededRemoteData(),
getRemoteDataPayload(),
getPaginatedListPayload()
);
/**
* Get all successful remotely retrieved paginated lists
* as arrays
*
* You usually don't want to use this, it is a code smell.
* Work with the RemoteData object instead, that way you can
* handle loading and errors correctly.
*
* You also don't want to ignore pagination and simply use the
* page as an array.
*
* These operators were created as a first step in refactoring
* out all the instances where this is used incorrectly.
*/
export const getAllSucceededRemoteListPayload = () =>
<T>(source: Observable<RemoteData<PaginatedList<T>>>): Observable<T[]> =>
source.pipe(
getAllSucceededRemoteData(),
getRemoteDataPayload(),
getPaginatedListPayload()
);
/**
* Operator that checks if a remote data object contains a page not found error
* When it does contain such an error, it will redirect the user to a page not found, without altering the current URL