28 lines
944 B
TypeScript
28 lines
944 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;
|
|
|
|
elementArg.connectedCallback = () => {
|
|
this.connectedElements.add(elementArg);
|
|
originalConnectedCallback.apply(elementArg);
|
|
};
|
|
elementArg.disconnectedCallback = () => {
|
|
this.connectedElements.remove(elementArg);
|
|
originalDisconnectedCallback.apply(elementArg);
|
|
};
|
|
this.connectedElements.add(elementArg);
|
|
|
|
}
|
|
|
|
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {
|
|
for (const elementArg of this.connectedElements.getArray()) {
|
|
await eachFuncArg(elementArg);
|
|
}
|
|
}
|
|
} |