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

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

There is a newer version: 0.23.0
Show newest version
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
            )
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy