mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-22 08:37:24 +00:00
attribute builder now may skip nullable values
This commit is contained in:
parent
ca8f927304
commit
1f8298f626
@ -24,9 +24,10 @@ class UIKitAttributeValueBuilder {
|
|||||||
|
|
||||||
fun AttrsBuilder<*>.buildAndAddAttribute(
|
fun AttrsBuilder<*>.buildAndAddAttribute(
|
||||||
attributeName: String,
|
attributeName: String,
|
||||||
|
skipNullValues: Boolean = true,
|
||||||
block: AttributeBuilder.() -> Unit
|
block: AttributeBuilder.() -> Unit
|
||||||
) {
|
) {
|
||||||
buildAttribute(attributeName, block).let {
|
buildAttribute(attributeName, skipNullValues, block).let {
|
||||||
attr(it.first, it.second)
|
attr(it.first, it.second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,15 @@ package dev.inmo.jsuikit.utils
|
|||||||
|
|
||||||
class AttributeBuilder (
|
class AttributeBuilder (
|
||||||
val attributeName: String,
|
val attributeName: String,
|
||||||
|
val skipNullValues: Boolean = true,
|
||||||
private val parametersPreset: MutableMap<String, String?> = mutableMapOf()
|
private val parametersPreset: MutableMap<String, String?> = mutableMapOf()
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun add(k: String, v: Any? = null) = parametersPreset.set(k, v ?.toString())
|
fun add(k: String, v: Any? = null) {
|
||||||
|
if (v != null || !skipNullValues) {
|
||||||
|
parametersPreset[k] = v ?.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
infix fun String.to(value: Any?) = add(this, value)
|
infix fun String.to(value: Any?) = add(this, value)
|
||||||
operator fun String.unaryPlus() = add(this, null)
|
operator fun String.unaryPlus() = add(this, null)
|
||||||
|
|
||||||
@ -16,6 +21,7 @@ class AttributeBuilder (
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun buildAttribute(attributeName: String, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
inline fun buildAttribute(attributeName: String, skipNullValues: Boolean = true, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||||
attributeName
|
attributeName,
|
||||||
|
skipNullValues
|
||||||
).apply(block).build()
|
).apply(block).build()
|
||||||
|
Loading…
Reference in New Issue
Block a user