@@ -20,7 +20,7 @@ const isLocalhost = Boolean(
2020
2121const isHttp = Boolean ( window . location . protocol === 'http:' ) ;
2222
23- export default function register ( swUrl , sendNotification ) {
23+ export default function register ( swUrl , { onUpdate , onInstalled } ) {
2424 if ( process . env . NODE_ENV === 'production' && 'serviceWorker' in navigator ) {
2525 // The URL constructor is available in all browsers that support SW.
2626 const publicUrl = new URL ( process . env . PUBLIC_URL , window . location ) ;
@@ -34,7 +34,7 @@ export default function register(swUrl, sendNotification) {
3434 window . addEventListener ( 'load' , ( ) => {
3535 if ( ! isLocalhost && ! isHttp ) {
3636 // It's neither localhost nor http. Just register service worker
37- registerValidSW ( swUrl , sendNotification ) ;
37+ registerValidSW ( swUrl , { onUpdate , onInstalled } ) ;
3838 } else if ( isLocalhost ) {
3939 // This is running on localhost. Lets check if a service worker still exists or not.
4040 checkValidServiceWorker ( swUrl ) ;
@@ -43,7 +43,7 @@ export default function register(swUrl, sendNotification) {
4343 }
4444}
4545
46- function registerValidSW ( swUrl , sendNotification ) {
46+ function registerValidSW ( swUrl , { onUpdate , onInstalled } ) {
4747 navigator . serviceWorker
4848 . register ( swUrl )
4949 . then ( registration => {
@@ -56,21 +56,15 @@ function registerValidSW(swUrl, sendNotification) {
5656 // the fresh content will have been added to the cache.
5757 // It's the perfect time to display a "New content is
5858 // available; please refresh." message in your web app.
59- if ( sendNotification ) {
60- sendNotification (
61- 'CodeSandbox received an update, refresh to see it!' ,
62- 'notice'
63- ) ;
59+ if ( onUpdate ) {
60+ onUpdate ( ) ;
6461 }
6562 } else {
6663 // At this point, everything has been precached.
6764 // It's the perfect time to display a
6865 // "Content is cached for offline use." message.
69- if ( sendNotification ) {
70- sendNotification (
71- 'CodeSandbox has been cached, it now works offline.' ,
72- 'success'
73- ) ;
66+ if ( onInstalled ) {
67+ onInstalled ( ) ;
7468 }
7569 }
7670 } else if ( installingWorker . state === 'redundant' ) {
0 commit comments