-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-invoking.void
70 lines (61 loc) · 2.59 KB
/
be-invoking.void
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {config as beCnfg} from 'be-enhanced/config.js';
import {BE, BEConfig} from 'be-enhanced/BE.js';
import {IEnhancement, BEAllProps, EnhancementInfo, EMC} from 'trans-render/be/types';
import { Specifier } from 'trans-render/dss/types';
import {dispatchEvent as de} from 'trans-render/positractions/dispatchEvent.js';
import {Actions, AP, InvokingParameters, PAP} from './types';
class BeInvoking extends BE implements Actions {
de = de;
static override config: BEConfig<AP & BEAllProps, Actions & IEnhancement, any> = {
propInfo: {
...beCnfg.propInfo,
parsedStatements: {},
rawStatements: {},
},
actions: {
hydrate: {
ifAllOf: ['parsedStatements']
}
}
}
#abortControllers: AbortController[] = [];
#cache: Map<Specifier, WeakRef<Element>> = new Map();
async hydrate(self: this){
const {parsedStatements, enhancedElement} = self;
const {nudge} = await import('trans-render/lib/nudge.js');
for(const parsedStatement of parsedStatements!){
let {localEventType} = parsedStatement;
if(localEventType === undefined){
const {getLocalSignal} = await import('be-linked/defaults.js');
const ls = await getLocalSignal(enhancedElement);
localEventType = ls.type;
}
const ac = new AbortController();
this.#abortControllers.push(ac);
enhancedElement.addEventListener(localEventType, e => {
this.#invokeRemoteMethods(parsedStatement, enhancedElement, e);
}, {signal: ac.signal});
}
nudge(enhancedElement);
return {
resolved: true
} as PAP;
}
async #invokeRemoteMethods(parsedStatement: InvokingParameters, enhancedElement: Element, event: Event){
const {remoteSpecifiers} = parsedStatement;
const {find} = await import('trans-render/dss/find.js');
for(const remoteSpecifier of remoteSpecifiers){
let remoteTarget = this.#cache.get(remoteSpecifier)?.deref() as Element | undefined | null;
if(remoteTarget === undefined){
remoteTarget = await find(enhancedElement, remoteSpecifier);
if(!remoteTarget) throw 404;
this.#cache.set(remoteSpecifier, new WeakRef(remoteTarget));
}
const {prop} = remoteSpecifier;
(<any>remoteTarget)[prop!](remoteTarget, event);
}
}
}
interface BeInvoking extends AP{}
await BeInvoking.bootUp();
export {BeInvoking}