Created
December 6, 2019 23:17
-
-
Save kmaraz/239aea696d297da0a533f8576232e731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.cacheUpdates = []; | |
window.channelInitialized = false; | |
export const initializeWorker = function() { | |
if ('BroadcastChannel' in window) { | |
// Subscribe to broadcast channel from worker | |
const apiUpdates = new BroadcastChannel(BROADCAST_CHANNEL); | |
apiUpdates.addEventListener('message', (event: any) => { | |
if (window.channelInitialized) { | |
return; | |
} | |
if (event.data.type === CACHE_UPDATED) { | |
const { cacheName, updatedURL } = event.data.payload; | |
console.log('W: worker append to cache updates', cacheName, updatedURL); | |
window.cacheUpdates.push({ | |
cacheName, updatedURL | |
}); | |
} | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment