diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-11-15 09:07:05 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-11-15 09:07:05 +0100 |
commit | 77bf290155cbfa6d389c4937bf2a5a34dd5b33bd (patch) | |
tree | e558ab18360da4d1685dc204ae661c4357842e41 | |
parent | 822ee9a8d0efd5bcacacd7dc5c1c35b549ed9c34 (diff) | |
download | kvision-77bf290155cbfa6d389c4937bf2a5a34dd5b33bd.tar.gz kvision-77bf290155cbfa6d389c4937bf2a5a34dd5b33bd.tar.bz2 kvision-77bf290155cbfa6d389c4937bf2a5a34dd5b33bd.zip |
Fix an issue with high CPU utilization in IntelliJ by introducing new onEvent extension function and changing the names of some style methods
18 files changed, 44 insertions, 31 deletions
diff --git a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt index 3170e462..fdf9f95a 100644 --- a/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt +++ b/kvision-modules/kvision-bootstrap-datetime/src/main/kotlin/pl/treksoft/kvision/form/time/DateTime.kt @@ -222,7 +222,9 @@ open class DateTime( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt index 4d90d18b..0c1df008 100644 --- a/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt +++ b/kvision-modules/kvision-bootstrap-select-remote/src/main/kotlin/pl/treksoft/kvision/form/select/SelectRemote.kt @@ -192,7 +192,9 @@ open class SelectRemote<T : Any>( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt index 8373dee7..af9e8c86 100644 --- a/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt +++ b/kvision-modules/kvision-bootstrap-select/src/main/kotlin/pl/treksoft/kvision/form/select/Select.kt @@ -209,7 +209,9 @@ open class Select( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt index ac0e9836..b841b16c 100644 --- a/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt +++ b/kvision-modules/kvision-bootstrap-spinner/src/main/kotlin/pl/treksoft/kvision/form/spinner/Spinner.kt @@ -206,7 +206,9 @@ open class Spinner( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt index 67c660ea..20d836f0 100644 --- a/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt +++ b/kvision-modules/kvision-bootstrap-upload/src/main/kotlin/pl/treksoft/kvision/form/upload/Upload.kt @@ -233,7 +233,9 @@ open class Upload( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt index 4c5b222e..852820af 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt @@ -77,13 +77,13 @@ open class Alert( init { body.add(contentTag) val okButton = Button("OK", "fas fa-check", ButtonStyle.PRIMARY) - okButton.setEventListener { + okButton.setEventListener<Button> { click = { hide() } } this.addButton(okButton) - this.setEventListener { + this.setEventListener<Button> { keydown = { e -> if (e.keyCode == ENTER_KEY) { hide() diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt index 058ca7bc..c464ea11 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt @@ -114,20 +114,20 @@ open class Confirm( init { body.add(contentTag) - cancelButton.setEventListener { + cancelButton.setEventListener<Button> { click = { hide() } } this.addButton(cancelButton) - noButton.setEventListener { + noButton.setEventListener<Button> { click = { hide() noCallback?.invoke() } } this.addButton(noButton) - yesButton.setEventListener { + yesButton.setEventListener<Button> { click = { hide() yesCallback?.invoke() diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt index b064e30c..63035e76 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt @@ -120,7 +120,7 @@ open class Modal( dialog.role = "document" dialog.add(content) closeIcon.visible = closeButton - closeIcon.setEventListener { + closeIcon.setEventListener<CloseIcon> { click = { hide() } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt index de8d60e8..d75d10df 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt @@ -175,7 +175,7 @@ open class TabPanel( } } } - setEventListener { + setEventListener<Tag> { click = { e -> activeIndex = this@TabPanel.content.getChildren().indexOf(childrenMap[currentIndex]) e.preventDefault() diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt index 861127fa..b34de18d 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/window/Window.kt @@ -189,7 +189,7 @@ open class Window( captionTag.add(windowIcon) header.add(iconsContainer) minimizeIcon.visible = minimizeButton - minimizeIcon.setEventListener { + minimizeIcon.setEventListener<MinimizeIcon> { click = { _ -> @Suppress("UnsafeCastFromDynamic") if (this@Window.dispatchEvent("minimizeWindow", obj {}) != false) { @@ -202,7 +202,7 @@ open class Window( } iconsContainer.add(minimizeIcon) maximizeIcon.visible = maximizeButton - maximizeIcon.setEventListener { + maximizeIcon.setEventListener<MaximizeIcon> { click = { _ -> @Suppress("UnsafeCastFromDynamic") if (this@Window.dispatchEvent("maximizeWindow", obj {}) != false) { @@ -215,7 +215,7 @@ open class Window( } iconsContainer.add(maximizeIcon) closeIcon.visible = closeButton - closeIcon.setEventListener { + closeIcon.setEventListener<CloseIcon> { click = { _ -> @Suppress("UnsafeCastFromDynamic") if (this@Window.dispatchEvent("closeWindow", obj {}) != false) { diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt b/src/main/kotlin/pl/treksoft/kvision/core/Component.kt index fe5569d4..e718dd7e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Component.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Component.kt @@ -52,7 +52,7 @@ interface Component { * @param css CSS style object * @return current component */ - fun addCssClass(css: Style): Component + fun addCssStyle(css: Style): Component /** * Removes given value from the set of CSS classes generated in html code of current component. @@ -66,7 +66,7 @@ interface Component { * @param css CSS style object * @return current component */ - fun removeCssClass(css: Style): Component + fun removeCssStyle(css: Style): Component /** * Adds given value to the set of CSS classes generated in html code of parent component. @@ -80,7 +80,7 @@ interface Component { * @param css CSS style object * @return current component */ - fun addSurroundingCssClass(css: Style): Component + fun addSurroundingCssStyle(css: Style): Component /** * Removes given value from the set of CSS classes generated in html code of parent component. @@ -94,7 +94,7 @@ interface Component { * @param css CSS style object * @return current component */ - fun removeSurroundingCssClass(css: Style): Component + fun removeSurroundingCssStyle(css: Style): Component /** * Returns the value of an additional attribute. diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt index 7c650e6c..4a68bff1 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Style.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Style.kt @@ -106,7 +106,7 @@ open class Style(className: String? = null, parentStyle: Style? = null, init: (S */ fun Widget.style(className: String? = null, init: (Style.() -> Unit)? = null): Style { val style = Style(className, null, init) - this.addCssClass(style) + this.addCssStyle(style) return style } diff --git a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt index ad1bd626..6b98664f 100644 --- a/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt +++ b/src/main/kotlin/pl/treksoft/kvision/core/Widget.kt @@ -358,16 +358,6 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component } /** - * @suppress - * Internal function - */ - protected fun setInternalEventListener(block: SnOn<Widget>.() -> Unit): Widget { - internalListeners.add(block) - refresh() - return this - } - - /** * Sets an event listener for current widget, keeping the actual type of component. * @param T widget type * @param block event handler @@ -403,6 +393,7 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component * } * } */ + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) open fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { listeners.add(block) refresh() @@ -568,19 +559,19 @@ open class Widget(classes: Set<String> = setOf()) : StyledComponent(), Component return this } - override fun addCssClass(css: Style): Widget { + override fun addCssStyle(css: Style): Widget { return addCssClass(css.className) } - override fun removeCssClass(css: Style): Widget { + override fun removeCssStyle(css: Style): Widget { return removeCssClass(css.className) } - override fun addSurroundingCssClass(css: Style): Widget { + override fun addSurroundingCssStyle(css: Style): Widget { return addSurroundingCssClass(css.className) } - override fun removeSurroundingCssClass(css: Style): Widget { + override fun removeSurroundingCssStyle(css: Style): Widget { return removeSurroundingCssClass(css.className) } @@ -827,3 +818,7 @@ fun Container.widget(classes: Set<String> = setOf(), init: (Widget.() -> Unit)? this.add(widget) return widget } + +inline fun <reified T : Widget> T.onEvent(noinline block: SnOn<T>.() -> Unit): Widget { + return this.setEventListener(block) +} diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt index 4fa30d7b..8575b09e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt @@ -128,7 +128,9 @@ open class CheckBox( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt index d2c58c87..bef7f078 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt @@ -138,7 +138,9 @@ open class Radio( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt index 1bcef061..5b262cef 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt @@ -142,7 +142,9 @@ open class SimpleSelect( return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt index 091278fc..250d142e 100644 --- a/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt +++ b/src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt @@ -139,7 +139,9 @@ abstract class AbstractText(label: String? = null, rich: Boolean = false) : return this } + @Deprecated("Use onEvent extension function instead.", ReplaceWith("onEvent(block)", "pl.treksoft.kvision.core.onEvent")) override fun setEventListener(block: SnOn<Widget>.() -> Unit): Widget { + @Suppress("DEPRECATION") input.setEventListener(block) return this } diff --git a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt index 6b9be23d..59f5f8e0 100644 --- a/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt +++ b/src/test/kotlin/test/pl/treksoft/kvision/core/WidgetSpec.kt @@ -95,7 +95,7 @@ class WidgetSpec : WSpec { @Test fun setEventListener() { runW { widget, _ -> - widget.setEventListener { click = { } } + widget.setEventListener<Widget> { click = { } } assertTrue("Element should have an event listener") { widget.listeners.size == 1 } } } @@ -103,7 +103,7 @@ class WidgetSpec : WSpec { @Test fun removeEventListener() { runW { widget, _ -> - widget.setEventListener { click = { } } + widget.setEventListener<Widget> { click = { } } widget.removeEventListeners() assertTrue("Element should not have any event listener") { widget.listeners.size == 0 } } |