diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-04-24 20:13:17 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-04-24 20:13:17 +0200 |
commit | 833390a649c633892fbc0d9b6e37d6f7913cabb1 (patch) | |
tree | afe334494ef1ab5265ed53d4f48e6fe389b532ef /src/main/kotlin/pl/treksoft | |
parent | 7bc2dce08659b7cbcb3fd1865c7e3d95e8c42c52 (diff) | |
download | kvision-833390a649c633892fbc0d9b6e37d6f7913cabb1.tar.gz kvision-833390a649c633892fbc0d9b6e37d6f7913cabb1.tar.bz2 kvision-833390a649c633892fbc0d9b6e37d6f7913cabb1.zip |
Fix various problems with re-creating DOM nodes.
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
7 files changed, 25 insertions, 26 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index 7bbbcca3..3388a011 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -96,7 +96,8 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() { var eventTarget: Widget? = null - private var vnode: VNode? = null + protected var vnkey: String? by refreshOnUpdate() + protected var vnode: VNode? = null private var snAttrsCache: List<StringPair>? = null private var snClassCache: List<StringBoolPair>? = null @@ -182,6 +183,7 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() { */ private fun getSnOpt(): VNodeData { return snOpt { + if (vnkey != null) key = vnkey attrs = snAttrs(getSnAttrsInternal()) style = snStyle(getSnStyleInternal()) `class` = snClasses(getSnClassInternal()) @@ -325,15 +327,6 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() { afterInsertInternal(v) afterInsert(v) } - postpatch = { ov, v -> - vnode = v - if (ov.elm !== v.elm) { - afterInsertInternal(v) - afterInsert(v) - } else { - afterPostpatch(v) - } - } destroy = { afterDestroyInternal() afterDestroy() @@ -629,12 +622,6 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent() { } /** - * Method called after updating Snabbdom vnode. - */ - protected open fun afterPostpatch(node: VNode) { - } - - /** * Internal method called after destroying Snabbdom vnode. */ @Suppress("UnsafeCastFromDynamic") diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index a521fe95..b58860ff 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -149,6 +149,7 @@ open class DropDown( internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu")) init { + this.vnkey = "kv_dropdown_$counter" setChildrenFromElements() this.addInternal(button) this.addInternal(list) diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt index 0184c779..6973efe9 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckInput.kt @@ -51,6 +51,7 @@ abstract class CheckInput( ) : Widget(classes), FormInput { init { + this.vnkey = "kv_checkinput_${counter++}" this.setInternalEventListener<CheckInput> { click = { val v = getElementJQuery()?.prop("checked") as Boolean? @@ -129,10 +130,6 @@ abstract class CheckInput( refreshState() } - override fun afterPostpatch(node: VNode) { - refreshState() - } - private fun refreshState() { val v = getElementJQuery()?.prop("checked") as Boolean? if (this.value != v) { @@ -166,4 +163,7 @@ abstract class CheckInput( getElementJQuery()?.blur() } + companion object { + internal var counter = 0 + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt index 3a06f47b..c9ea2dba 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractTextInput.kt @@ -41,6 +41,7 @@ abstract class AbstractTextInput( ) : Widget(classes), FormInput { init { + this.vnkey = "kv_textinput_${counter++}" this.setInternalEventListener<AbstractTextInput> { input = { self.changeValue() @@ -127,10 +128,6 @@ abstract class AbstractTextInput( refreshState() } - override fun afterPostpatch(node: VNode) { - refreshState() - } - /** * @suppress * Internal function @@ -170,4 +167,8 @@ abstract class AbstractTextInput( open fun blur() { getElementJQuery()?.blur() } + + companion object { + internal var counter = 0 + } } diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt b/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt index 450042a2..476ee118 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/Canvas.kt @@ -53,6 +53,10 @@ open class Canvas( */ lateinit var context2D: CanvasRenderingContext2D + init { + this.vnkey = "kv_canvas_${counter++}" + } + override fun render(): VNode { return render("canvas") } @@ -68,11 +72,14 @@ open class Canvas( return pr } - override fun afterInsert(node: VNode) { + override fun afterInsertInternal(node: VNode) { + super.afterInsertInternal(node) context2D = (node.elm as HTMLCanvasElement).getContext("2d") as CanvasRenderingContext2D } companion object { + internal var counter = 0 + /** * DSL builder extension function. * diff --git a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt index 5f911539..5d872b08 100644 --- a/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt +++ b/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt @@ -110,6 +110,7 @@ open class Modal( private val footer = SimplePanel(setOf("modal-footer")) init { + this.vnkey = "kv_modal_${counter++}" this.hide() this.role = "dialog" this.addInternal(dialog) @@ -270,6 +271,7 @@ open class Modal( } companion object { + internal var counter = 0 internal var modals = mutableListOf<Modal>() } } diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt index d3211d7a..7b046e1a 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt @@ -123,8 +123,9 @@ internal class Splitter(private val splitPanel: SplitPanel, direction: Direction private val idc = "kv_splitter_$counter" init { - counter++ + this.vnkey = "kv_splitter_$counter" this.id = idc + counter++ } override fun afterInsert(node: VNode) { |