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

commonMain.internal.actions.InfoAction.kt Maven / Gradle / Ivy

There is a newer version: 0.23.0
Show newest version
package io.kform.internal.actions

import io.kform.*
import io.kform.internal.*
import kotlinx.coroutines.flow.map

/**
 * Action that calls [infoHandler] with all info of values at [path] and holds a lock over said info
 * until [infoHandler] finishes.
 */
internal class InfoAction(
    formManager: FormManager,
    path: AbsolutePath,
    val infoHandler: InfoHandler
) : ReadValueStateAction(formManager, path) {
    override fun toString() = "Info($path)"

    override val accesses =
        listOf(
            AccessValueStateTree(ActionAccessType.Read),
            AccessIsDirty(ActionAccessType.Read),
            AccessIsTouched(ActionAccessType.Read),
            AccessValidationState(ActionAccessType.Read),
            AccessDescendantsDisplayingIssues(ActionAccessType.Read)
        )

    override suspend fun run() =
        infoHandler(
            valueStateInfo(path).map {
                val state = it.state as StateImpl

                @Suppress("UNCHECKED_CAST")
                Info(
                    it.value,
                    it.schema as Schema,
                    it.path,
                    it.schemaPath,
                    state.isDirty,
                    state.isTouched,
                    state.getAllVisibleIssues(),
                    state.validationStatus,
                    state.displayStatus()
                )
            }
        )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy