All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yandex.div.dsl.util.PropertyMap.kt Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 30.19.0
Show newest version
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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy