kopia lustrzana https://gitlab.com/rysiekpl/libresilient
better comment explaining the need for initServiceWorker() in event handlers (ref. #31)
rodzic
fe81a2232a
commit
c37cd53a89
|
@ -760,7 +760,14 @@ self.addEventListener('activate', async event => {
|
|||
|
||||
self.addEventListener('fetch', async event => {
|
||||
return void event.respondWith(async function () {
|
||||
// initialize the SW
|
||||
// initialize the SW; this is necessary as SW can be stopped at any time
|
||||
// and restarted when an event gets triggered -- `fetch` is just such an event.
|
||||
//
|
||||
// `install` and `activate` events only handle the initial installation of the SW
|
||||
// this means that we might end up here without initServiceWorker() ever being run
|
||||
// and so in a situation where plugins have never been actually set-up!
|
||||
//
|
||||
// the good news is that the config.json should have been cached already
|
||||
await initServiceWorker()
|
||||
// if event.resultingClientId is available, we need to use this
|
||||
// otherwise event.clientId is what we want
|
||||
|
@ -833,7 +840,17 @@ self.addEventListener('fetch', async event => {
|
|||
* assumptions to be considered:
|
||||
* every message contains clientId (so that we know where to respond if/when we need to)
|
||||
*/
|
||||
self.addEventListener('message', (event) => {
|
||||
self.addEventListener('message', async (event) => {
|
||||
|
||||
// initialize the SW; this is necessary as SW can be stopped at any time
|
||||
// and restarted when an event gets triggered -- `message` is just such an event.
|
||||
//
|
||||
// `install` and `activate` events only handle the initial installation of the SW
|
||||
// this means that we might end up here without initServiceWorker() ever being run
|
||||
// and so in a situation where plugins have never been actually set-up!
|
||||
//
|
||||
// the good news is that the config.json should have been cached already
|
||||
await initServiceWorker()
|
||||
|
||||
// inform
|
||||
var msg = 'Message received!'
|
||||
|
|
Ładowanie…
Reference in New Issue