-
Notifications
You must be signed in to change notification settings - Fork 0
/
service-worker.js
41 lines (31 loc) · 892 Bytes
/
service-worker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* globals self */
const VERSION = 'v1.0.0';
const WORKER = '👷';
// const KEY = 'camelX3-v1';
// eslint-disable-next-line no-console
const log = (...args) => console.log(WORKER, VERSION, ...args);
const messages = new Map();
self.addEventListener('message', (event) => {
log('message', event);
const name = event.data;
const resolvers = messages.get(name) || [];
messages.delete(name);
for (let resolve of resolvers) {
resolve();
}
});
self.addEventListener('install', (event) => {
log('install', event);
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
log('activate', event);
return self.clients.claim();
});
self.addEventListener('sync', function(event) {
log('sync', event);
});
self.addEventListener('fetch', (event) => {
log('fetch', event.request.method, event.request.url);
event.respondWith(fetch(event.request));
});