Skip to main content

UndoRedoStack

The UndoRedoStack object allows an app to track, undo or redo user actions. The undo action has to start from the top and move to the bottom of the stack sequentially. The redo action has to start from the bottom and move to the top of the stack sequentially. Pushing a new item to the stack may remove undone items. For example, the stack has total 5 item and 4 items have been undone. If a new item is pushed in, the 4 undone items will be removed from the stack. The stack will just have item 1 and the newly added one. The assumption is that the current state is satisfying. There is no need to track previous undone items after adding a new one.

You create a a UndoRedoStack by specifying a baseline item.

Param

Object.

Example

const undoRedoStack = new UndoRedoStack({
  item: [...stops]
});

Methods

canRedo()

canRedo(): boolean

Can redo

Returns

boolean

boolean - It returns true if can redo, otherwise false


canUndo()

canUndo(): boolean

Can undo

Returns

boolean

  • boolean. It returns true if can undo, otherwise false

push()

push(item: any): void

Pushes data item to a stack.

Parameters

Parameter Type Description
item any any. Data item

Returns

void

Example

undoRedoStack.push(stops);

redo()

redo(): any

Gets the data item that can be used to perform redo.

Returns

any

  • any. It returns data item

size()

size(): number

Gets the number of items in the stack.

Returns

number

  • number. The length of the stack

undo()

undo(): any

Gets the data item that can be used to perform undo.

Returns

any

  • any. It returns data item
Last updated August 23, 2024.