mirror of
https://github.com/localForage/localForage.git
synced 2026-01-18 14:31:57 +00:00
41 lines
1.1 KiB
JavaScript
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
|
|
);
|