commonMain.symphony.AbstractSelectorBasedActionsBuilder.kt Maven / Gradle / Ivy
@file:Suppress("NOTHING_TO_INLINE")
package symphony
import kevlar.Action0
import kevlar.builders.Actions0Builder
import kollections.List
import kollections.mutableListOf
import kollections.mutableSetOf
import kollections.Collection
import kollections.MutableList
import kollections.MutableSet
import kollections.add
import kollections.associateBy
import kollections.contains
import kollections.filterKeys
import kollections.forEach
import kollections.toList
import kollections.values
import symphony.selected.Selected
abstract class AbstractSelectorBasedActionsBuilder> @PublishedApi internal constructor(
primary: MutableList> = mutableListOf(),
single: MutableList> = mutableListOf(),
multi: MutableList> = mutableListOf(),
global: MutableList> = mutableListOf(),
@PublishedApi
internal val filters: MutableSet = mutableSetOf()
) {
@PublishedApi
internal val primaryActions = Actions0Builder(primary)
@PublishedApi
internal val singleActions = Actions0Builder(single)
@PublishedApi
internal val singleActionsContainer = mutableListOf.(T) -> Unit>()
@PublishedApi
internal val multiActionsBuilder = Actions0Builder(multi)
@PublishedApi
internal val multiActionsContainer = mutableListOf.(List) -> Unit>()
@PublishedApi
internal val globalActions = Actions0Builder(global)
inline fun primary(builder: Actions0Builder.() -> Unit) {
primaryActions.apply(builder)
}
inline fun single(noinline builder: Actions0Builder.(T) -> Unit) {
singleActionsContainer.add(builder)
}
inline fun multi(noinline builder: Actions0Builder.(List) -> Unit) {
multiActionsContainer.add(builder)
}
protected inline fun Collection>.applyFilters() = associateBy {
it.key
}.filterKeys {
!filters.contains(it.lowercase())
}.values.toList()
fun buildPrimaryActions() = primaryActions.actions.applyFilters()
fun buildSingleSelectActions(selected: T) = singleActions.apply {
singleActionsContainer.forEach { builder -> builder(selected) }
}.actions.applyFilters()
fun buildMultiSelectActions(selected: List) = multiActionsBuilder.apply {
multiActionsContainer.forEach { builder -> builder(selected) }
}.actions.applyFilters()
abstract fun buildActions(selected: S): List>
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy