Skip to content

Commit

Permalink
0.0.24
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed Jun 29, 2024
1 parent a686461 commit 7217b32
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 112 deletions.
103 changes: 52 additions & 51 deletions be-calculating.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,32 @@ class BeCalculating extends BE {
static config = {
propInfo: {
...beCnfg.propInfo,
for: {}
for: {},
forArgs: {},
onInput: {},
defaultEventType: {},
},
actions: {
parseForAttr: {
ifAllOf: ['for']
},
regOnInput: {
ifAllOf: ['onInput']
}
}
};
parseForAttr(self) {
const { enhancedElement } = self;
console.log(enhancedElement);
return {};
const { for: f } = self;
return {
forArgs: f?.split(' ').map(s => s.trim()),
};
}
regOnInput(self) {
const { onInput } = self;
console.log({ onInput });
return {
defaultEventType: 'input',
};
}
// getDefaultForAttribute(self: this): PAP {
// const {enhancedElement} = self;
Expand Down Expand Up @@ -71,40 +85,40 @@ class BeCalculating extends BE {
};
}
#controllers;
async observe(self) {
const { args, searchBy, searchScope, recalculateOn } = self;
const defaultLink = {
localInstance: 'local',
enhancement: 'beCalculating',
downstreamPropName: 'propertyBag',
observe: {
attr: searchBy,
isFormElement: true,
names: args,
scope: searchScope,
on: recalculateOn
}
};
const { observe } = await import('be-linked/observe.js');
await observe(self, defaultLink);
const { propertyBag, calculator } = self;
this.#disconnect();
this.#controllers = [];
for (const arg of args) {
const ac = new AbortController();
propertyBag.addEventListener(arg, async (e) => {
const result = await calculator(propertyBag, e.detail);
Object.assign(self, result);
}, { signal: ac.signal });
this.#controllers.push(ac);
}
const result = await calculator(propertyBag);
Object.assign(self, result);
return {
//value: await calculator!(propertyBag!),
resolved: true,
};
}
// async observe(self: this): ProPAP {
// const {args, searchBy, searchScope, recalculateOn} = self;
// const defaultLink = {
// localInstance: 'local',
// enhancement: 'beCalculating',
// downstreamPropName: 'propertyBag',
// observe: {
// attr: searchBy,
// isFormElement: true,
// names: args,
// scope: searchScope,
// on: recalculateOn
// }
// } as Link;
// const {observe} = await import('be-linked/observe.js');
// await observe(self, defaultLink);
// const {propertyBag, calculator} = self;
// this.#disconnect();
// this.#controllers = [];
// for(const arg of args!){
// const ac = new AbortController();
// propertyBag!.addEventListener(arg, async e => {
// const result = await calculator!(propertyBag!, (e as CustomEvent).detail);
// Object.assign(self, result);
// }, {signal: ac.signal});
// this.#controllers.push(ac);
// }
// const result = await calculator!(propertyBag!);
// Object.assign(self, result);
// return {
// //value: await calculator!(propertyBag!),
// resolved: true,
// } as PAP;
// }
#disconnect() {
if (this.#controllers !== undefined) {
for (const ac of this.#controllers) {
Expand All @@ -116,19 +130,6 @@ class BeCalculating extends BE {
async detach(detachedElement) {
this.#disconnect();
}
getArgs(self) {
const { for: forString } = self;
let forS = forString;
if (!forS) {
const { forAttribute, enhancedElement } = self;
forS = enhancedElement.getAttribute(forAttribute);
}
if (!forS)
throw 404;
return {
args: forS.split(' ')
};
}
}
await BeCalculating.bootUp();
export { BeCalculating };
112 changes: 62 additions & 50 deletions be-calculating.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,31 @@ class BeCalculating extends BE<any, any, HTMLOutputElement | HTMLMetaElement> im
static override config: BEConfig<AP & BEAllProps, Actions & IEnhancement, any> = {
propInfo:{
...beCnfg.propInfo,
for:{}
for:{},
forArgs:{},
onInput: {},
defaultEventType: {},
},
actions: {
parseForAttr:{
ifAllOf: ['for']
},
regOnInput: {
ifAllOf: ['onInput']
}
}
};
parseForAttr(self: this): PAP {
const {enhancedElement} = self;
console.log(enhancedElement);
const {for: f} = self;
return {

forArgs: f?.split(' ').map(s => s.trim()),
}
}
regOnInput(self: this): PAP {
const {onInput} = self;
console.log({onInput});
return {
defaultEventType: 'input',
}
}
// getDefaultForAttribute(self: this): PAP {
Expand Down Expand Up @@ -83,40 +95,40 @@ class BeCalculating extends BE<any, any, HTMLOutputElement | HTMLMetaElement> im
}
}
#controllers : AbortController[] | undefined;
async observe(self: this): ProPAP {
const {args, searchBy, searchScope, recalculateOn} = self;
const defaultLink = {
localInstance: 'local',
enhancement: 'beCalculating',
downstreamPropName: 'propertyBag',
observe: {
attr: searchBy,
isFormElement: true,
names: args,
scope: searchScope,
on: recalculateOn
}
} as Link;
const {observe} = await import('be-linked/observe.js');
await observe(self, defaultLink);
const {propertyBag, calculator} = self;
this.#disconnect();
this.#controllers = [];
for(const arg of args!){
const ac = new AbortController();
propertyBag!.addEventListener(arg, async e => {
const result = await calculator!(propertyBag!, (e as CustomEvent).detail);
Object.assign(self, result);
}, {signal: ac.signal});
this.#controllers.push(ac);
}
const result = await calculator!(propertyBag!);
Object.assign(self, result);
return {
//value: await calculator!(propertyBag!),
resolved: true,
} as PAP;
}
// async observe(self: this): ProPAP {
// const {args, searchBy, searchScope, recalculateOn} = self;
// const defaultLink = {
// localInstance: 'local',
// enhancement: 'beCalculating',
// downstreamPropName: 'propertyBag',
// observe: {
// attr: searchBy,
// isFormElement: true,
// names: args,
// scope: searchScope,
// on: recalculateOn
// }
// } as Link;
// const {observe} = await import('be-linked/observe.js');
// await observe(self, defaultLink);
// const {propertyBag, calculator} = self;
// this.#disconnect();
// this.#controllers = [];
// for(const arg of args!){
// const ac = new AbortController();
// propertyBag!.addEventListener(arg, async e => {
// const result = await calculator!(propertyBag!, (e as CustomEvent).detail);
// Object.assign(self, result);
// }, {signal: ac.signal});
// this.#controllers.push(ac);
// }
// const result = await calculator!(propertyBag!);
// Object.assign(self, result);
// return {
// //value: await calculator!(propertyBag!),
// resolved: true,
// } as PAP;
// }


