Fix markup plugin.
This commit is contained in:
parent
d32dc3fa08
commit
c4b866f5b5
@ -13,20 +13,20 @@ import kotlin.reflect.KProperty1
|
||||
|
||||
|
||||
/**
|
||||
* Call [callBack] on initial value of the property and then on all subsequent values after change
|
||||
* Call [callback] on initial value of the property and then on all subsequent values after change
|
||||
*/
|
||||
public fun Vision.useProperty(
|
||||
propertyName: Name,
|
||||
inherit: Boolean? = null,
|
||||
includeStyles: Boolean? = null,
|
||||
scope: CoroutineScope? = manager?.context,
|
||||
callBack: (Meta) -> Unit,
|
||||
callback: (Meta) -> Unit,
|
||||
): Job {
|
||||
//Pass initial value.
|
||||
callBack(properties.getProperty(propertyName, inherit, includeStyles))
|
||||
callback(properties.getProperty(propertyName, inherit, includeStyles))
|
||||
return properties.changes.onEach { name ->
|
||||
if (name.startsWith(propertyName)) {
|
||||
callBack(properties.getProperty(propertyName, inherit, includeStyles))
|
||||
callback(properties.getProperty(propertyName, inherit, includeStyles))
|
||||
}
|
||||
}.launchIn(scope ?: error("Orphan Vision can't observe properties"))
|
||||
}
|
||||
@ -36,19 +36,19 @@ public fun Vision.useProperty(
|
||||
inherit: Boolean? = null,
|
||||
includeStyles: Boolean? = null,
|
||||
scope: CoroutineScope? = manager?.context,
|
||||
callBack: (Meta) -> Unit,
|
||||
): Job = useProperty(propertyName.parseAsName(), inherit, includeStyles, scope, callBack)
|
||||
callback: (Meta) -> Unit,
|
||||
): Job = useProperty(propertyName.parseAsName(), inherit, includeStyles, scope, callback)
|
||||
|
||||
public fun <V : Vision, T> V.useProperty(
|
||||
property: KProperty1<V, T>,
|
||||
scope: CoroutineScope? = manager?.context,
|
||||
callBack: V.(T) -> Unit,
|
||||
callback: V.(T) -> Unit,
|
||||
): Job {
|
||||
//Pass initial value.
|
||||
callBack(property.get(this))
|
||||
callback(property.get(this))
|
||||
return properties.changes.onEach { name ->
|
||||
if (name.startsWith(property.name.asName())) {
|
||||
callBack(property.get(this@useProperty))
|
||||
callback(property.get(this@useProperty))
|
||||
}
|
||||
}.launchIn(scope ?: error("Orphan Vision can't observe properties"))
|
||||
}
|
@ -12,6 +12,7 @@ import space.kscience.dataforge.context.PluginFactory
|
||||
import space.kscience.dataforge.context.PluginTag
|
||||
import space.kscience.dataforge.meta.Meta
|
||||
import space.kscience.dataforge.names.Name
|
||||
import space.kscience.dataforge.names.asName
|
||||
import space.kscience.visionforge.*
|
||||
import space.kscience.visionforge.markup.VisionOfMarkup.Companion.COMMONMARK_FORMAT
|
||||
import space.kscience.visionforge.markup.VisionOfMarkup.Companion.GFM_FORMAT
|
||||
@ -44,8 +45,13 @@ public actual class MarkupPlugin : VisionPlugin(), ElementVisionRenderer {
|
||||
element.append(div)
|
||||
}
|
||||
|
||||
override fun content(target: String): Map<Name, Any> = when (target) {
|
||||
ElementVisionRenderer.TYPE -> mapOf("markup".asName() to this)
|
||||
else -> super.content(target)
|
||||
}
|
||||
|
||||
public actual companion object : PluginFactory<MarkupPlugin> {
|
||||
override val tag: PluginTag = PluginTag("vision.markup", PluginTag.DATAFORGE_GROUP)
|
||||
override val tag: PluginTag = PluginTag("vision.markup.js", PluginTag.DATAFORGE_GROUP)
|
||||
|
||||
override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin()
|
||||
|
||||
|
@ -14,7 +14,7 @@ public actual class MarkupPlugin : VisionPlugin() {
|
||||
override val tag: PluginTag get() = Companion.tag
|
||||
|
||||
public actual companion object : PluginFactory<MarkupPlugin> {
|
||||
override val tag: PluginTag = PluginTag("vision.markup", PluginTag.DATAFORGE_GROUP)
|
||||
override val tag: PluginTag = PluginTag("vision.markup.jvm", PluginTag.DATAFORGE_GROUP)
|
||||
|
||||
override fun build(context: Context, meta: Meta): MarkupPlugin = MarkupPlugin()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user