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

com.yandex.div.dsl.context.TemplateContext.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.context

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.databind.node.ObjectNode
import com.yandex.div.dsl.LiteralProperty
import com.yandex.div.dsl.Property
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.InvocationKind
import kotlin.contracts.contract

@Deprecated("Use divkit.dsl framework")
class TemplateContext {

    @JvmField
    @JsonAnyGetter
    internal val templates = mutableMapOf()

    @JvmField
    @JsonIgnore
    internal var asString: String? = null

    @JvmField
    @JsonIgnore
    internal var asNode: ObjectNode? = null

    fun copyFrom(source: TemplateContext) {
        clearCache()
        templates.putAll(source.templates)
    }

    fun  listOf(vararg items: LiteralProperty?): Property> {
        return LiteralProperty(items.mapNotNull { property -> property?.value })
    }

    internal fun clearCache() {
        asString = null
        asNode = null
    }
}

@OptIn(ExperimentalContracts::class)
@Deprecated("Use divkit.dsl framework")
fun  templates(initialize: TemplateContext.() -> Unit): TemplateContext {
    contract {
        callsInPlace(initialize, InvocationKind.EXACTLY_ONCE)
    }
    val context = TemplateContext()
    context.initialize()
    return context
}

fun > TemplateContext.define(
    templateName: String,
    templateProperty: P
) {
    clearCache()
    templates[templateName] = templateProperty.value
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy