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

commonMain.com.copperleaf.ballast.undo.state.stateBasedUtils.kt Maven / Gradle / Ivy

There is a newer version: 4.2.1
Show newest version
package com.copperleaf.ballast.undo.state

import com.copperleaf.ballast.BallastViewModelConfiguration
import com.copperleaf.ballast.core.FifoInputStrategy
import com.copperleaf.ballast.withViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.sample
import kotlin.time.Duration.Companion.seconds

public fun  BallastViewModelConfiguration.Builder.withStateBasedUndoController(
    bufferStates: (Flow) -> Flow = { it.sample(5.seconds) },
    historyDepth: Int = 10,
): BallastViewModelConfiguration.TypedBuilder<
        StateBasedUndoControllerContract.Inputs,
        StateBasedUndoControllerContract.Events,
        StateBasedUndoControllerContract.State> {
    return this
        .withViewModel(
            initialState = StateBasedUndoControllerContract.State(),
            inputHandler = StateBasedUndoControllerInputHandler(bufferStates, historyDepth),
            name = "UndoController",
        )
        .apply {
            this.inputStrategy = FifoInputStrategy.typed()
        }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy