import * as plugins from './domtools.plugins'; import { LitElement } from 'lit-element'; export class ElementInstrumenter { connectedElements = new plugins.lik.ObjectMap(); public instrumentElement(elementArg: LitElement) { const addToConnectedElementsFunc = (eventArg: CustomEvent) => { this.connectedElements.add(elementArg); }; const removeFromConnectedElementsFunc = eventArg => { this.connectedElements.remove(elementArg); elementArg.removeEventListener('domtools-connected', addToConnectedElementsFunc); elementArg.removeEventListener('domtools-disconnected', removeFromConnectedElementsFunc); }; elementArg.addEventListener('domtools-connected', addToConnectedElementsFunc); elementArg.addEventListener('domtools-disconnected', removeFromConnectedElementsFunc); if (!elementArg.parentElement) { this.connectedElements.add(elementArg); } } public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise) { for (const elementArg of this.connectedElements.getArray()) { await eachFuncArg(elementArg); } } }