
commonMain.maryk.core.query.DefinedByReference.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-jvm Show documentation
Show all versions of core-jvm Show documentation
Maryk is a Kotlin Multiplatform library which helps you to store, query and send data in a structured way over multiple platforms. The data store stores any value with a version, so it is possible to request only the changed data or live listen for updates.
The newest version!
package maryk.core.query
import maryk.core.exceptions.ContextNotFoundException
import maryk.core.models.BaseDataModel
import maryk.core.models.IsObjectDataModel
import maryk.core.properties.definitions.IsPropertyDefinition
import maryk.core.properties.definitions.IsSerializablePropertyDefinition
import maryk.core.properties.definitions.contextual.ContextualPropertyReferenceDefinition
import maryk.core.properties.definitions.wrapper.contextual
import maryk.core.properties.references.AnyPropertyReference
import maryk.core.properties.references.IsPropertyReference
/**
* For objects containing a reference which defines the context of other properties
*/
interface DefinedByReference {
val reference: IsPropertyReference, *>
}
internal fun IsObjectDataModel.addReference(
getter: (DO) -> AnyPropertyReference?
) =
this.contextual(
index = 1u,
definition = ContextualPropertyReferenceDefinition(
contextualResolver = {
it?.dataModel as? BaseDataModel<*>?
?: throw ContextNotFoundException()
}
),
getter = getter,
capturer = { context, value ->
@Suppress("UNCHECKED_CAST")
context.reference = value as IsPropertyReference<*, IsSerializablePropertyDefinition<*, *>, *>
}
)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy