diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-01-20 13:13:20 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-01-20 13:13:20 +0100 |
commit | dfbd27b66a8ad7f3db527480037f21ba2d7b7292 (patch) | |
tree | c7174406f42479c38df60f220e4ec07f7301fdcc /src/main/kotlin/pl | |
parent | 73ab234bad21da33c06020195870cb046b702239 (diff) | |
download | kvision-dfbd27b66a8ad7f3db527480037f21ba2d7b7292.tar.gz kvision-dfbd27b66a8ad7f3db527480037f21ba2d7b7292.tar.bz2 kvision-dfbd27b66a8ad7f3db527480037f21ba2d7b7292.zip |
Better support for applications with multiple roots.
Diffstat (limited to 'src/main/kotlin/pl')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/panel/Root.kt | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt index 8847a3c6..b1bb36a8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt @@ -31,6 +31,7 @@ import pl.treksoft.kvision.core.Style import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.utils.snClasses import pl.treksoft.kvision.utils.snOpt +import kotlin.browser.document /** * Root container. @@ -44,7 +45,7 @@ class Root : SimplePanel { private val fixed: Boolean private val contextMenus: MutableList<Widget> = mutableListOf() - private var rootVnode: VNode = renderVNode() + private var rootVnode: VNode? = null internal var renderDisabled = false @@ -59,7 +60,9 @@ class Root : SimplePanel { */ constructor(id: String, fixed: Boolean = false, init: (Root.() -> Unit)? = null) : super() { this.fixed = fixed - rootVnode = KVManager.patch(id, this.renderVNode()) + if (document.getElementById(id) != null) { + rootVnode = KVManager.patch(id, this.renderVNode()) + } this.id = id @Suppress("LeakingThis") init?.invoke(this) @@ -140,15 +143,17 @@ class Root : SimplePanel { } internal fun reRender(): Root { - if (!renderDisabled) { - rootVnode = KVManager.patch(rootVnode, renderVNode()) + if (!renderDisabled && rootVnode != null) { + rootVnode = KVManager.patch(rootVnode!!, renderVNode()) } return this } internal fun restart() { - rootVnode = KVManager.patch(rootVnode, h("div")) - rootVnode = KVManager.patch(rootVnode, renderVNode()) + if (rootVnode != null) { + rootVnode = KVManager.patch(rootVnode!!, h("div")) + rootVnode = KVManager.patch(rootVnode!!, renderVNode()) + } } override fun getRoot(): Root? { |