-
Notifications
You must be signed in to change notification settings - Fork 0
/
e.ts
28 lines (25 loc) · 1.1 KB
/
e.ts
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
import { EMC, EventListenerClass, EventListenerOrFn, IW } from "./ts-refs/trans-render/be/types";
export function e(emc: EMC, matchingElement: Element, ws: Array<IW>, initialPropVals: any, ac?: AbortController){
const matchingWs = [];
const {mapWSTo, primaryProp} = emc;
for(const w of ws){
if(!matchingElement.matches(w.q)) continue;
matchingWs.push(w);
const {listeners, props, primaryVal} = w;
for(const key in listeners){
let listener = listeners[key] as any;
if(listener.toString().substring(0, 5) === 'class'){
listener = new (<EventListenerClass>listener)() as any as EventListenerOrFn;
}
matchingElement.addEventListener(key, listener, {signal: ac?.signal});
}
Object.assign(initialPropVals, props);
if(primaryProp !== undefined && primaryVal !== undefined){
//TODO: check if object and use object.assign?
initialPropVals[primaryProp] = primaryVal;
}
}
if(mapWSTo !== undefined){
initialPropVals[mapWSTo] = matchingWs;
}
}