commonMain.internal.actions.InfoAction.kt Maven / Gradle / Ivy
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()
)
}
)
}