Skip to content

Commit

Permalink
0.0.849
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Nov 9, 2024
1 parent ccf22ef commit c0bd36a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
24 changes: 20 additions & 4 deletions XV/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export async function get(key, protocol) {
const cachedVal = aWin[cache[protocol]][key];
if (cachedVal !== undefined)
return cachedVal;
window.addEventListener('message', (e) => {
throw 'NI';
});
}
let returnObj = window[protocol].getItem(key);
if (returnObj === null)
Expand All @@ -39,8 +42,21 @@ export async function get(key, protocol) {
}
return returnObj;
}
export async function set(key, splitPath, protocol) {
const head = splitPath.shift();
if (head === undefined)
throw 400;
export async function set(key, protocol, val) {
const aWin = window;
if (isLoaded) {
aWin[cache[protocol]][key] = val;
}
if (val === null) {
window[protocol].removeItem(key);
}
else {
if (typeof val === 'object') {
window[protocol].setItem(key, JSON.stringify(val));
}
else {
window[protocol].setItem(key, val);
}
}
window.postMessage([`$protocol://${key}`]);
}
22 changes: 18 additions & 4 deletions XV/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export async function get(key: string, protocol: 'sessionStorage' | 'localStorag
if(isLoaded){
const cachedVal = aWin[cache[protocol]][key];
if(cachedVal !== undefined) return cachedVal;
window.addEventListener('message', (e: Event) => {
throw 'NI';
});
}
let returnObj = window[protocol].getItem(key);
if(returnObj === null) return null;
Expand All @@ -43,8 +46,19 @@ export async function get(key: string, protocol: 'sessionStorage' | 'localStorag

}

export async function set(key: string, splitPath: Array<string>, protocol: 'sessionStorage' | 'localStorage'){
const head = splitPath.shift();
if(head === undefined) throw 400;

export async function set(key: string, protocol: 'sessionStorage' | 'localStorage', val: any){
const aWin = window as any;
if(isLoaded){
aWin[cache[protocol]][key] = val;
}
if(val === null){
window[protocol].removeItem(key);
}else{
if(typeof val === 'object'){
window[protocol].setItem(key, JSON.stringify(val));
}else{
window[protocol].setItem(key, val);
}
}
window.postMessage([`$protocol://${key}`]);
}
2 changes: 2 additions & 0 deletions XV/set.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export async function set(usl, val) {
case 'localStorage':
case 'sessionStorage':
const { set } = await import('./Storage.js');
const [key] = uspParts;
await set(key, protocol, val);
throw 'NI';
default:
throw 'NI';
Expand Down
2 changes: 2 additions & 0 deletions XV/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export async function set(usl: USL, val: any){
case 'localStorage':
case 'sessionStorage':
const {set} = await import('./Storage.js');
const [key] = uspParts;
await set(key, protocol, val);
throw 'NI';
default:
throw 'NI';
Expand Down

0 comments on commit c0bd36a

Please sign in to comment.