From a296651c6f624f1471fc2bb420663ab860f4cce9 Mon Sep 17 00:00:00 2001 From: Xmader Date: Tue, 10 Nov 2020 13:51:48 -0500 Subject: [PATCH] refactor: commit btn list --- src/btn.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/btn.ts b/src/btn.ts index 0ef3ddf..b86797f 100644 --- a/src/btn.ts +++ b/src/btn.ts @@ -73,7 +73,7 @@ export class BtnList { return btn } - private _commit (): Element { + private _commit () { const parent = this.getTemplateBtn().parentElement as HTMLDivElement const shadow = parent.attachShadow({ mode: 'closed' }) @@ -87,20 +87,23 @@ export class BtnList { newParent.append(...this.list) shadow.append(newParent) - return parent + return { + parent, + shadowRoot: shadow, + } } /** * replace the template button with the list of new buttons */ commit (): void { - let el = this._commit() + let el: Element = this._commit().parent const observer = new MutationObserver(() => { // check if the buttons are still in document when dom updates if (!document.contains(el)) { // re-commit // performance issue? - el = this._commit() + el = this._commit().parent } }) observer.observe(document, { childList: true, subtree: true })