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