mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-11-30 05:58:45 +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(
|
||||
attributeName: String,
|
||||
skipNullValues: Boolean = true,
|
||||
block: AttributeBuilder.() -> Unit
|
||||
) {
|
||||
buildAttribute(attributeName, block).let {
|
||||
buildAttribute(attributeName, skipNullValues, block).let {
|
||||
attr(it.first, it.second)
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,15 @@ package dev.inmo.jsuikit.utils
|
||||
|
||||
class AttributeBuilder (
|
||||
val attributeName: String,
|
||||
val skipNullValues: Boolean = true,
|
||||
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)
|
||||
operator fun String.unaryPlus() = add(this, null)
|
||||
|
||||
@ -16,6 +21,7 @@ class AttributeBuilder (
|
||||
)
|
||||
}
|
||||
|
||||
inline fun buildAttribute(attributeName: String, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||
attributeName
|
||||
inline fun buildAttribute(attributeName: String, skipNullValues: Boolean = true, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||
attributeName,
|
||||
skipNullValues
|
||||
).apply(block).build()
|
||||
|
Loading…
Reference in New Issue
Block a user