moonundo

    Generic snapshot undo/redo and transactional state history for MoonBit applications

    undo
    redo
    history
    state
    transaction
    Download zip
    Author
    Version
    0.2.2
    License
    Apache-2.0
    Last updated
    8 hours ago
    Downloads
    6

    YeeHh2004/moonundo does not have a README file

    History

    pub struct History[T] {
    // private fields
    }

    Single-user snapshot history. Supply a pure deep copy and semantic equality.

    History::begin

    fn[T] History::begin(self : History[T], label : String) -> Result[Unit, String]

    Nested transactions preview state, but only an outer commit creates history.

    History::break_group

    fn[T] History::break_group(self : History[T]) -> Unit

    End a coalescing run explicitly, e.g. blur, pointer-up or a cursor move. record(..., group="typing") coalesces only consecutive compatible edits.

    History::can_redo

    fn[T] History::can_redo(self : History[T]) -> Bool

    History::can_undo

    fn[T] History::can_undo(self : History[T]) -> Bool

    History::capacity

    fn[T] History::capacity(self : History[T]) -> Int

    History::clear

    fn[T] History::clear(self : History[T]) -> Result[Unit, String]

    Forget navigation history while retaining current state and revision id.

    History::commit

    fn[T] History::commit(self : History[T]) -> Result[Bool, String]

    Returns whether the frame changed state. Empty/net-zero commits preserve redo.

    History::export_session

    fn[T] History::export_session(self : History[T], encode : (T) -> Json) -> Result[Json, String]

    The codec owns the schema of T. Active previews cannot be persisted.

    History::forget_saved

    fn[T] History::forget_saved(self : History[T]) -> Unit

    Disassociate history from any external saved state, e.g. an untitled document.

    History::is_dirty

    fn[T] History::is_dirty(self : History[T]) -> Bool

    Dirty means revision identity differs from saved, or a preview differs. It does not prove a file was saved: call mark_saved only after successful I/O.

    History::jump_to

    fn[T] History::jump_to(self : History[T], index : Int) -> Result[Bool, String]

    Navigate by current timeline index, not by stable revision identifier.

    History::mark_saved

    fn[T] History::mark_saved(self : History[T]) -> Result[Unit, String]

    History::new

    fn[T] History::new(initial : T, copy~ : (T) -> T, equal~ : (T, T) -> Bool, limit? : Int) -> Result[History[T], String]

    Limit counts undoable revisions, not bytes. At most limit+1 committed snapshots are retained, in addition to the live copy and active transaction snapshots.

    History::record

    fn[T] History::record(self : History[T], next : T, label : String, group? : String) -> Result[Bool, String]

    Equal states are no-ops and preserve redo. Genuine edits drop the future.

    History::redo

    fn[T] History::redo(self : History[T]) -> Result[Bool, String]

    History::redo_depth

    fn[T] History::redo_depth(self : History[T]) -> Int

    History::redo_label

    fn[T] History::redo_label(self : History[T]) -> String?

    History::reset

    fn[T] History::reset(self : History[T], initial : T, label? : String) -> Result[Unit, String]

    Load a new baseline, forgetting navigation and marking this revision clean.

    History::revision_id

    fn[T] History::revision_id(self : History[T]) -> Int

    History::rollback

    fn[T] History::rollback(self : History[T]) -> Result[Bool, String]

    Cancel only the innermost frame; committed timeline and future stay intact.

    History::saved_revision_id

    fn[T] History::saved_revision_id(self : History[T]) -> Int?

    History::set_capacity

    fn[T] History::set_capacity(self : History[T], limit : Int) -> Result[Unit, String]

    Reducing capacity keeps current state, closest past first, then future.

    History::state

    fn[T] History::state(self : History[T]) -> T

    Return an isolated state, never the history-owned snapshot.

    History::timeline

    fn[T] History::timeline(self : History[T]) -> Array[RevisionInfo]

    History::transaction_depth

    fn[T] History::transaction_depth(self : History[T]) -> Int

    History::undo

    fn[T] History::undo(self : History[T]) -> Result[Bool, String]

    History::undo_depth

    fn[T] History::undo_depth(self : History[T]) -> Int

    History::undo_label

    fn[T] History::undo_label(self : History[T]) -> String?

    JsonEditor

    pub struct JsonEditor {
    // private fields
    }

    Incremental JSON adapter. Owns a history, not a growing replay script.

    JsonEditor::dispatch

    fn JsonEditor::dispatch(self : JsonEditor, text : String) -> String

    Execute one command. A rejected command leaves the history unchanged. prepare_save exports a clean candidate without marking the live state saved; the host persists it, then sends save only after successful synchronous I/O.

    JsonEditor::new

    fn JsonEditor::new(text : String) -> Result[JsonEditor, String]

    Accept {initial, limit?} or {session}; optional include_session defaults to true. Construction never executes commands.

    JsonEditor::status

    fn JsonEditor::status(self : JsonEditor) -> String

    Return isolated state and metadata, optionally including the committed session.

    RevisionInfo

    pub struct RevisionInfo {
    index : Int
    revision_id : Int
    label : String
    current : Bool
    } derive(ToJson)

    Metadata-only timeline entry; no mutable user data is exposed.

    RevisionInfo::to_json

    replay

    fn replay(text : String) -> String

    Portable JSON adapter for CLI/JS. Replays at most 2000 commands atomically. Errors produce no output session; callers keep their previous document.

    restore_session

    fn[T] restore_session(value : Json, decode : (Json) -> Result[T, String], copy~ : (T) -> T, equal~ : (T, T) -> Bool) -> Result[History[T], String]

    Restore validates metadata before constructing a new history. Edit groups close.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io