Skip to content
pixi-silk
GitHub repository
Class

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#

ParameterType
optionsHistoryOptions

Returns#

History

Properties#

PropertyModifierTypeDescriptionDefined in
maxDepthpublicnumberSteps kept. The oldest fall off. Change it at any time.history.ts:84
statereadonlyHistoryStatecanUndo, 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#

ParameterTypeDefault value
labelstring''

Returns#

void

Implementation of#

HistoryLike.begin


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#

HistoryLike.end


execute()#

execute(command: Command): this;

Runs command.do() and records it.

Parameters#

ParameterType
commandCommand

Returns#

this


onChange()#

onChange(fn: () => void): () => void;

Calls fn after every change of the stack. Returns the unsubscribe function.

Parameters#

ParameterType
fn() => void

Returns#

() => void


record()#

record(command: Command): void;

Records a change that is already applied. Clears the redo steps.

Parameters#

ParameterType
commandCommand

Returns#

void

Implementation of#

HistoryLike.record


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#

ParameterType
labelstring
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