-
Notifications
You must be signed in to change notification settings - Fork 0
/
inject.ts
44 lines (43 loc) · 1.3 KB
/
inject.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {EventConfigs} from './types';
interface injectArgs<T extends [any, EventConfigs]> {
mold: T,
with?: T,
tbdSlots?: {
of?: EventTarget,
on?: string,
}
}
export function inject<T extends [any, EventConfigs]>({mold, with: w, tbdSlots}: injectArgs<T>): T{
const into1 = mold[1];
if(w !== undefined){
const me0 = w[0];
const into0 = mold[0];
if(into0 !== undefined) Object.assign(into0, me0);
const me1 = w[1];
if(me1 !== undefined){
for(const key in me1){
const into1val = into1[key];
if(into1val !== undefined){
Object.assign(into1val, me1[key]);
}else{
into1[key] = me1[key];
}
}
}
}
if(tbdSlots !== undefined){
const props = Object.keys(tbdSlots);
for(const val of Object.values(into1)){
for(const prop of props){
if((val as any)[prop] === 'tbd'){
(val as any)[prop] = (tbdSlots as any)[prop];
}
const abort = (val as any).abort;
if(abort?.[prop] === 'tbd'){
abort[prop] = (tbdSlots as any)[prop];
}
}
}
}
return mold;
}