fix localstorage

This commit is contained in:
Toshit Chawda 2024-07-13 11:49:45 -07:00
parent 29bbda0700
commit 80abf239b4
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -1,13 +1,7 @@
import IDBMapSync from "@webreflection/idb-map/sync";
const store = new IDBMapSync(window.__location.host, {
prefix: "Storage",
durability: "relaxed"
});
await store.sync();
function storageProxy(scope: Storage): Storage {
const store = new IDBMapSync(window.__location.host);
return new Proxy(scope, {
get(target, prop) {
@ -20,33 +14,39 @@ function storageProxy(scope: Storage): Storage {
case "setItem":
return (key: string, value: string) => {
store.set(key, value);
store.sync();
}
case "removeItem":
return (key: string) => {
store.delete(key);
store.sync();
}
case "clear":
return () => {
store.clear();
store.sync();
}
case "key":
return (index: number) => {
store.keys()[index];
}
case "length":
return store.size;
default:
return store.get(prop);
}
},
set(target, prop, value) {
store.set(prop, value);
store.sync();
},
defineProperty(target, property, attributes) {
store.set(property as string, attributes.value);
target.setItem(property as string, attributes.value);
return true;
},