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 2803d0d commit 7fd284d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
16 changes: 12 additions & 4 deletions lib/assignGingerly.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function assignGingerly(dest, src) {
export async function assignGingerly(dest, src) {
if (!src || typeof src !== 'object')
return;
const chainOps = {};
Expand All @@ -9,23 +9,31 @@ export function assignGingerly(dest, src) {
doChains = true;
chainOps[srcKey] = src[srcKey];
delete srcCopy[srcKey];
continue;
}
else if (srcKey === '...') {
const guid = src[srcKey];
const { when } = await import('../weave.js');
const values = await when(guid);
await assignGingerly(dest, values);
continue;
}
//if target prop exists and isn't an instance of a class, but the src prop is of type EventType
//merge what is there first...
//if target prop is of type EventType and src prop isn't an instance of a class, merge it in.
const destProp = dest[srcKey];
const srcProp = srcCopy[srcKey];
if (destProp instanceof Object && destProp.constructor === Object && srcProp instanceof EventTarget) {
assignGingerly(srcProp, destProp);
await assignGingerly(srcProp, destProp);
}
else if (destProp instanceof EventTarget && srcProp instanceof Object && srcProp.constructor === Object) {
assignGingerly(destProp, srcProp);
await assignGingerly(destProp, srcProp);
continue;
}
dest[srcKey] = srcProp;
}
//Object.assign(dest, srcCopy);
applyChains(dest, chainOps);
await applyChains(dest, chainOps);
}
async function applyChains(dest, chainOps) {
// const {setProp} = await import('./setProp.js');
Expand Down
15 changes: 11 additions & 4 deletions lib/assignGingerly.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function assignGingerly(dest: any, src: any){
export async function assignGingerly(dest: any, src: any){
if(!src || typeof src !== 'object') return;
const chainOps: any = {};
const srcCopy = {...src};
Expand All @@ -8,22 +8,29 @@ export function assignGingerly(dest: any, src: any){
doChains = true;
chainOps[srcKey] = src[srcKey];
delete srcCopy[srcKey];
continue;
}else if(srcKey === '...'){
const guid = src[srcKey];
const {when} = await import('../weave.js');
const values = await when(guid);
await assignGingerly(dest, values);
continue;
}
//if target prop exists and isn't an instance of a class, but the src prop is of type EventType
//merge what is there first...
//if target prop is of type EventType and src prop isn't an instance of a class, merge it in.
const destProp = dest[srcKey];
const srcProp = srcCopy[srcKey];
if(destProp instanceof Object && destProp.constructor === Object && srcProp instanceof EventTarget){
assignGingerly(srcProp, destProp);
await assignGingerly(srcProp, destProp);
}else if(destProp instanceof EventTarget && srcProp instanceof Object && srcProp.constructor === Object){
assignGingerly(destProp, srcProp);
await assignGingerly(destProp, srcProp);
continue;
}
dest[srcKey] = srcProp;
}
//Object.assign(dest, srcCopy);
applyChains(dest, chainOps);
await applyChains(dest, chainOps);
}

async function applyChains(dest: any, chainOps: any){
Expand Down

0 comments on commit 7fd284d

Please sign in to comment.