aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-11-15 09:07:05 +0100
committerRobert Jaros <rjaros@finn.pl>2019-11-15 09:07:05 +0100
commit77bf290155cbfa6d389c4937bf2a5a34dd5b33bd (patch)
treee558ab18360da4d1685dc204ae661c4357842e41 /src/main/kotlin/pl/treksoft
parent822ee9a8d0efd5bcacacd7dc5c1c35b549ed9c34 (diff)
downloadkvision-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
Diffstat (limited to 'src/main/kotlin/pl/treksoft')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Component.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Style.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/Widget.kt23
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/CheckBox.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/check/Radio.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/select/SimpleSelect.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/form/text/AbstractText.kt2
7 files changed, 22 insertions, 19 deletions
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
}