Skip to content

Commit

Permalink
refactor: commit btn list
Browse files Browse the repository at this point in the history
  • Loading branch information
Xmader committed Nov 10, 2020
1 parent df99718 commit a296651
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/btn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' })

Expand All @@ -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 })
Expand Down

0 comments on commit a296651

Please sign in to comment.