@@ -18,12 +18,12 @@ const isLocalhost = Boolean(
18
18
window . location . hostname . match ( / ^ 1 2 7 (?: \. (?: 2 5 [ 0 - 5 ] | 2 [ 0 - 4 ] [ 0 - 9 ] | [ 0 1 ] ? [ 0 - 9 ] [ 0 - 9 ] ? ) ) { 3 } $ / )
19
19
) ;
20
20
21
- type Config = {
21
+ interface IConfig {
22
22
onSuccess ?: ( registration : ServiceWorkerRegistration ) => void ;
23
23
onUpdate ?: ( registration : ServiceWorkerRegistration ) => void ;
24
- } ;
24
+ }
25
25
26
- export function register ( config ?: Config ) {
26
+ export function register ( config ?: IConfig ) {
27
27
if ( process . env . NODE_ENV === 'production' && 'serviceWorker' in navigator ) {
28
28
// The URL constructor is available in all browsers that support SW.
29
29
const publicUrl = new URL ( ( process as { env : { [ key : string ] : string } } ) . env . PUBLIC_URL , window . location . href ) ;
@@ -44,7 +44,8 @@ export function register(config?: Config) {
44
44
// Add some additional logging to localhost, pointing developers to the
45
45
// service worker/PWA documentation.
46
46
navigator . serviceWorker . ready . then ( ( ) => {
47
- console . log ( 'This web app is being served cache-first by a service ' + 'worker. To learn more, visit https://bit.ly/CRA-PWA' ) ;
47
+ /* tslint:disable-next-line no-console */
48
+ console . log ( 'This web app is being served cache-first by a service worker. To learn more, visit https://bit.ly/CRA-PWA' ) ;
48
49
} ) ;
49
50
} else {
50
51
// Is not localhost. Just register service worker
@@ -54,7 +55,7 @@ export function register(config?: Config) {
54
55
}
55
56
}
56
57
57
- function registerValidSW ( swUrl : string , config ?: Config ) {
58
+ function registerValidSW ( swUrl : string , config ?: IConfig ) {
58
59
navigator . serviceWorker
59
60
. register ( swUrl )
60
61
. then ( ( registration ) => {
@@ -69,6 +70,7 @@ function registerValidSW(swUrl: string, config?: Config) {
69
70
// At this point, the updated precached content has been fetched,
70
71
// but the previous service worker will still serve the older
71
72
// content until all client tabs are closed.
73
+ /* tslint:disable-next-line no-console */
72
74
console . log ( 'New content is available and will be used when all ' + 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' ) ;
73
75
74
76
// Execute callback
@@ -79,6 +81,7 @@ function registerValidSW(swUrl: string, config?: Config) {
79
81
// At this point, everything has been precached.
80
82
// It's the perfect time to display a
81
83
// "Content is cached for offline use." message.
84
+ /* tslint:disable-next-line no-console */
82
85
console . log ( 'Content is cached for offline use.' ) ;
83
86
84
87
// Execute callback
@@ -95,7 +98,7 @@ function registerValidSW(swUrl: string, config?: Config) {
95
98
} ) ;
96
99
}
97
100
98
- function checkValidServiceWorker ( swUrl : string , config ?: Config ) {
101
+ function checkValidServiceWorker ( swUrl : string , config ?: IConfig ) {
99
102
// Check if the service worker can be found. If it can't reload the page.
100
103
fetch ( swUrl )
101
104
. then ( ( response ) => {
@@ -114,6 +117,7 @@ function checkValidServiceWorker(swUrl: string, config?: Config) {
114
117
}
115
118
} )
116
119
. catch ( ( ) => {
120
+ /* tslint:disable-next-line no-console */
117
121
console . log ( 'No internet connection found. App is running in offline mode.' ) ;
118
122
} ) ;
119
123
}
0 commit comments