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

View File

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