KStateWithHistory
Holds a value and a capped history of past values, supporting undo/redo.
Port of the useStateWithHistory and useUndoRedo React hooks.
val history = StateWithHistory("hello", capacity = 10)
history.set("world")
history.set("!")
history.back() // → "world"
history.forward() // → "!"
println(history.canUndo) // true
println(history.canRedo) // false
// Observe reactively:
history.state.collect { v -> println(v) }Content copied to clipboard
Parameters
defaultValue
Initial value pushed into history.
capacity
Maximum number of history entries retained. Default: 10.
Properties
Link copied to clipboard
Index of the current entry within historySnapshot.
Link copied to clipboard
Snapshot of the history list (oldest → newest, up to capacity entries).