weasel API - v0.8.0
    Preparing search index...

    Interface History

    Op-batched undo/redo controller returned by createHistory.

    interface History {
        allForwardOps(): Op[];
        apply(op: Op, label?: string): void;
        applyOps(ops: Op[], label: string): void;
        beginJournal(opts: BeginJournalOptions): Journal;
        canRedo(): boolean;
        canUndo(): boolean;
        clear(): void;
        currentEntryId(): number;
        entries(): { redo: HistoryEntry[]; undo: HistoryEntry[] };
        getVersion(): number;
        goto(n: number): void;
        recordEntry(ops: Op[], label: string): void;
        redo(): void;
        redoDepth(): number;
        restore(snapshot: SerializedHistory): void;
        resumeJournal(journal: Journal): void;
        serialize(): SerializedHistory;
        subscribe(listener: () => void): () => void;
        undo(): void;
        undoDepth(): number;
    }
    Index

    Methods

    • Concatenated forwardOps of every undo-stack entry, in order. Snapshot of "what changes are currently applied via this history" — useful for Journal.commit to flush to a parent, and for any caller that wants to diff against a baseline.

      Returns Op[]

    • The id that will be assigned to the next pushed entry. Stable monotonic counter; callers use it to tag a fork point (see Journal).

      Returns number

    • Snapshot of the current undo + redo stacks. undo is oldest→newest (i.e. the last element is what undo() would pop next); redo is also oldest→newest from the user's perspective (i.e. the first element is what redo() would pop next — see implementation note). Callers should treat the arrays as immutable.

      Returns { redo: HistoryEntry[]; undo: HistoryEntry[] }

    • Monotonic counter bumped on every push/undo/redo/clear/coalesce. Cheap to read; callers use it as a React dep to detect changes.

      Returns number

    • Walk the history forward/back until exactly n entries are on the undo stack (0 ≤ n ≤ entries().undo.length + entries().redo.length). Equivalent to repeated undo()/redo() calls but doesn't bother rebuilding entry snapshots between steps. No-op if already at n.

      Parameters

      • n: number

      Returns void

    • Push an entry whose ops have already been applied to the adapter. Unlike applyOps, does NOT call op.apply(). Used by Journal.commit to flush a session's net forward ops to the parent as one entry without re-mutating the scene.

      Parameters

      • ops: Op[]
      • label: string

      Returns void

    • Replace the current undo + redo stacks with the deserialized contents of snapshot. Ops are rebuilt via the rebuildOp option when provided, then the global registry; unknown names become no-op placeholders so stack ordering survives across kit-version skew. Bumps version and notifies subscribers exactly once.

      Parameters

      Returns void

    • Re-activate a suspended journal. Throws if the journal was committed or cancelled (those are terminal). Staleness checking is the caller's responsibility — consult journal.forkedAtEntryId against currentEntryId() and your own op-semantic rules to decide whether to resume or discard before calling this.

      Parameters

      Returns void

    • Snapshot the undo + redo stacks in a structured-clone-safe form. Entries whose ops aren't all kit-registered (i.e. any op missing a name) are dropped from the snapshot with a debug-level log — they can't round-trip, so we omit them rather than emit a half-restorable entry. The in-memory stacks aren't modified.

      Returns SerializedHistory

    • Subscribe to history changes. Fires after every push/undo/redo/ clear/coalesce. Returns an unsubscribe fn.

      Parameters

      • listener: () => void

      Returns () => void

    • Number of entries on the undo stack (O(1); entries().undo.length without materializing the views).

      Returns number