mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-16 15:40:02 -04:00
fix localstorage
This commit is contained in:
parent
29bbda0700
commit
80abf239b4
1 changed files with 44 additions and 44 deletions
|
@ -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;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue