ui: tree: defer tree update when not mounted

This commit is contained in:
bordun 2020-12-09 16:29:52 +01:00
parent f29f815463
commit 97c31aca17
2 changed files with 19 additions and 3 deletions

View file

@ -21,7 +21,8 @@ class UiTree extends UiWidget {
this.mounted = false
this.list = this.container.appendChild(html`<ol style="--depth: 1"></ol`)
this.dragDummy = html`<span></span>`
this.deferredUpdateTimeout = null
this.editor = options.editor
this.expanded = {}
@ -85,6 +86,21 @@ class UiTree extends UiWidget {
updateTree(selectedWidgets) {
if (this.parent.mounted) {
this.deferredUpdateTree(selectedWidgets)
} else {
clearTimeout(this.deferredUpdateTimeout)
this.deferredUpdateTimeout = setTimeout(()=>{
this.deferredUpdateTree(selectedWidgets)
})
}
}
deferredUpdateTree(selectedWidgets) {
this.deferredUpdateTimeout = null
for (var s of this.sortables) {
s.destroy()
}