mirror of
https://github.com/localForage/localForage.git
synced 2026-02-01 15:32:04 +00:00
30 lines
784 B
JavaScript
30 lines
784 B
JavaScript
importScripts("../dist/localforage.js");
|
|
|
|
self.addEventListener('message', function(e) {
|
|
var data = e.data;
|
|
|
|
function handleError(e) {
|
|
data.value = e.message;
|
|
self.postMessage({
|
|
error: JSON.stringify(e),
|
|
body: data,
|
|
fail: true
|
|
});
|
|
}
|
|
|
|
localforage.setDriver(data.driver)
|
|
.then(function () {
|
|
data.value += ' with ' + localforage.driver();
|
|
return localforage.setItem(data.key, data);
|
|
}, handleError)
|
|
.then(function () {
|
|
return localforage.getItem(data.key);
|
|
}, handleError)
|
|
.then(function (data) {
|
|
self.postMessage({
|
|
body: data
|
|
});
|
|
}, handleError)
|
|
.catch(handleError);
|
|
}, false);
|