commonMain.internal.actions.InvalidateValidationAction.kt Maven / Gradle / Ivy
package io.kform.internal.actions
import io.kform.AbsolutePath
import io.kform.FormManager
import io.kform.Validation
import io.kform.internal.*
/**
* Action that invalidates the validation with index [validationIndex] of the values at [path] by
* removing their cached issues and marking the values as unvalidated when necessary.
*/
internal class InvalidateValidationAction(
formManager: FormManager,
private val path: AbsolutePath,
private val validation: Validation<*>,
private val validationIndex: Int
) : ValueStateAction(formManager) {
override fun toString(): String = "InvalidateValidation($validation@$path)"
override val accesses =
listOf(
AccessValueStateTree(ActionAccessType.Read),
AccessValidationState(ActionAccessType.Write),
AccessIsTouched(ActionAccessType.Read),
AccessDescendantsDisplayingIssues(ActionAccessType.Read)
)
override val accessedPaths = listOf(path)
override fun overridesConflictingAction(action: Action<*>): Boolean =
action is InvalidateValidationAction &&
validationIndex == action.validationIndex &&
path.contains(action.path)
override suspend fun run() {
for (info in stateInfo(path)) {
val state = info.state as StateImpl? ?: continue
RemoveCachedIssuesAction.removeCachedIssues(
formManager,
info.path,
info.schema,
state,
validationIndex
)
}
}
}