Provided fallback for failing instant load

This commit is contained in:
squidfunk 2020-02-21 09:44:25 +01:00
parent 71758b41b4
commit 58175137e2
2 changed files with 20 additions and 4 deletions

View File

@ -20,9 +20,10 @@
* IN THE SOFTWARE.
*/
import { Observable } from "rxjs"
import { NEVER, Observable } from "rxjs"
import { ajax } from "rxjs/ajax"
import {
catchError,
distinctUntilChanged,
map,
pluck,
@ -32,7 +33,7 @@ import {
switchMap
} from "rxjs/operators"
import { getLocation } from "../../location"
import { getLocation, setLocation } from "../../location"
/* ----------------------------------------------------------------------------
* Helper types
@ -57,6 +58,8 @@ interface WatchOptions {
* to the same page, the request is effectively ignored (i.e. when only the
* fragment identifier changes).
*
* In case the request fails, the location change is dispatched regularly.
*
* @param options - Options
*
* @return Document switch observable
@ -77,8 +80,12 @@ export function watchDocumentSwitch(
responseType: "document",
withCredentials: true
})
.pipe<Document>(
pluck("response")
.pipe<Document, Document>(
pluck("response"),
catchError(() => {
setLocation(url)
return NEVER
})
)
),
share()

View File

@ -36,6 +36,15 @@ export function getLocation(): string {
return location.href
}
/**
* Set location
*
* @param value - New location
*/
export function setLocation(value: string): void {
location.href = value
}
/* ------------------------------------------------------------------------- */
/**