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 6, 2024
1 parent d3faf5f commit 1cddb1c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 15 deletions.
13 changes: 7 additions & 6 deletions XV/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ export function init(whichStorage, win = window) {
}
init('localStorage');
init('sessionStorage');
export async function get(splitPath, protocol) {
const head = splitPath.shift();
if (head === undefined)
throw 400;
const sessionStr = window[protocol].getItem(head)?.trim();
export async function get(key, splitPath, protocol) {
// const head = splitPath.shift();
// if(head === undefined) throw 400;
const sessionStr = window[protocol].getItem(key)?.trim();
if (sessionStr === undefined)
return undefined;
const start = sessionStr[0];
Expand All @@ -88,6 +87,8 @@ export async function get(splitPath, protocol) {
return sessionStr;
}
}
export async function set(splitPath, protocol) {
export async function set(key, splitPath, protocol) {
const head = splitPath.shift();
if (head === undefined)
throw 400;
}
13 changes: 7 additions & 6 deletions XV/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ export function init(whichStorage: 'sessionStorage' | 'localStorage', win: Windo
init('localStorage');
init('sessionStorage');

export async function get(splitPath: Array<string>, protocol: 'sessionStorage' | 'localStorage'){
const head = splitPath.shift();
if(head === undefined) throw 400;
const sessionStr = window[protocol].getItem(head)?.trim();
export async function get(key: string, splitPath: Array<string>, protocol: 'sessionStorage' | 'localStorage'){
// const head = splitPath.shift();
// if(head === undefined) throw 400;
const sessionStr = window[protocol].getItem(key)?.trim();
if(sessionStr === undefined) return undefined;
const start = sessionStr[0];
const last = sessionStr[-1];
Expand All @@ -88,7 +88,8 @@ export async function get(splitPath: Array<string>, protocol: 'sessionStorage' |
}
}

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

if(head === undefined) throw 400;

}
3 changes: 2 additions & 1 deletion XV/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function get(usl) {
case 'localStorage':
case 'sessionStorage':
const { get } = await import('./Storage.js');
ctxObj = await get(uspParts, protocol);
const [key] = uspParts;
ctxObj = await get(key, [], protocol);
break;
default:
throw 'NI';
Expand Down
3 changes: 2 additions & 1 deletion XV/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export async function get(usl: USL){
case 'localStorage':
case 'sessionStorage':
const {get} = await import('./Storage.js');
ctxObj = await get(uspParts, protocol);
const [key] = uspParts
ctxObj = await get(key, [], protocol);
break;
default:
throw 'NI';
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';

test('Pull', async ({ page }) => {
await page.goto('./tests/XV/Get.html');
await page.goto('./tests/XV/GetIndexedDBObject.html');
// wait for 1 second
await page.waitForTimeout(1000);
const editor = page.locator('#target');
Expand Down
23 changes: 23 additions & 0 deletions tests/XV/GetSessionStorage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id=target></div>
<script type=module>
window.addEventListener('message', e => {
console.log({e});
})
import {get} from '/XV/get.js';
const test = {a: 'b'};
sessionStorage.setItem('c', JSON.stringify(test));

const test2 = get('sessionStorage://c');


</script>
</body>
</html>

0 comments on commit 1cddb1c

Please sign in to comment.