fix(core): update

This commit is contained in:
Philipp Kunz 2020-11-25 14:43:23 +00:00
parent 64a3f57813
commit e077bf5b25

View File

@ -5,23 +5,20 @@ export class ElementInstrumenter {
connectedElements = new plugins.lik.ObjectMap<LitElement>(); connectedElements = new plugins.lik.ObjectMap<LitElement>();
public instrumentElement(elementArg: LitElement) { public instrumentElement(elementArg: LitElement) {
const originalConnectedCallback = elementArg.connectedCallback; const addToConnectedElementsFunc = (eventArg: CustomEvent) => {
const originalDisconnectedCallback = elementArg.disconnectedCallback; 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) { if (!elementArg.parentElement) {
elementArg.connectedCallback = () => {
this.connectedElements.add(elementArg);
originalConnectedCallback.apply(elementArg);
};
} else {
this.connectedElements.add(elementArg); this.connectedElements.add(elementArg);
} }
elementArg.disconnectedCallback = () => {
this.connectedElements.remove(elementArg);
originalDisconnectedCallback.apply(elementArg);
};
} }
public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) { public async forEachelement(eachFuncArg: (elementArg: LitElement) => Promise<void>) {