History
import { History } from 'pixi-silk/history';
The default undo stack: steps in memory, transactions, merging and a depth limit.
const history = new History();
history.execute({ label: 'Rename', do: () => (layer.name = 'B'), undo: () => (layer.name = 'A') });
history.undo();
Implements#
Constructors#
Constructor#
new History(options?: HistoryOptions): History;
Parameters#
| Parameter | Type |
|---|---|
options | HistoryOptions |
Returns#
History
Properties#
| Property | Modifier | Type | Description | Defined in |
|---|---|---|---|---|
maxDepth | public | number | Steps kept. The oldest fall off. Change it at any time. | history.ts:84 |
state | readonly | HistoryState | canUndo, canRedo and the labels, as signals for buttons and menus. | history.ts:82 |
Accessors#
applying#
Get Signature#
get applying(): boolean;
True while undo() or redo() runs. Changes recorded meanwhile are dropped.
Returns
boolean
future#
Get Signature#
get future(): readonly HistoryStep[];
Steps that redo() can apply again, next first.
Returns
readonly HistoryStep[]
grouping#
Get Signature#
get grouping(): boolean;
True while a transaction is open.
Returns
boolean
past#
Get Signature#
get past(): readonly HistoryStep[];
Steps that undo() can revert, oldest first.
Returns
readonly HistoryStep[]
Methods#
begin()#
begin(label?: string): void;
Opens a transaction. Everything recorded until the matching end() becomes one step.
Parameters#
| Parameter | Type | Default value |
|---|---|---|
label | string | '' |
Returns#
void
Implementation of#
cancel()#
cancel(): void;
Reverts what the open transaction recorded and closes it.
Returns#
void
clear()#
clear(): void;
Forgets every step and drops an open transaction without reverting it.
Returns#
void
end()#
end(): void;
Closes a transaction. The outermost end() pushes the step (an empty one is dropped).
Returns#
void
Implementation of#
execute()#
execute(command: Command): this;
Runs command.do() and records it.
Parameters#
| Parameter | Type |
|---|---|
command | Command |
Returns#
this
onChange()#
onChange(fn: () => void): () => void;
Calls fn after every change of the stack. Returns the unsubscribe function.
Parameters#
| Parameter | Type |
|---|---|
fn | () => void |
Returns#
() => void
record()#
record(command: Command): void;
Records a change that is already applied. Clears the redo steps.
Parameters#
| Parameter | Type |
|---|---|
command | Command |
Returns#
void
Implementation of#
redo()#
redo(): boolean;
Applies the last undone step again, after one end() of an open transaction. Returns false when there is none.
Returns#
boolean
seal()#
seal(): void;
Stops the last step from taking merges: the next change starts a new step.
Returns#
void
transaction()#
transaction<R>(label: string, fn: () => R): R;
Runs fn as one step. If it throws, its changes are reverted and the error rethrown.
Type Parameters#
| Type Parameter |
|---|
R |
Parameters#
| Parameter | Type |
|---|---|
label | string |
fn | () => R |
Returns#
R
undo()#
undo(): boolean;
Reverts the last step, after one end() of an open transaction. Returns false when there is none.
Returns#
boolean