Prefer arrow functions and callbacks (#1210)

This commit is contained in:
Lipis 2020-05-20 16:21:37 +03:00 committed by GitHub
parent 33fe223b5d
commit c427aa3cce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 784 additions and 847 deletions

View file

@ -25,7 +25,7 @@ type Config = {
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
export function register(config?: Config) {
export const register = (config?: Config) => {
if (process.env.NODE_ENV === "production" && "serviceWorker" in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
@ -57,9 +57,9 @@ export function register(config?: Config) {
}
});
}
}
};
function registerValidSW(swUrl: string, config?: Config) {
const registerValidSW = (swUrl: string, config?: Config) => {
navigator.serviceWorker
.register(swUrl)
.then((registration) => {
@ -103,9 +103,9 @@ function registerValidSW(swUrl: string, config?: Config) {
.catch((error) => {
console.error("Error during service worker registration:", error);
});
}
};
function checkValidServiceWorker(swUrl: string, config?: Config) {
const checkValidServiceWorker = (swUrl: string, config?: Config) => {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { "Service-Worker": "script" },
@ -133,9 +133,9 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
// "No internet connection found. App is running in offline mode.",
// );
});
}
};
export function unregister() {
export const unregister = () => {
if ("serviceWorker" in navigator) {
navigator.serviceWorker.ready
.then((registration) => {
@ -145,4 +145,4 @@ export function unregister() {
console.error(error.message);
});
}
}
};