fixed an issue where sometimes the wrong resource would be returned if it was fetched as part of a list, and later queried as a single resource

This commit is contained in:
Art Lowel
2017-06-21 11:30:48 +02:00
parent 21a6a80d13
commit 0bccc7c201

View File

@@ -64,9 +64,10 @@ export class RemoteDataBuildService {
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).pageInfo) .map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).pageInfo)
.distinctUntilChanged(); .distinctUntilChanged();
//always use self link if that is cached, only if it isn't, get it via the response.
const payload = const payload =
Observable.race( Observable.combineLatest(
this.objectCache.getBySelfLink<TNormalized>(href, normalizedType), this.objectCache.getBySelfLink<TNormalized>(href, normalizedType).startWith(undefined),
responseCacheObs responseCacheObs
.filter((entry: ResponseCacheEntry) => entry.response.isSuccessful) .filter((entry: ResponseCacheEntry) => entry.response.isSuccessful)
.map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).resourceUUIDs) .map((entry: ResponseCacheEntry) => (<SuccessResponse> entry.response).resourceUUIDs)
@@ -79,7 +80,17 @@ export class RemoteDataBuildService {
} }
}) })
.distinctUntilChanged() .distinctUntilChanged()
).map((normalized: TNormalized) => { .startWith(undefined),
(fromSelfLink, fromResponse) => {
if (hasValue(fromSelfLink)) {
return fromSelfLink;
}
else {
return fromResponse;
}
}
).filter(normalized => hasValue(normalized))
.map((normalized: TNormalized) => {
return this.build<TNormalized, TDomain>(normalized); return this.build<TNormalized, TDomain>(normalized);
}); });