Undo/redo history stack for LiveFlow.
Stores snapshots of nodes and edges only (not viewport, selection,
or transient UI state). Elixir's immutable data structures provide
efficient structural sharing, making full snapshots cheap.
Usage
# Initialize in mount
history = LiveFlow.History.new()
# Before a mutation, save the current state
history = LiveFlow.History.push(history, flow)
flow = State.add_edge(flow, edge)
# Undo
case LiveFlow.History.undo(history, flow) do
{:ok, restored_flow, history} -> ...
:empty -> ...
end
# Redo
case LiveFlow.History.redo(history, flow) do
{:ok, restored_flow, history} -> ...
:empty -> ...
endOptions
:max_entries— Maximum history entries (default: 50)
Summary
Functions
Returns true if there are entries to redo.
Returns true if there are entries to undo.
Creates a new empty history.
Saves a snapshot of the current flow state to the undo stack.
Re-applies a previously undone state from the redo stack.
Returns the number of redo entries.
Restores the previous state from the undo stack.
Returns the number of undo entries.
Types
@type t() :: %LiveFlow.History{ max_entries: pos_integer(), redo_stack: [snapshot()], undo_stack: [snapshot()] }
Functions
Returns true if there are entries to redo.
Returns true if there are entries to undo.
Creates a new empty history.
Options
:max_entries— Maximum number of undo entries (default: 50)
@spec push(t(), LiveFlow.State.t()) :: t()
Saves a snapshot of the current flow state to the undo stack.
Clears the redo stack (a new action after undo invalidates the redo path).
Trims the undo stack to max_entries.
@spec redo(t(), LiveFlow.State.t()) :: {:ok, LiveFlow.State.t(), t()} | :empty
Re-applies a previously undone state from the redo stack.
Pushes the current state onto the undo stack before restoring.
Returns {:ok, restored_flow, updated_history} or :empty.
@spec redo_count(t()) :: non_neg_integer()
Returns the number of redo entries.
@spec undo(t(), LiveFlow.State.t()) :: {:ok, LiveFlow.State.t(), t()} | :empty
Restores the previous state from the undo stack.
Pushes the current state onto the redo stack before restoring.
Returns {:ok, restored_flow, updated_history} or :empty.
@spec undo_count(t()) :: non_neg_integer()
Returns the number of undo entries.