From 247a1868f672f9a65406f5abed684fa127d4e7e6 Mon Sep 17 00:00:00 2001 From: "Bruce B. Anderson" Date: Sun, 31 Dec 2023 08:36:16 -0500 Subject: [PATCH] 0.0.720 --- lib/setEnhProp.js | 5 +++++ lib/setEnhProp.ts | 5 +++++ trHelpers/doUpdate.js | 26 +++++++++++--------------- trHelpers/doUpdate.ts | 25 +++++++++++-------------- 4 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 lib/setEnhProp.js create mode 100644 lib/setEnhProp.ts diff --git a/lib/setEnhProp.js b/lib/setEnhProp.js new file mode 100644 index 00000000..7b4b0e55 --- /dev/null +++ b/lib/setEnhProp.js @@ -0,0 +1,5 @@ +import { setProp } from './setProp.js'; +export function setEnhProp(obj, path, val) { + path = path.replace('+', "beEnhanced.by."); + setProp(obj, path, val); +} diff --git a/lib/setEnhProp.ts b/lib/setEnhProp.ts new file mode 100644 index 00000000..94936adc --- /dev/null +++ b/lib/setEnhProp.ts @@ -0,0 +1,5 @@ +import {setProp} from './setProp.js'; +export function setEnhProp(obj: any, path: string, val: any){ + path = path.replace('+', "beEnhanced.by."); + setProp(obj, path, val); +} \ No newline at end of file diff --git a/trHelpers/doUpdate.js b/trHelpers/doUpdate.js index 6d5c695f..7afee370 100644 --- a/trHelpers/doUpdate.js +++ b/trHelpers/doUpdate.js @@ -21,21 +21,17 @@ export async function doUpdate(transformer, matchingElement, uow) { const val = await transformer.getDerivedVal(uow, d, matchingElement); if (s !== undefined) { const path = s; - if (path[0] === '.') { - const { setProp } = await import('../lib/setProp.js'); - setProp(matchingElement, path, val); - } - else { - // if(typeof val === 'object' && !Array.isArray(val)){ - // const keys = Object.keys(val); - // if(keys[0] in matchingElement){ - // Object.assign(matchingElement, val); - // }else{ - // (matchingElement)[s as string] = val; - // } - // }else{ - matchingElement[s] = val; - //} + switch (path[0]) { + case '.': + const { setProp } = await import('../lib/setProp.js'); + setProp(matchingElement, path, val); + break; + case '+': + const { setEnhProp } = await import('../lib/setEnhProp.js'); + setEnhProp(matchingElement, path, val); + break; + default: + matchingElement[s] = val; } } else if (sa !== undefined) { diff --git a/trHelpers/doUpdate.ts b/trHelpers/doUpdate.ts index 187d31dc..5f562b00 100644 --- a/trHelpers/doUpdate.ts +++ b/trHelpers/doUpdate.ts @@ -25,23 +25,20 @@ export async function doUpdate( if(s !== undefined){ const path = s as string; - if(path[0] === '.'){ - const {setProp} = await import('../lib/setProp.js'); - setProp(matchingElement, path, val); - }else{ - // if(typeof val === 'object' && !Array.isArray(val)){ - // const keys = Object.keys(val); - // if(keys[0] in matchingElement){ - // Object.assign(matchingElement, val); - // }else{ - // (matchingElement)[s as string] = val; - // } - // }else{ + switch(path[0]){ + case '.': + const {setProp} = await import('../lib/setProp.js'); + setProp(matchingElement, path, val); + break; + case '+': + const {setEnhProp} = await import('../lib/setEnhProp.js'); + setEnhProp(matchingElement, path, val); + break; + default: (matchingElement)[s as string] = val; - //} - } + }else if(sa !== undefined){ const {A} = await import('../froop/A.js'); A({[sa]: val}, matchingElement);