commonMain.com.copperleaf.ballast.undo.state.StateBasedUndoControllerEventHandler.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ballast-undo-jvm Show documentation
Show all versions of ballast-undo-jvm Show documentation
Adds undo/redo functionality to your ViewModel state.
package com.copperleaf.ballast.undo.state
import com.copperleaf.ballast.EventHandler
import com.copperleaf.ballast.EventHandlerScope
import com.copperleaf.ballast.undo.UndoScope
internal class StateBasedUndoControllerEventHandler(
private val undoScope: UndoScope
) : EventHandler<
StateBasedUndoControllerContract.Inputs,
StateBasedUndoControllerContract.Events,
StateBasedUndoControllerContract.State> {
override suspend fun EventHandlerScope<
StateBasedUndoControllerContract.Inputs,
StateBasedUndoControllerContract.Events,
StateBasedUndoControllerContract.State>.handleEvent(
event: StateBasedUndoControllerContract.Events,
) = when (event) {
is StateBasedUndoControllerContract.Events.RestoreState -> {
undoScope.restoreState(event.stateToRestore)
}
}
}