-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbe-functional.js
64 lines (64 loc) · 1.97 KB
/
be-functional.js
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
import { BE, propDefaults, propInfo } from 'be-enhanced/BE.js';
import { XE } from 'xtal-element/XE.js';
import { register } from 'be-hive/register.js';
export class BeFunctional extends BE {
static get beConfig() {
return {
parse: true,
primaryProp: 'fnParams',
primaryPropReq: true,
};
}
#exportsLookup = new Map();
onFnParams(self) {
const { fnParams, enhancedElement } = self;
import('be-exportable/be-exportable.js');
for (const key in fnParams) {
const param = fnParams[key];
enhancedElement.addEventListener(key, async (e) => {
const { scriptRef, fn } = param;
if (this.#exportsLookup.has(scriptRef)) {
const exports = this.#exportsLookup.get(scriptRef);
const fun = exports[fn];
fun.bind(self)(e);
return;
}
const rn = enhancedElement.getRootNode();
const scriptEl = rn.getElementById(scriptRef);
if (scriptEl === null)
throw '404';
const base = await scriptEl.beEnhanced.whenResolved('be-exportable');
const exports = base.exports;
this.#exportsLookup.set(scriptRef, exports);
const fun = exports[fn];
fun.bind(self)(e);
});
}
return {
resolved: true,
};
}
}
const tagName = 'be-functional';
const ifWantsToBe = 'functional';
const upgrade = '*';
const xe = new XE({
config: {
tagName,
propDefaults: {
...propDefaults,
},
propInfo: {
...propInfo,
fnParams: {
type: 'Object',
parse: false,
}
},
actions: {
onFnParams: 'fnParams'
}
},
superclass: BeFunctional
});
register(ifWantsToBe, upgrade, tagName);