From 3ab257697ae794fbe244162e274115386482c405 Mon Sep 17 00:00:00 2001 From: Art Lowel Date: Wed, 4 Oct 2017 15:37:52 +0200 Subject: [PATCH] fixed an issue where the remote data state observable would only fire for the first time after the response had already returned --- .../builders/remote-data-build.service.ts | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/app/core/cache/builders/remote-data-build.service.ts b/src/app/core/cache/builders/remote-data-build.service.ts index 744ef7fb25..046250efda 100644 --- a/src/app/core/cache/builders/remote-data-build.service.ts +++ b/src/app/core/cache/builders/remote-data-build.service.ts @@ -49,12 +49,20 @@ export class RemoteDataBuildService { requestHrefObs.flatMap((requestHref) => this.responseCache.get(requestHref)).filter((entry) => hasValue(entry)) ); - const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged(); + const requestPending = requestObs + .map((entry: RequestEntry) => entry.requestPending) + .startWith(true) + .distinctUntilChanged(); - const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged(); + const responsePending = requestObs + .map((entry: RequestEntry) => entry.responsePending) + .startWith(false) + .distinctUntilChanged(); const isSuccessFul = responseCacheObs - .map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged(); + .map((entry: ResponseCacheEntry) => entry.response.isSuccessful) + .startWith(false) + .distinctUntilChanged(); const errorMessage = responseCacheObs .filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful) @@ -133,12 +141,20 @@ export class RemoteDataBuildService { const responseCacheObs = hrefObs.flatMap((href: string) => this.responseCache.get(href)) .filter((entry) => hasValue(entry)); - const requestPending = requestObs.map((entry: RequestEntry) => entry.requestPending).distinctUntilChanged(); + const requestPending = requestObs + .map((entry: RequestEntry) => entry.requestPending) + .startWith(true) + .distinctUntilChanged(); - const responsePending = requestObs.map((entry: RequestEntry) => entry.responsePending).distinctUntilChanged(); + const responsePending = requestObs + .map((entry: RequestEntry) => entry.responsePending) + .startWith(false) + .distinctUntilChanged(); const isSuccessFul = responseCacheObs - .map((entry: ResponseCacheEntry) => entry.response.isSuccessful).distinctUntilChanged(); + .map((entry: ResponseCacheEntry) => entry.response.isSuccessful) + .startWith(false) + .distinctUntilChanged(); const errorMessage = responseCacheObs .filter((entry: ResponseCacheEntry) => !entry.response.isSuccessful)