-
Notifications
You must be signed in to change notification settings - Fork 0
/
doPG.ts
28 lines (27 loc) · 982 Bytes
/
doPG.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 {SignalContainer} from './types';
import {IEnhancement} from 'trans-render/be/types';
import 'be-propagating/be-propagating.js';
export async function doPG<TSelf extends IEnhancement = IEnhancement>(
self: TSelf,
el: Element,
signalContainer: SignalContainer,
signalProp: string,
prop: string,
abortControllers: Array<AbortController>,
evalFn: (self: TSelf, triggerSrc?: string) => void,
triggerSrc: string
){
const bePropagating = await (<any>el).beEnhanced.whenResolved('be-propagating');
const signal = await bePropagating.getSignal(prop);
signalContainer[signalProp] = new WeakRef(signal);
const ab = new AbortController();
abortControllers?.push(ab);
signal.addEventListener('value-changed', async () => {
if(self.resolved){
evalFn(self, triggerSrc);
}else{
await self.whenResolved();
evalFn(self, triggerSrc);
}
}, {signal: ab.signal});
}