Skip to content

Commit

Permalink
0.0.852
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Nov 14, 2024
1 parent 7fd284d commit 1dd894a
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 110 deletions.
5 changes: 3 additions & 2 deletions XV/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ export async function get(usl) {
const { protocol, accessorChain, uspParts } = parsedUSL;
let ctxObj;
switch (protocol) {
// case 'globalThis':
// return await getProp(globalThis, splitPath);
case 'globalThis':
throw 'NI';
//return await getProp(globalThis, splitPath);
case 'indexedDB':
const [dbName, storeName, propName] = uspParts;
if (dbName === undefined || storeName === undefined || propName === undefined)
Expand Down
5 changes: 3 additions & 2 deletions XV/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ export async function get(usl: USL){
const {protocol, accessorChain, uspParts} = parsedUSL;
let ctxObj: any;
switch(protocol){
// case 'globalThis':
// return await getProp(globalThis, splitPath);
case 'globalThis':
throw 'NI';
//return await getProp(globalThis, splitPath);
case 'indexedDB':
const [dbName, storeName, propName] = uspParts;
if(dbName === undefined || storeName === undefined || propName === undefined) throw 400;
Expand Down
2 changes: 1 addition & 1 deletion lib/assignGingerly.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export async function assignGingerly(dest, src) {
}
else if (srcKey === '...') {
const guid = src[srcKey];
const { when } = await import('../weave.js');
const { when } = await import('./weave.js');
const values = await when(guid);
await assignGingerly(dest, values);
continue;
Expand Down
2 changes: 1 addition & 1 deletion lib/assignGingerly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function assignGingerly(dest: any, src: any){
continue;
}else if(srcKey === '...'){
const guid = src[srcKey];
const {when} = await import('../weave.js');
const {when} = await import('./weave.js');
const values = await when(guid);
await assignGingerly(dest, values);
continue;
Expand Down
8 changes: 8 additions & 0 deletions lib/textWeave.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export async function weave(textNodes, host) {
return (await Promise.all(textNodes.map(async (path, idx) => {
if (idx % 2 === 0)
return path;
const { getVal } = await import('./getVal.js');
return await getVal({ host }, path);
}))).join('');
}
7 changes: 7 additions & 0 deletions lib/textWeave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export async function weave(textNodes: string[], host: any){
return (await Promise.all(textNodes.map(async (path, idx) => {
if(idx % 2 === 0) return path;
const {getVal} = await import ('./getVal.js');
return await getVal({host}, path) as string;
}))).join('');
}
50 changes: 43 additions & 7 deletions lib/weave.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
export async function weave(textNodes, host) {
return (await Promise.all(textNodes.map(async (path, idx) => {
if (idx % 2 === 0)
return path;
const { getVal } = await import('./getVal.js');
return await getVal({ host }, path);
}))).join('');
const values = new Map();
export async function weave(schema) {
return new Weave(schema);
}
export async function when(guid) {
if (values.has(guid))
return values.get(guid);
const { waitForEvent } = await import('./waitForEvent.js');
await waitForEvent(window, guid);
return values.get(guid);
}
export class Weave {
schema;
constructor(schema) {
this.schema = schema;
}
#into;
async into(guid) {
if (values.has(guid))
return;
this.#into = guid;
const objToPipe = await this.#draw();
values.set(guid, objToPipe);
window.dispatchEvent(new Event(guid.toString()));
}
async #draw() {
return new Promise(async (resolve, reject) => {
const { draw } = await import('../XV/draw.js');
const drawn = await draw(this.schema);
if (this.#isComplete(drawn)) {
resolve(drawn);
return;
}
throw 'NI';
});
}
#isComplete(obj) {
for (const key in this.schema) {
if (obj[key] === undefined || obj[key] === null)
return false;
}
return true;
}
}
51 changes: 45 additions & 6 deletions lib/weave.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
export async function weave(textNodes: string[], host: any){
return (await Promise.all(textNodes.map(async (path, idx) => {
if(idx % 2 === 0) return path;
const {getVal} = await import ('./getVal.js');
return await getVal({host}, path) as string;
}))).join('');
import { USLMapping } from '../ts-refs/trans-render/XV/types.js';

const values: Map<string | number | symbol, any> = new Map();

export async function weave(schema: USLMapping){
return new Weave(schema);
}

export async function when(guid: string){
if(values.has(guid)) return values.get(guid);
const {waitForEvent} = await import('./waitForEvent.js');
await waitForEvent(window, guid);
return values.get(guid);
}

export class Weave {
constructor(public schema: USLMapping){}
#into: string | number | symbol | undefined;
async into(guid: string | number | symbol){
if(values.has(guid)) return;
this.#into = guid;

const objToPipe = await this.#draw();
values.set(guid, objToPipe);
window.dispatchEvent(new Event(guid.toString()));
}

async #draw() : Promise<any>{
return new Promise(async (resolve, reject) => {
const {draw} = await import('../XV/draw.js');
const drawn = await draw(this.schema);
if(this.#isComplete(drawn)){
resolve(drawn);
return;
}
throw 'NI';
});
}

#isComplete(obj: any){
for(const key in this.schema){
if(obj[key] === undefined || obj[key] === null) return false;
}
return true;
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"positractions/*",
"funions/Localizer.ts",
"asmr/*",
"weave.ts"
"lib/weave.ts"
],
"exclude":[
"node_modules/*"
Expand Down
44 changes: 0 additions & 44 deletions weave.js

This file was deleted.

46 changes: 0 additions & 46 deletions weave.ts

This file was deleted.

0 comments on commit 1dd894a

Please sign in to comment.