localForage/test/webworker-client.js
2017-12-18 08:42:12 +02:00

41 lines
1.1 KiB
JavaScript

/*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
);