32 lines
1015 B
TypeScript
32 lines
1015 B
TypeScript
import * as plugins from './domtools.plugins';
|
|
import { LitElement } from 'lit-element';
|
|
|
|
export class ElementInstrumenter {
|
|
connectedElements = new plugins.lik.ObjectMap<LitElement>();
|
|
|
|
public instrumentElement(elementArg: LitElement) {
|
|
const originalConnectedCallback = elementArg.connectedCallback;
|
|
const originalDisconnectedCallback = elementArg.disconnectedCallback;
|
|
|
|
if (!elementArg.parentElement) {
|
|
elementArg.connectedCallback = () => {
|
|
this.connectedElements.add(elementArg);
|
|
originalConnectedCallback.apply(elementArg);
|
|
};
|
|
} else {
|
|
this.connectedElements.add(elementArg);
|
|
}
|
|
|
|
elementArg.disconnectedCallback = () => {
|
|
this.connectedElements.remove(elementArg);
|
|
originalDisconnectedCallback.apply(elementArg);
|
|
};
|
|
|
|
}
|
|
|
|
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {
|
|
for (const elementArg of this.connectedElements.getArray()) {
|
|
await eachFuncArg(elementArg);
|
|
}
|
|
}
|
|
} |