#disconnect(){
Expand All @@ -132,18 +144,18 @@ class BeCalculating extends BE<any, any, HTMLOutputElement | HTMLMetaElement> im
this.#disconnect();
}

getArgs(self: this): PAP {
const {for: forString} = self;
let forS: string | null | undefined = forString;
if(!forS){
const {forAttribute, enhancedElement} = self;
forS = enhancedElement.getAttribute(forAttribute!);
}
if(!forS) throw 404;
return {
args: forS.split(' ')
};
}
// getArgs(self: this): PAP {
// const {for: forString} = self;
// let forS: string | null | undefined = forString;
// if(!forS){
// const {forAttribute, enhancedElement} = self;
// forS = enhancedElement.getAttribute(forAttribute!);
// }
// if(!forS) throw 404;
// return {
// args: forS.split(' ')
// };
// }

// async onValue(self: this){
// const {enhancedElement, value, propertyToSet, notify} = self;
Expand Down
4 changes: 4 additions & 0 deletions behivior.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export const emc = {
{
name: 'for',
mapsTo: 'for'
},
{
name: 'oninput',
mapsTo: 'onInput'
}
],
importEnh: async () => {
Expand Down
4 changes: 4 additions & 0 deletions behivior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export const emc: EMC = {
{
name: 'for',
mapsTo: 'for'
},
{
name: 'oninput',
mapsTo: 'onInput'
}
],
importEnh: async () => {
Expand Down
27 changes: 16 additions & 11 deletions types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import {Target, Scope, ProxyPropChangeInfo} from 'trans-render/lib/types';
export interface EndUserProps extends IEnhancement<HTMLOutputElement | HTMLMetaElement>{
//forAttribute?: string,
for?: string,
args?: string[],
propertyToSet?: string,
searchBy?: string,
scriptRef?: Target,
notify?: 'scope' | 'elementProps',
searchScope?: Scope,
recalculateOn?: string,
nameOfCalculator?: string,

onInput?: string,

// propertyToSet?: string,
// searchBy?: string,
// scriptRef?: Target,
// notify?: 'scope' | 'elementProps',
// searchScope?: Scope,
// recalculateOn?: string,
// nameOfCalculator?: string,
}

export interface AllProps extends EndUserProps{
Expand All @@ -21,6 +23,8 @@ export interface AllProps extends EndUserProps{
isParsed: boolean;
attrExpr?: string | null;
scriptEl?: HTMLScriptElement;
defaultEventType?: string,
forArgs?: string[],
}

export type AP = AllProps;
Expand All @@ -33,10 +37,11 @@ export interface Actions{
//getDefaultForAttribute(self: this): PAP;
//getAttrExpr(self: this): PAP;
parseForAttr(self: this): PAP;
onAttrExpr(self: this): PAP;
regOnInput(self: this): PAP;
//onAttrExpr(self: this): PAP;
findScriptEl(self: this): ProPAP;
getArgs(self: this): PAP;
observe(self: this): ProPAP;
//getArgs(self: this): PAP;
//observe(self: this): ProPAP;
importSymbols(self: this): ProPAP;
//onValue(self: this): void;
}

0 comments on commit 7217b32

Please sign in to comment.