@zhelvis/structure-ts
    Preparing search index...

    Class History<T>

    Array-like structure with undo/redo functionality. It uses limited stack based on RingBuffer.

    Type Parameters

    • T
    Index

    Constructors

    • Creates a new History instance.

      Type Parameters

      • T

      Parameters

      • capacity: number

        Maximum number of items the history can hold.

      • Optionalitems: T[]

        Initial items to populate the history. If the number of items exceeds capacity, the oldest items will be discarded.

      • currentPosition: number = -1

        Initial position relative to the end of history. Defaults to -1 (newest item).

      Returns History<T>

      if capacity is not a positive safe integer.

      if currentPosition is out of bounds of history.

    Accessors

    • get capacity(): number

      Maximum number of items the history can hold.

      Returns number

    • get size(): number

      Number of items in the history.

      Returns number

    Methods

    • An iterator for the items in the history.

      Returns IterableIterator<T>

    • Checks if there is a next item to redo to.

      Returns boolean

      true if there is a next item to redo to, false otherwise.

    • Checks if there is a previous item to undo to.

      Returns boolean

      true if there is a previous item to undo to, false otherwise.

    • Gets the current item.

      Returns undefined | T

      The current item or undefined if history is empty.

    • Adds items to the end of the history. If the current item is not the latest, future history will be deleted. If the history is full, it will overwrite the oldest items.

      Parameters

      • ...items: T[]

        The items to add to the history.

      Returns number

      The new size of the history.

    • Restore next item.

      Returns undefined | T

      The next item or undefined if there is no next item.

    • Restore previous item.

      Returns undefined | T

      The previous item or undefined if there is no previous item.