Skip to content
EliteChart

HistoryCommand

Documentation


Documentation / @elitechart/core / HistoryCommand

Defined in: history/history-stack.ts:28

A reversible command.

redo is the forward action (first invoked when push is called with execute: true). undo reverses it. Both MUST be pure with respect to the command instance — calling redo(); undo(); repeatedly must leave the world in the same state as not calling either.

Example

code
const cmd: HistoryCommand = {
  label: 'Move drawing',
  redo: () => chart.updateDrawing(id, nextState),
  undo: () => chart.updateDrawing(id, prevState),
};
stack.push(cmd);

Properties

kind?

code
readonly optional kind?: string;

Defined in: history/history-stack.ts:32

Command kind for coalescing + filtering (optional).


label

code
readonly label: string;

Defined in: history/history-stack.ts:30

Short, user-readable label used for UI hints (e.g. menu items).

Methods

canMerge()?

code
optional canMerge(prev): boolean;

Defined in: history/history-stack.ts:40

Optional merge test. If canMerge(prev) returns true, the stack coalesces this command into prev via mergeWith and does NOT push a new entry. Useful for rapid drag steps.

Parameters

prev

HistoryCommand

Returns

boolean


mergeWith()?

code
optional mergeWith(prev): HistoryCommand;

Defined in: history/history-stack.ts:45

Optional merge. Extend prev with state from this command; return the merged command (or mutate prev in place and return it).

Parameters

prev

HistoryCommand

Returns

HistoryCommand


redo()

code
redo(): void;

Defined in: history/history-stack.ts:33

Returns

void


undo()

code
undo(): void;

Defined in: history/history-stack.ts:34

Returns

void