com.yandex.div.dsl.util.PropertyMap.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-json-builder Show documentation
Show all versions of kotlin-json-builder Show documentation
DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app.
package com.yandex.div.dsl.util
import com.yandex.div.dsl.ExpressionProperty
import com.yandex.div.dsl.LiteralProperty
import com.yandex.div.dsl.Property
import com.yandex.div.dsl.ReferenceProperty
import com.yandex.div.dsl.context.PropertyOverriding
import com.yandex.div.dsl.context.ReferenceResolving
import com.yandex.div.dsl.context.TemplateBinding
fun propertyMapOf(vararg properties: Pair?>): Map {
return properties.mapNotNull { (key, property) -> associateProperty(key, property) }
.toMap()
}
fun propertyMapOf(vararg bindings: TemplateBinding<*>): Map {
return bindings.mapNotNull { binding ->
when (binding) {
is PropertyOverriding -> associateProperty(binding.name, binding.property)
is ReferenceResolving -> associateProperty(binding.reference.name, binding.property)
}
}.toMap()
}
@Suppress("ConvertToStringTemplate")
private fun associateProperty(key: String, property: Property<*>?): Pair? {
return when (property) {
null -> null
is ReferenceProperty -> ("$" + key) to property.name
is LiteralProperty -> if (property.value == null) null else key to property.value
is ExpressionProperty -> key to property.expression
}
}