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

divkit.dsl.core.Supplements.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 divkit.dsl.core

import divkit.dsl.scope.DivScope

/**
 * Provides supplement by specified key.
 * Uses factory to create instance
 * if supplement is missing in [DivScope].
 */
fun  DivScope.supplement(
    key: SupplementKey,
    factory: () -> T
): T = supplements.getOrPut(key, factory) as T

/**
 * Each instances of this class should be unique
 * key for supplement in [DivScope]. So the class
 * should be final with default [equals]/[hashCode].
 */
class SupplementKey(private val key: String) {
    override fun toString(): String {
        return "SupplementKey(\"$key\")"
    }
}

/**
 * Interface of Supplement for [DivScope].
 * Can be used to collect supplementary data
 * while layout build process.
 */
fun interface Supplement {

    /**
     * Extends current [Supplement] by another one.
     */
    fun extend(extension: Supplement): Supplement
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy