refactor: add handleRegisterServiceWorker fn
This commit is contained in:
parent
44b9874fbe
commit
21f577d471
|
@ -16,8 +16,23 @@ export async function registerServiceWorker(navigator: Navigator, path: string,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof navigator !== "undefined" && "serviceWorker" in navigator) {
|
interface HandleServiceWorkerRegistration {
|
||||||
const options = getOptions()
|
getOptions: () => Options
|
||||||
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
|
normalize: (url: string, keepTrailing?: boolean) => string
|
||||||
registerServiceWorker(navigator, path, options)
|
registerServiceWorker: (navigator: Navigator, path: string, options: Options) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handleServiceWorkerRegistration({
|
||||||
|
getOptions,
|
||||||
|
normalize,
|
||||||
|
registerServiceWorker,
|
||||||
|
}: HandleServiceWorkerRegistration): void {
|
||||||
|
if (typeof navigator !== "undefined" && "serviceWorker" in navigator) {
|
||||||
|
const options = getOptions()
|
||||||
|
const path = normalize(`${options.csStaticBase}/dist/serviceWorker.js`)
|
||||||
|
registerServiceWorker(navigator, path, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Written this way so that it's easier to test
|
||||||
|
handleServiceWorkerRegistration({ getOptions, normalize, registerServiceWorker })
|
||||||
|
|
Loading…
Reference in New Issue