diff --git a/src/app/core/data/data.service.ts b/src/app/core/data/data.service.ts index 6176694d9d..695b2e5fea 100644 --- a/src/app/core/data/data.service.ts +++ b/src/app/core/data/data.service.ts @@ -1,7 +1,7 @@ import { HttpClient } from '@angular/common/http'; import { Store } from '@ngrx/store'; import { Operation } from 'fast-json-patch'; -import { AsyncSubject, combineLatest, from as observableFrom, Observable, of as observableOf } from 'rxjs'; +import { AsyncSubject, from as observableFrom, Observable, of as observableOf } from 'rxjs'; import { distinctUntilChanged, filter, @@ -166,7 +166,7 @@ export abstract class DataService implements UpdateDa */ buildHrefWithParams(href: string, params: RequestParam[], ...linksToFollow: FollowLinkConfig[]): string { - let args = []; + let args = []; if (hasValue(params)) { params.forEach((param: RequestParam) => { args = this.addHrefArg(href, args, `${param.fieldName}=${param.fieldValue}`); @@ -181,6 +181,7 @@ export abstract class DataService implements UpdateDa return href; } } + /** * Adds the embed options to the link for the request * @param href The href the params are to be added to @@ -487,7 +488,7 @@ export abstract class DataService implements UpdateDa } createPatchFromCache(object: T): Observable { - const oldVersion$ = this.findByHref(object._links.self.href, true, false); + const oldVersion$ = this.findByHref(object._links.self.href, true, false); return oldVersion$.pipe( getFirstSucceededRemoteData(), getRemoteDataPayload(), @@ -665,9 +666,17 @@ export abstract class DataService implements UpdateDa invalidated$.complete(); }); - return combineLatest([response$, invalidated$]).pipe( - filter(([_, invalidated]) => invalidated), - map(([response, _]) => response), + return response$.pipe( + switchMap((rd: RemoteData) => { + if (rd.hasSucceeded) { + return invalidated$.pipe( + filter((invalidated: boolean) => invalidated), + map(() => rd) + ); + } else { + return [rd]; + } + }) ); }