commonMain.internal.actions.IsTouchedAction.kt Maven / Gradle / Ivy
package io.kform.internal.actions
import io.kform.AbsolutePath
import io.kform.AbsolutePathFragment
import io.kform.FormManager
import io.kform.internal.AccessIsTouched
import io.kform.internal.AccessValueStateTree
import io.kform.internal.ActionAccessType
import io.kform.internal.StateImpl
/** Action that returns whether at least one value matching [path] has been touched. */
internal class IsTouchedAction(formManager: FormManager, private val path: AbsolutePath) :
ValueStateAction(formManager) {
override fun toString() = "IsTouched($path)"
override val accesses =
listOf(AccessValueStateTree(ActionAccessType.Read), AccessIsTouched(ActionAccessType.Read))
override val accessedPaths = listOf(path + AbsolutePathFragment.RecursiveWildcard)
override suspend fun run(): Boolean =
stateInfo(path).any { info -> (info.state as StateImpl).isTouched }
}