forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceworker-client.js
38 lines (36 loc) · 1.07 KB
/
serviceworker-client.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
/*globals importScripts:true, self:true */
importScripts('/dist/localforage.js');
self.onmessage = function(messageEvent) {
return localforage
.setDriver(messageEvent.data.driver)
.then(function() {
return localforage.setItem(
'service worker',
messageEvent.data.value
);
})
.then(function() {
return localforage.getItem('service worker');
})
.then(function(value) {
messageEvent.ports[0].postMessage({
body: value + ' using ' + localforage.driver()
});
})
.catch(function(error) {
messageEvent.ports[0].postMessage({
error: JSON.stringify(error),
body: error,
fail: true
});
});
};
self.oninstall = function(event) {
event.waitUntil(
localforage
.setItem('service worker registration', 'serviceworker present')
.then(function(value) {
console.log(value);
})
);
};