forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebworker-client.js
40 lines (38 loc) · 1.09 KB
/
webworker-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
39
40
/*globals importScripts:true, self:true */
importScripts('/dist/localforage.js');
self.addEventListener(
'message',
function(e) {
function handleError(e) {
self.postMessage({
error: JSON.stringify(e),
body: e,
fail: true
});
}
localforage.setDriver(
e.data.driver,
function() {
localforage
.setItem(
'web worker',
e.data.value,
function() {
localforage.getItem('web worker', function(
err,
value
) {
self.postMessage({
body: value
});
});
},
handleError
)
.catch(handleError);
},
handleError
);
},
false
);